Alert endpoint + save dish safety even if danger present
This commit is contained in:
+23
-11
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user