From 93c1c8e2997c711e5fc6e6b72c31decfae46562f Mon Sep 17 00:00:00 2001 From: Matthias Guillitte Date: Tue, 11 Aug 2026 17:10:42 +0200 Subject: [PATCH] Alert endpoint + save dish safety even if danger present --- cloud/app.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/cloud/app.py b/cloud/app.py index 4a871a5..5223f30 100644 --- a/cloud/app.py +++ b/cloud/app.py @@ -31,6 +31,7 @@ db = client["microwave_network_db"] cooking_collection = db["cooking_parameters"] telemetry_collection = db["telemetry_data"] +alert_collection = db["alert_data"] # Ensure the camera image storage directory exists when the app starts CAMERA_IMAGE_DIR = "storage/dishPhotos" @@ -105,18 +106,9 @@ async def cooking_params(): current_app.logger.exception("Exception during safety check or cook planning") return jsonify({"error": f"Task execution failed: {str(e)}"}), 500 - # 3. Evaluate Safety Result - data["safety_check"] = safety_result - if not safety_result.get("is_safe", True): - current_app.logger.warning(f"Unsafe dish detected: {safety_result}") - return jsonify({ - "error": "Safety hazard detected in microwave area", - "is_safe": False, - "warning": safety_result.get("warning_message", "Unsafe materials detected."), - "detected_hazards": safety_result.get("detected_hazards", []) - }), 200 - # 4. Attach Cooking Plan & Save to MongoDB + # 4. Attach Cooking Plan & safety check and Save to MongoDB + data["safety_check"] = safety_result data["analysis_results"] = cook_plan try: @@ -125,10 +117,30 @@ async def cooking_params(): except Exception as e: return jsonify({"error": f"Database error: {str(e)}"}), 500 + # 3. Evaluate Safety Result + if not safety_result.get("is_safe", True): + current_app.logger.warning(f"Unsafe dish detected: {safety_result}") + return jsonify({ + "error": "Safety hazard detected in microwave area", + "is_safe": False, + "warning_message": safety_result.get("warning_message", "Unsafe materials detected."), + "detected_hazards": safety_result.get("detected_hazards", []) + }), 200 + return jsonify(cook_plan), 201 except Exception as e: current_app.logger.exception("Exception in /cooking-params") +@app.route("/alert", methods=["POST"]) +def alert(): + # Save the alert in alert_collection + data = request.get_json() + alert_collection.insert_one(data) + + # TODO : Créer une room webex et envoyer un sms + + return jsonify({"status": "success", "message": "Alert saved"}), 200 + @app.route("/telemetry", methods=["POST"]) def telemetry(): data = request.get_json()