Update server.py
Browse files
server.py
CHANGED
|
@@ -255,6 +255,28 @@ async def get_stats(current_user: dict = Depends(get_current_user)):
|
|
| 255 |
avg_confidence=round(avg_conf, 2),
|
| 256 |
last_7_days=last_7,
|
| 257 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
|
| 260 |
app.include_router(api_router)
|
|
|
|
| 255 |
avg_confidence=round(avg_conf, 2),
|
| 256 |
last_7_days=last_7,
|
| 257 |
)
|
| 258 |
+
|
| 259 |
+
@api_router.get("/global-stats")
|
| 260 |
+
async def get_global_stats():
|
| 261 |
+
# Iterate all for a simple global count (since local mock doesn't support aggregate)
|
| 262 |
+
# Using to_list(length=100000) to grab items
|
| 263 |
+
items = await db.detections.find({}, {"_id": 0, "label": 1}).to_list(length=100000)
|
| 264 |
+
total_found = len(items)
|
| 265 |
+
ai_count = sum(1 for i in items if i.get("label") == "ai")
|
| 266 |
+
human_count = sum(1 for i in items if i.get("label") == "human")
|
| 267 |
+
|
| 268 |
+
# Hardcoded global accuracy representing the SADA model
|
| 269 |
+
avg_accuracy = 79.8
|
| 270 |
+
|
| 271 |
+
if total_found == 0:
|
| 272 |
+
return {"total": total_found, "ai_ratio": 0.0, "human_ratio": 0.0, "avg_accuracy": avg_accuracy}
|
| 273 |
+
|
| 274 |
+
return {
|
| 275 |
+
"total": total_found,
|
| 276 |
+
"ai_ratio": round((ai_count / total_found) * 100, 1),
|
| 277 |
+
"human_ratio": round((human_count / total_found) * 100, 1),
|
| 278 |
+
"avg_accuracy": avg_accuracy
|
| 279 |
+
}
|
| 280 |
|
| 281 |
|
| 282 |
app.include_router(api_router)
|