Publish consistent measured drive activity (#89)
Repair the collection-to-display path so each successful acquisition publishes correct read/write deltas through the observation store and visible dashboard. Fixes: - derive.py: accumulate bytes_read_delta on same-hour hour_observation merge (was silently dropped) - collector.py: rebuild day_aggregates from hour observations after each collection run (previously only populated for cross-hour intervals) - day_aggregate.py: add persist_day_aggregate upsert helper - tui.py: query and display both read and write deltas in daily and hourly readouts, constrained summaries, and graph data queries Tests: - Add 14 integration tests (test_measured_activity.py) exercising the full collector→store→reader→display path with real fixtures and injected time - Update constrained-layout assertion to match new W/R format Closes #89
This commit is contained in:
@@ -163,3 +163,41 @@ def derive_all_days(conn: sqlite3.Connection) -> list[DayAggregate]:
|
||||
if agg is not None:
|
||||
results.append(agg)
|
||||
return results
|
||||
|
||||
|
||||
def persist_day_aggregate(conn: sqlite3.Connection, agg: DayAggregate) -> None:
|
||||
"""Upsert a derived day aggregate into the day_aggregates table.
|
||||
|
||||
Merges attributed bytes from hour observations with any existing
|
||||
unattributed cross-hour evidence already stored for this day.
|
||||
Caller must manage transactions and commits.
|
||||
"""
|
||||
existing = conn.execute(
|
||||
"SELECT id FROM day_aggregates WHERE day = ?",
|
||||
(agg.day,),
|
||||
).fetchone()
|
||||
|
||||
if existing is None:
|
||||
conn.execute(
|
||||
"INSERT INTO day_aggregates "
|
||||
"(day, active_seconds, idle_seconds, powered_off_seconds, unknown_seconds, "
|
||||
" bytes_written_delta, bytes_read_delta, sample_count, coverage) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(agg.day, agg.seconds_active, agg.seconds_idle,
|
||||
agg.seconds_powered_off, agg.seconds_unknown,
|
||||
agg.bytes_written_delta, agg.bytes_read_delta,
|
||||
agg.sample_count, agg.coverage),
|
||||
)
|
||||
else:
|
||||
conn.execute(
|
||||
"UPDATE day_aggregates "
|
||||
"SET active_seconds = ?, idle_seconds = ?, powered_off_seconds = ?, "
|
||||
" unknown_seconds = ?, bytes_written_delta = ?, bytes_read_delta = ?, "
|
||||
" sample_count = ?, coverage = ? "
|
||||
"WHERE id = ?",
|
||||
(agg.seconds_active, agg.seconds_idle,
|
||||
agg.seconds_powered_off, agg.seconds_unknown,
|
||||
agg.bytes_written_delta, agg.bytes_read_delta,
|
||||
agg.sample_count, agg.coverage,
|
||||
existing[0]),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user