Skip to content

feat(plan-ui): stack price bars into spot + grid tariff + VAT - #191

Merged
frahlg merged 1 commit into
masterfrom
price-bar-stacked
Apr 24, 2026
Merged

frahlg merged 1 commit into
masterfrom
price-bar-stacked

Conversation

@frahlg

@frahlg frahlg commented Apr 24, 2026

Copy link
Copy Markdown
Member

Why

Users were asking "what do these price numbers mean?" The flat bars hide where the öre/kWh actually comes from — spot (what the planner can time against) vs grid tariff (fixed) vs VAT (fixed percentage). Making the split visible is pedagogical and makes the planner's behavior more legible ("the planner only cares about the green bit at the bottom").

What

Backend (go/internal/mpc/mpc.go):

  • Action gained SpotOre — raw wholesale price (öre/kWh, ex grid tariff and VAT), surfaced from Slot.SpotOre the DP already reads.

Frontend (web/plan.js, style.css, index.html):

  • Price bars now render as three stacked segments: spot (bottom, tercile-coloured green/red), grid tariff (middle, neutral slate), VAT (top, lighter slate). Tercile colour applied only to spot — that's the variable part.
  • Tooltip adds a breakdown block with spot öre, grid tariff öre, VAT öre, one-for-one with the colored segments.
  • Legend: "Cheap" / "Expensive" split into "Spot (cheap)", "Spot (expensive)", "Grid tariff", "VAT".
  • Reads grid_tariff_ore_kwh + vat_percent from /api/config (already fetched for the fuse scale) so the split matches prices.Applier exactly.
  • Falls back to a single flat bar when spot_ore isn't available.

Test plan

  • go test ./internal/mpc/... — 94 tests pass
  • JS syntax check
  • Refresh the planner page and confirm bars are stacked; hover a slot to see the breakdown; verify the legend explains each segment.

🤖 Generated with Claude Code

The flat price bar was opaque — users couldn't see why it lands at
e.g. 128 öre/kWh. Now each bar is stacked into its three components
so it's visually obvious where the kr/kWh goes and which part the
planner can actually do something about.

Backend (mpc.go):
- Action gained SpotOre — the raw wholesale price (öre/kWh, ex grid
  tariff and VAT), mirroring Slot.SpotOre which the DP already reads
  for export cost. Surfaces per-slot so the UI doesn't have to
  back-derive the split.

Frontend (web/plan.js + style.css + index.html):
- Price bars render as three stacked segments: spot (bottom,
  tercile-coloured green/red), grid tariff (middle, neutral slate),
  VAT (top, lighter slate). Tercile colour is applied only to spot
  since that's the variable part the planner is timing decisions
  against — fixed portions stay quiet.
- Tooltip adds a breakdown block showing spot öre + grid tariff öre
  + VAT öre for the hovered slot, numbers matching the segments
  one-for-one. Hover titles explain each component.
- Legend splits "Cheap/Expensive" into "Spot (cheap)", "Spot
  (expensive)", "Grid tariff", "VAT" so users know what each
  colour in a stacked bar means.
- Reads grid_tariff_ore_kwh + vat_percent from /api/config (already
  fetched for the fuse scale) so the split matches prices.Applier.
- Falls back to a single flat bar when spot_ore isn't available
  (legacy price points from before the SpotOre surface, or a tariff
  engine with zero grid tariff + VAT).

No backend tests change — SpotOre is already exercised end-to-end
through the existing DP cost path; the new field just surfaces it.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@frahlg
frahlg merged commit 2a1af1d into master Apr 24, 2026
1 check passed
@frahlg
frahlg deleted the price-bar-stacked branch April 24, 2026 09:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 75527b2f71

ℹ️ 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".

Comment thread web/plan.js
// Stack from zero upward. runningOre accumulates in öre/kWh and
// we re-project each segment's top edge through priceY so the
// stacked bar lines up pixel-perfect with the axis grid.
let runningOre = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Start stacked bars from plotted baseline, not absolute zero

In the stacked-price renderer, runningOre is initialized to 0 even though the chart’s visible baseline is Math.max(0, priceMin) (see zero in the same block). When all prices are positive (the common case), priceY(0) is below the price band, so each segment is drawn too tall and can bleed into the mode/power areas, misrepresenting relative prices. Initialize the stack accumulator from the plotted baseline (or clip to the price panel) so stacked bars match the axis scale.

Useful? React with 👍 / 👎.

Comment thread web/plan.js
let runningOre = 0;
const topY = priceY(priceVal);
for (const part of parts) {
if (part.ore <= 0) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve negative spot segments in stacked price bars

The stacked loop skips any component with part.ore <= 0, which drops negative spot prices entirely. In negative-price hours (which do occur on Nord Pool), the spot contribution is omitted while fixed components are still added, so the stack no longer matches the slot total and can invert the visual signal for cheap/negative periods. Handle negative components explicitly (draw below baseline) instead of filtering them out.

Useful? React with 👍 / 👎.

frahlg added a commit that referenced this pull request Oct 23, 2026
…#1811)

Move the device-drivers pin from 5cc7bb1a to 219c462e
(srcfl/device-drivers#190 and #191). Between the two pins only
easee_cloud changed.

An Easee Cloud charger given a 6 A order now starts at 7 A per phase
when Core's cap_amps_per_phase (#1809) allows 7 A, which avoids
Easee's roughly five-minute delay at 6 A, and steps down to 6 A once
the charger reports charging or after 90 s. 1.3.8 adds two review
fixes: no 7 A before the first poll, and a pause or stand-down cannot
leave 7 A for the phaseMode re-assert.

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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