INNER CODE UNIT · Python
get_signal_stats
GifariKemal/xaubot-ai · web-dashboard/api/main.py:381
async def get_signal_stats(hours: int = Query(24, ge=1, le=168)):
"""Get signal statistics for the last N hours."""
if not db.is_available():
return {"total": 0, "executed": 0, "executionRate": 0, "avgConfidence": 0, "byType": {}}
row = db.query(
"""SELECT
COUNT(*) as total,
COUNT(*) FILTER (WHERE executed = TRUE) as executed,
COALESCE(AVG(confidence), 0) as avg_confidence
FROM signals
WHERE signal_time > NOW() - MAKE_INTERVAL(hours => %s)""",
(hours,),
one=True,
)
if not row or row["total"] == 0:
return {"total": 0, "executed": 0, "executionRate": 0, "avgConfidence": 0, "byType": {}}