From d923a4ac61ce0460c9f8a40324b226ebfcbf2962 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 31 Jul 2025 19:08:54 -0600 Subject: [PATCH] feat: track history of last 3 predictions Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) --- server.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.py b/server.py index c195ee8..57caed9 100644 --- a/server.py +++ b/server.py @@ -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(':', '-')