Skip to content

feat(state): the energy ledger keeps hourly totals for four years - #1951

Merged
frahlg merged 1 commit into
masterfrom
feat/ledger-hourly-four-years
Nov 2, 2026
Merged

frahlg merged 1 commit into
masterfrom
feat/ledger-hourly-four-years

Conversation

@frahlg

@frahlg frahlg commented Nov 2, 2026

Copy link
Copy Markdown
Member

Stacked on #1950. Retarget to master once #1950 merges.

Why

Skatteverket's refund of energy tax after battery storage (#1950) is worked out hour by hour for one calendar year and may be claimed until three years after that year ends. The ledger kept hourly totals for two years and daily totals after that, so a year claimed late had its first months as daily totals, which the report counts as incomplete.

What

  • EnergyLedgerRetention goes from 2 × 365 days to 4 × 366 days: the hours of a year now last until its claim deadline, leap years included. Five-minute detail (30 days) and the daily tier after the hourly horizon are unchanged.
  • The note under the refund figure no longer tells owners to download the CSV before the hours are gone.

Cost

The ledger stores about one hourly row per asset and flow (more only where an hour mixes qualities). A site with a grid meter, battery, solar, a charger and observed load has about ten flows, so roughly 88,000 rows a year. Two more years of hours adds about 175,000 rows, a few tens of MB in history.db, instead of the same years as daily rows.

Evidence

go test ./internal/state -run 'Ledger|Prune|Plain|Energy' and node --test web/battery-return.test.mjs pass. The prune tests use the constant, so they move with it. No conflict with #1751, the other open PR touching energy_ledger.go.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T09:31:38.039220Z d117cb9 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg force-pushed the feat/ledger-hourly-four-years branch 2 times, most recently from d6d8b88 to 871b79e Compare November 2, 2026 11:52
Skatteverket's refund of energy tax after battery storage is worked out
hour by hour for a calendar year and may be claimed until three years
after the year ends. With two years of hours, the start of an older year
was already daily totals and counted as incomplete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg force-pushed the feat/ledger-hourly-four-years branch from 871b79e to f7952f5 Compare November 2, 2026 14:52
@frahlg
frahlg changed the base branch from feat/battery-return-tax to master November 2, 2026 14:52
@frahlg frahlg closed this Nov 2, 2026
@frahlg frahlg reopened this Nov 2, 2026
@frahlg
frahlg merged commit cd1ce6e into master Nov 2, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant