Spaces:
Runtime error
Runtime error
Update services/metrics_service.py
Browse files- services/metrics_service.py +17 -6
services/metrics_service.py
CHANGED
@@ -1,8 +1,19 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
return {
|
4 |
-
"
|
5 |
-
"
|
6 |
-
"cracks": len([item for item in items if item['type'] == 'crack']),
|
7 |
-
"holes": len([item for item in items if item['type'] == 'hole'])
|
8 |
}
|
|
|
1 |
+
# services/metrics_service.py
|
2 |
+
def compute_metrics(detections):
|
3 |
+
"""
|
4 |
+
Compute metrics from detection results.
|
5 |
+
Args:
|
6 |
+
detections: List of detection dictionaries
|
7 |
+
Returns:
|
8 |
+
dict: Metrics summary
|
9 |
+
"""
|
10 |
+
if not detections:
|
11 |
+
return {"count": 0, "avg_confidence": 0.0}
|
12 |
+
|
13 |
+
count = len(detections)
|
14 |
+
avg_confidence = sum(d["confidence"] for d in detections if "confidence" in d) / count if count > 0 else 0.0
|
15 |
+
|
16 |
return {
|
17 |
+
"count": count,
|
18 |
+
"avg_confidence": avg_confidence
|
|
|
|
|
19 |
}
|