feat: track history of last 3 predictions

Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
2025-07-31 19:08:54 -06:00
parent dd53b40909
commit d923a4ac61

View File

@@ -27,6 +27,8 @@ CLASS_NAMES = ['closed', 'open'] # From training, sorted alphabetically
POLL_INTERVAL_SECONDS = 10
REQUEST_TIMEOUT_SECONDS = 5
UNSURE_CONFIDENCE_THRESHOLD = 0.97
PREDICTION_HISTORY = []
PREDICTION_HISTORY_MAX_LENGTH = 3
# --- Model Inference ---
def get_prediction(model, image_bytes, device):
@@ -74,6 +76,16 @@ async def monitor_garage_door(app):
prediction, confidence = result
logging.debug(f"Garage door status: {prediction} (confidence: {confidence:.4f})")
# Update prediction history
if confidence >= UNSURE_CONFIDENCE_THRESHOLD:
PREDICTION_HISTORY.append(prediction)
else:
PREDICTION_HISTORY.append('unknown')
# Trim history if it's too long
if len(PREDICTION_HISTORY) > PREDICTION_HISTORY_MAX_LENGTH:
PREDICTION_HISTORY.pop(0)
if confidence < UNSURE_CONFIDENCE_THRESHOLD:
# Sanitize timestamp for use in filename
timestamp = datetime.now().isoformat().replace(':', '-')