SuriRaja commited on
Commit
fa1e159
·
1 Parent(s): 06a815f

Update services/metrics_service.py

Browse files
Files changed (1) hide show
  1. services/metrics_service.py +21 -18
services/metrics_service.py CHANGED
@@ -1,22 +1,25 @@
1
  # services/metrics_service.py
2
 
3
- import random
 
 
 
 
4
 
5
- # Define dummy anomaly types (same as videos you created)
6
- ANOMALY_TYPES = [
7
- "Thermal Anomaly Detected",
8
- "Panel Broken Detected",
9
- "Human Intrusion Detected",
10
- "Fire Detected",
11
- ]
12
 
13
- # You can expand metrics here
14
- def get_live_metrics(anomaly_type):
15
- """Simulate live metrics based on anomaly type."""
16
- metrics = {
17
- "Thermal Anomaly Detected": f"🔥 Hotspot Temperature: {random.randint(70, 120)} °C",
18
- "Panel Broken Detected": f"⚡ Broken Panels: {random.randint(1, 3)} detected",
19
- "Human Intrusion Detected": f"🚶 People Count: {random.randint(1, 2)} moving in area",
20
- "Fire Detected": f"🚒 Fire Alert Level: {random.randint(5, 10)} / 10",
21
- }
22
- return f"**{anomaly_type}**\n\n{metrics.get(anomaly_type, 'No anomaly detected')}"
 
 
 
1
  # services/metrics_service.py
2
 
3
+ metrics = {
4
+ "Frames Processed": 0,
5
+ "Anomalies Detected": 0,
6
+ "Last Detected Anomaly": "None"
7
+ }
8
 
9
+ def reset_metrics():
10
+ metrics["Frames Processed"] = 0
11
+ metrics["Anomalies Detected"] = 0
12
+ metrics["Last Detected Anomaly"] = "None"
 
 
 
13
 
14
+ def update_metrics(detected, anomaly_name="None"):
15
+ metrics["Frames Processed"] += 1
16
+ if detected:
17
+ metrics["Anomalies Detected"] += 1
18
+ metrics["Last Detected Anomaly"] = anomaly_name
19
+
20
+ def get_metrics_text():
21
+ return (
22
+ f"📈 Frames Processed: {metrics['Frames Processed']}\n"
23
+ f"🚨 Anomalies Detected: {metrics['Anomalies Detected']}\n"
24
+ f"⚡ Last Anomaly: {metrics['Last Detected Anomaly']}"
25
+ )