fix(api): aggregate metrics history by day so days=42 spans days, not minutes
CI/CD / build-and-push (push) Successful in 7s
CI/CD / build-and-push (push) Successful in 7s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
060fc89953
commit
1797b79f7b
+13
-1
@@ -330,9 +330,21 @@ class Database:
|
||||
return result
|
||||
|
||||
async def get_metrics_history(self, days: int = 42) -> list[dict]:
|
||||
"""Return the closing snapshot of each UTC day, newest day first.
|
||||
|
||||
metrics_daily receives one snapshot per trading cycle (~1/min), so a
|
||||
plain LIMIT over raw rows would cover minutes, not days. DISTINCT ON
|
||||
collapses each calendar day to its last snapshot, making `days` bound
|
||||
actual days. history[0] remains the most recent snapshot overall.
|
||||
"""
|
||||
async with self._pool.acquire() as conn:
|
||||
rows = await conn.fetch(
|
||||
"SELECT * FROM metrics_daily ORDER BY timestamp DESC LIMIT $1", days
|
||||
"""
|
||||
SELECT DISTINCT ON (timestamp::date) *
|
||||
FROM metrics_daily
|
||||
ORDER BY timestamp::date DESC, timestamp DESC
|
||||
LIMIT $1
|
||||
""", days
|
||||
)
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user