Spaces:
Runtime error
Runtime error
Update services/metrics_service.py
Browse files- services/metrics_service.py +11 -13
services/metrics_service.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import logging
|
|
|
2 |
|
3 |
# Setup logging
|
4 |
logging.basicConfig(
|
@@ -7,7 +8,7 @@ logging.basicConfig(
|
|
7 |
format="%(asctime)s - %(levelname)s - %(message)s"
|
8 |
)
|
9 |
|
10 |
-
def update_metrics(detected_items):
|
11 |
"""
|
12 |
Update metrics based on detected items.
|
13 |
Args:
|
@@ -16,23 +17,20 @@ def update_metrics(detected_items):
|
|
16 |
dict: Updated metrics
|
17 |
"""
|
18 |
try:
|
19 |
-
|
20 |
-
avg_confidence = sum(item["confidence"] for item in detected_items if "confidence" in item) / total_detections if total_detections else 0
|
21 |
-
types = [item["type"] for item in detected_items if "type" in item]
|
22 |
-
type_counts = {t: types.count(t) for t in set(types)}
|
23 |
-
|
24 |
metrics = {
|
25 |
-
"
|
26 |
-
"
|
27 |
-
"
|
|
|
28 |
}
|
29 |
-
|
30 |
logging.info(f"Updated metrics: {metrics}")
|
31 |
return metrics
|
32 |
except Exception as e:
|
33 |
logging.error(f"Error updating metrics: {str(e)}")
|
34 |
return {
|
35 |
-
"
|
36 |
-
"
|
37 |
-
"
|
|
|
38 |
}
|
|
|
1 |
import logging
|
2 |
+
from typing import List, Dict, Any
|
3 |
|
4 |
# Setup logging
|
5 |
logging.basicConfig(
|
|
|
8 |
format="%(asctime)s - %(levelname)s - %(message)s"
|
9 |
)
|
10 |
|
11 |
+
def update_metrics(detected_items: List[Dict[str, Any]]) -> Dict[str, Any]:
|
12 |
"""
|
13 |
Update metrics based on detected items.
|
14 |
Args:
|
|
|
17 |
dict: Updated metrics
|
18 |
"""
|
19 |
try:
|
20 |
+
items = detected_items if detected_items else []
|
|
|
|
|
|
|
|
|
21 |
metrics = {
|
22 |
+
"items": items,
|
23 |
+
"total_detected": len(items),
|
24 |
+
"cracks": len([item for item in items if item.get("type") == "crack"]),
|
25 |
+
"holes": len([item for item in items if item.get("type") == "hole"])
|
26 |
}
|
|
|
27 |
logging.info(f"Updated metrics: {metrics}")
|
28 |
return metrics
|
29 |
except Exception as e:
|
30 |
logging.error(f"Error updating metrics: {str(e)}")
|
31 |
return {
|
32 |
+
"items": [],
|
33 |
+
"total_detected": 0,
|
34 |
+
"cracks": 0,
|
35 |
+
"holes": 0
|
36 |
}
|