Repository navigation
feat(state): aggregate dashboard history after counting interval energy - #1294
Conversation
Signed-off-by: Fredrik Ahlgren <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c14db7717
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| SELECT ts_ms, grid_w, pv_w, bat_w, load_w, bat_soc, 2,1,86400000,ts_ms FROM history_cold | ||
| WHERE ts_ms BETWEEN ? AND ? | ||
| ), | ||
| UNION ALL SELECT last_ms,grid_w,pv_w,bat_w,load_w,bat_soc,-1,n,resolution_ms,first_ms FROM history_dashboard WHERE last_ms BETWEEN ? AND ? |
There was a problem hiding this comment.
Keep dashboard aggregates out of research training data
When aggregation is enabled, this adds history_dashboard rows to every LoadHistory consumer even though their flat power fields are sample means while their JSON contains only the newest tick. The inspected handleLoadResearchDump/buildLoadResearchBuckets path consumes these rows without checking resolution_ms or the new aggregate_not_for_training marker, extracts EV/V2X power from that last-tick JSON, and counts each aggregate as one sample; for example, two ticks with different EV power can export averaged grid power paired with only the second EV value. This silently corrupts the model-oriented research bundle, so that path needs compatible per-signal aggregates or must reject these dashboard summaries.
Useful? React with 👍 / 👎.
| _, err := tx.ExecContext(ctx, `INSERT INTO history_site_energy VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?) | ||
| ON CONFLICT(start_ms,resolution_ms) DO UPDATE SET first_ms=MIN(first_ms,excluded.first_ms),last_ms=MAX(last_ms,excluded.last_ms),covered_ms=covered_ms+excluded.covered_ms,n=n+excluded.n, | ||
| import_wh=import_wh+excluded.import_wh,export_wh=export_wh+excluded.export_wh,pv_wh=pv_wh+excluded.pv_wh,bat_charge_wh=bat_charge_wh+excluded.bat_charge_wh,bat_discharge_wh=bat_discharge_wh+excluded.bat_discharge_wh,load_wh=load_wh+excluded.load_wh,ev_wh=ev_wh+excluded.ev_wh`, | ||
| start, ArchiveResolutionMS, from, to, ms, 1, math.Max(0, p.GridW)*hours, math.Max(0, -p.GridW)*hours, -p.PVW*hours, math.Max(0, p.BatW)*hours, math.Max(0, -p.BatW)*hours, p.LoadW*hours, math.Max(0, p.GridW-p.BatW-p.PVW-p.LoadW)*hours) |
There was a problem hiding this comment.
Count each source interval only once
When a valid observation interval crosses one or more minute boundaries, this loop stores n=1 for every fragment rather than once for the original interval. aggregateDayEnergy later sums these values into DayEnergy.Intervals, whose contract is the number of integration intervals, and recentDailyLoadWh uses a threshold of 50 intervals as a data-quality gate; a handful of sparse 20-minute observations can therefore be reported as dozens of independent intervals and incorrectly influence the planner's recent-load floor.
Useful? React with 👍 / 👎.
Signed-off-by: Fredrik Ahlgren <[email protected]>
Dashboard power rows still grew at poll cadence after scalar history moved to bounded aggregates. Averaging those rows before counting energy would cancel short import/export changes and hide gaps.
Record signed energy and measured coverage from each original site interval in the same transaction as its retry receipt. Keep chart summaries at 10 seconds for 24 hours, one minute through 30 days and five minutes through two years. These small site summaries stay in SQLite; scalar history uses the Parquet path merged in #1290. Minute energy totals remain for two years, then quarter-hour totals preserve local day boundaries and normal tariff periods. Existing legacy chart tiers remain readable.
Energy and cost readers use the interval totals. A range or tariff edge inside a retained interval remains uncovered; the code never invents how that energy split. Missing site observations break integration. Chart means retain sample counts and source resolution; detail JSON retains its actual timestamp and is marked unsuitable for forecast training. Schema 6 prevents an older binary from silently ignoring the new history format.
Validation: full local
make verifypassed. Regression tests compare original and aggregated import/export, battery flows, costs, tariff boundaries, outages, receipt retries, restart, retention and local day boundaries. A full backup/restore test verifies the energy cursor and duplicate timestamp handling.Closes #1291. Continues #1287. Does not close the SD-card IO latency gate in #1246 or the control-loop IO issue #1247. No running Core was replaced and no EV charging cycle was tested.