feat: downsampled DOD trail + history endpoint for live-chart backfill
So a viewer sees recent trend on open instead of a blank chart. Viewing
only — reports still use the device's FTP .rnd data.
- NL43Reading table (auto-creates; no migration): unit_id, timestamp,
lp/leq/lmax/ln1/ln2.
- Monitor stores one downsampled reading per MONITOR_TRAIL_SAMPLE_S
(default 60s) from its keepalive poll loop, pruning rows older than
MONITOR_TRAIL_RETENTION_HOURS (default 24h). ~1440 rows/unit max.
- GET /api/nl43/{unit}/history?hours=N -> the trail for the last N hours
(clamped 0.1-48h), oldest-first.
Because keepalive runs 24/7, the trail fills continuously, so the history
is there whenever someone opens the live view.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -128,3 +128,24 @@ class AlertEvent(Base):
|
||||
acknowledged_at = Column(DateTime, nullable=True)
|
||||
acknowledged_by = Column(String, nullable=True)
|
||||
notes = Column(Text, nullable=True)
|
||||
|
||||
|
||||
class NL43Reading(Base):
|
||||
"""Downsampled time-series of live-monitor readings, for the live-chart
|
||||
backfill (so a viewer sees recent trend on open, not a blank chart).
|
||||
|
||||
Viewing only — NOT the report source. Reports use the device's authoritative
|
||||
FTP .rnd intervals. This is a short, capped trail (one row/minute, pruned to
|
||||
a retention window) fed by the monitor's keepalive poll loop.
|
||||
"""
|
||||
|
||||
__tablename__ = "nl43_readings"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
unit_id = Column(String, index=True, nullable=False)
|
||||
timestamp = Column(DateTime, default=func.now(), index=True)
|
||||
lp = Column(String, nullable=True)
|
||||
leq = Column(String, nullable=True)
|
||||
lmax = Column(String, nullable=True)
|
||||
ln1 = Column(String, nullable=True)
|
||||
ln2 = Column(String, nullable=True)
|
||||
|
||||
Reference in New Issue
Block a user