Repository navigation
feat(plan): give each charger its planned slots, cost and expected level - #2185
Conversation
Codex Review Summary: ✅ CompletedThis 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: b420b97e71
ℹ️ 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".
| hours := max(0, s.End.Sub(from).Hours()) | ||
| level += s.PowerW * hours * loadpoint.DefaultChargeEfficiency / st.VehicleCapacityWh |
There was a problem hiding this comment.
Account for delivered pulse energy in the running slot's level
When the running slot uses a partial-duty charge, multiplying its average power by the remaining wall-clock time adds energy that may already have been delivered. loadpoint.Controller.computeCommandForBudget runs at the pulse ceiling until the energy budget is spent, rather than spreading delivery evenly. For example, a 15-minute slot averaging 3,667 W can deliver its entire budget at 11 kW in the first five minutes; reading the plan ten minutes into that slot still adds another 306 Wh here, although the current car level already includes the whole charge. This overstates that slot's expected level and every subsequent level. Calculate the running slot's remaining energy from its budget and delivery/pulse progress instead of assuming uniform delivery.
Useful? React with 👍 / 👎.
The plan an app reads or is pushed now carries, per charger, the slots the plan charges in: the average power, the part bought from the grid, and the car's expected level at each slot's end when the box knows the car's level and capacity. It also carries what the charge should cost, in the plan's own accounting. All of it comes from the plan the box acts on, Core's or Energyplan's. Back-to-back slots with the same power, grid part and level are one run. A plan too large for its bucket cuts its own slots, and each heat zone's with them, only while it would not fit without the chargers' slots and cost, so it keeps the slots it kept before chargers carried them. The chargers' slots end with the plan's, then lose their far end until the plan fits; the cost goes next, then far windows and heat slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53cb9a6 to
0f20e18
Compare
What
HannesB's new charging screen for iPhone 1.2 draws a car's charge quarter by quarter: power, how much comes from the grid, the car's level and what the charge costs. The plan the box sends had only joined windows and a Wh total, so an app would have had to guess the rest or plan again on its own.
This gives each charger in the plan (
plan.chargers[]) three new fields, all read from the plan the box acts on, whether Core's or Energyplan's. No second plan is made.slotsare the windows' slots, the running slot first and counted whole, astotalWhcounts it. Only slots with power are sent, and back-to-back slots with the samew,gridWand level (or no level) are one run whosedurationMsis their sum. Without levels a long charge is one or a few entries; with levels each quarter is its own, since the level moves.wis the slot's planned power, an average. A Core reserve or Energyplan plan can pulse the car at full power for part of a slot.gridWis the import the charge adds while the rest of the plan stays as planned. The rest is the site's own power. With the default rule (the battery never feeds the car) that is sun; if the owner lets the battery cover the car, or boosts it, it may be battery too.costMinoruses the plan's own cost function (SlotGridCostOre): import at the slot's price, the site's own power at the export price it gives up (spot + bonus − fee, or the flat price), and spill and curtailment free. Each pulse state counts on its own, asreserveSlotCostprices them. Energy only, no power fee. Rounded once; absent when a price is not known.socPermillecounts from the car's level now plus planned energy × 0.9 / capacity, capped at 100 %. It is sent only when the box knows both: never from a level assumed at plug-in, for a visitor's car, or with the default capacity.socEstimatemarks it as the box's estimate.planChargersVectorkeeps its bytes: a charger without the new fields encodes as before.What is trimmed first
The battery plan keeps priority over car detail. When a plan is too large for its 16 KB bulk bucket:
plan.slotsand the windows come out exactly as they did before this PR, for a plan that fits (it keeps every slot) and for one that does not (in the test, a 193-quarter plan keeps 144). Older apps see the same plan slots.socEstimategoes too.costMinorgoes next.totalWhandcostMinorcover the whole plan, so the slots can sum to less. An app with no slots draws the windows.No registry names change: these are plan fields, as
windowsare.Tests
go test ./internal/mpc ./internal/appproto ./cmd/ftw, andgo test ./...ingo/protocolmake verify, once, before pushinginternal/mpc: grid, sun, mixed, spill at the export limit, a limit crossed without the car, curtailment, one pulse priced per state, an outdated plan and an unknown charger. One test per planner: Core DP (the older single shape), Core reserve and Energyplan (a reserve plan throughtoPlanandValidatePlan). The native worker test runs undermake native-solver-testand skips withoutFTW_NATIVE_SOLVER. On this Mac it skipped, because no worker is bundled for the host.cmd/ftw: a car with a goal (slots, cost 865 öre, levels 433/474/489‰), a charger with no car (nothing), a level assumed at plug-in, a visitor and no capacity (slots and cost, no levels), and a car's own level from the cars runtime.internal/appproto: a wire vector,planCarSlotsVector, for the apps to copy.TestTheCarsSlotsNeverCostThePlanASlotpushes a 96-quarter plan (fits) and a 193-quarter plan (does not) with two chargers charging every quarter, and checks thatplan.slotsand the windows equal those of the same plan without car fields, while the chargers' slots are the nearest ones and end with the plan. Cutting plan slots first, as the first version of this PR did, fails it: 54 of 96 and 60 of 144 plan slots.TestACarsRunEndsWithThePlansLastSlotcovers the cut of a run.cmd/ftw: two grid quarters alike without a level are one 30-minute run.Paired work
ftw-webapp/docs/protocol.mdneeds the same "A car's plan" section.slots,costMinorandsocEstimate, falling back to windows when a box sends no slots.writePlan's trim,app_link.go,protocol.goanddocs/protocol.md. Branchcar-plan-slots-on-heatholds this change rebased onto it: heat zones give way with the plan's slots, charger slots end at the last plan slot, and chargers and heat trim when plan slots run out. It is meant to replace this branch once feat(appproto): the plan carries each heat zone's plan #2184 merges.Release
The changeset is
minor, as the earlier plan level field was: the plan carries new data the apps will show. The owner approves a minor here.🤖 Generated with Claude Code