AryaAzhar commited on
Commit
dbea7ff
·
verified ·
1 Parent(s): 5046041

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +15 -5
server.py CHANGED
@@ -258,24 +258,34 @@ async def get_stats(current_user: dict = Depends(get_current_user)):
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
 
 
258
 
259
  @api_router.get("/global-stats")
260
  async def get_global_stats():
261
+ # Iterate all for a simple global count
262
+ items = await db.detections.find({}, {"_id": 0, "label": 1}).sort("created_at", -1).to_list(length=100000)
 
263
  total_found = len(items)
264
  ai_count = sum(1 for i in items if i.get("label") == "ai")
265
  human_count = sum(1 for i in items if i.get("label") == "human")
266
 
267
+ # Get last 56 labels for the live waveform visual
268
+ recent_labels = [i.get("label", "human") for i in items[:56]]
269
+
270
  # Hardcoded global accuracy representing the SADA model
271
  avg_accuracy = 79.8
272
 
273
  if total_found == 0:
274
+ return {
275
+ "total": total_found,
276
+ "ai_ratio": 0.0,
277
+ "human_ratio": 0.0,
278
+ "avg_accuracy": avg_accuracy,
279
+ "recent_labels": []
280
+ }
281
+
282
 
283
  return {
284
  "total": total_found,
285
  "ai_ratio": round((ai_count / total_found) * 100, 1),
286
  "human_ratio": round((human_count / total_found) * 100, 1),
287
+ "avg_accuracy": avg_accuracy,
288
+ "recent_labels": recent_labels
289
  }
290
 
291