Dashboard: fix freshness-chip timezone bug + sync-aware thresholds
Live verification caught it: the data-freshness chip read ~14,477s (RED) on data that was actually 1s fresh — exactly the EDT offset. Event timestamps are stored NAIVE LOCAL (datetime.now()), but query_risk_state compared them against UTC now. Compare naive-local to naive-local instead (tz-aware timestamps still use UTC). Verified live: chip now reads ~78s. Also align the amber/red thresholds to the ~60s broker-sync cadence (amber >90s, red >180s) so a healthy feed reads green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
b79377f41e
commit
fbe2eff3d4
2 files changed
+8
-3
No files matched your search
@@ -471,7 +471,8 @@ function render(d) {
|
||||
$("risk-day").textContent = rk.day_pnl_pct != null ? (rk.day_pnl_pct * 100).toFixed(1) + "% / -" + (rk.daily_loss_limit_pct * 100).toFixed(0) + "%" : "—";
|
||||
const fr = $("risk-fresh");
|
||||
fr.textContent = rk.data_age_s != null ? rk.data_age_s.toFixed(0) + "s" : "—";
|
||||
fr.style.color = (rk.data_age_s == null) ? "" : (rk.data_age_s > 90 ? "#ff4d4f" : rk.data_age_s > 30 ? "#f1c40f" : "");
|
||||
// broker sync runs ~every 60s, so >90s = a missed sync (amber), >180s = stale (red)
|
||||
fr.style.color = (rk.data_age_s == null) ? "" : (rk.data_age_s > 180 ? "#ff4d4f" : rk.data_age_s > 90 ? "#f1c40f" : "");
|
||||
|
||||
const accts = d.accounts || [];
|
||||
$("acct-count").textContent = accts.length;
|
||||
|
||||
@@ -625,8 +625,12 @@ def query_risk_state(store) -> dict:
|
||||
t = (datetime.fromisoformat(ts_latest.replace("Z", "+00:00"))
|
||||
if isinstance(ts_latest, str) else ts_latest)
|
||||
if t.tzinfo is None:
|
||||
t = t.replace(tzinfo=timezone.utc)
|
||||
age = (datetime.now(timezone.utc) - t).total_seconds()
|
||||
# event timestamps are stored NAIVE LOCAL (datetime.now()), so
|
||||
# compare against naive-local now — comparing to UTC would be off
|
||||
# by the whole timezone offset (the chip read ~4h on fresh data).
|
||||
age = (datetime.now() - t).total_seconds()
|
||||
else:
|
||||
age = (datetime.now(timezone.utc) - t).total_seconds()
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user