Skip to content

WP3: vehicle form, observation guard, asap bays, done events, queue with move-by - #11

Merged
Neal006 merged 1 commit into
mainfrom
worktree-wp3-cars-queue
Sep 13, 2026
Merged

Neal006 merged 1 commit into
mainfrom
worktree-wp3-cars-queue

Conversation

@Neal006

@Neal006 Neal006 commented Sep 13, 2026

Copy link
Copy Markdown
Owner

WP3 of prompt.md (solutions.md §3, §10, §11). Plan and deviations: .docs/implementation-plan.md (A5, deviations 6 and 8).

What changed

  • Vehicle form. POST /sessions takes optional vehicle {model, battery_kwh, max_kw}, soc_now, target_soc (default 1.0). kwh_needed = (target − now) × battery when given; the brain plans with min(bay, car). need_confidence on the session: declared (form or typed kWh) → history (this bay's median) → site (the day's median). The old hard-coded 8.0 default is gone.
  • Observation guard. A car drawing < 80 % of its limit for 5 consecutive minutes (and not yet tapering) gets max_kw = metered × 1.05 for the rest of the session and a cap_observed event. The sim carries car_kw (what the car can physically draw) separately from max_kw (what the planner believes) so this is testable.
  • connectors_asap in site.json (c41, c42 — clear of both replayed datasets and the smoke bays): those bays are always ASAP in car().
  • Done + queue. Sim.tick emits done and stamps idle_since; ConnectorMeter.idle_min. Sim.waiting holds arrivals with no free bay and plugs them first-come-first-served as bays free (plug_in events carry waited_min). A5: a done car idle ≥ 10 min is unplugged when someone is waiting — the sim's stand-in for "done, please move"; real-world signal is OCPP StatusNotification.
  • Move-by. On every re-solve with a queue, the plugged cars with the most slack get deadline = now + e_rem / p_max (+ one slot), one tightened car per waiting car, never an urgent car or one with < 1 h slack; event move_by. /demo/oversubscribe now queues instead of dropping and reports waiting.
  • Additive contract fields (SessionOut, ConnectorMeter, MeterMsg.waiting, StatusOut.waiting/connectors_asap, event names); contract files regenerated.

Tests (fail on old code) — 69 pass

  • 3.3 kW PHEV on a 7 kW bay: planned at ≤ 3.3 kW, 8 kWh from the SoC form, full by its deadline.
  • Need from history/site when nothing is typed.
  • Guard trips on a simulated slow car (form says 7, car draws 3.3) → max_kw 3.47, event, plan follows.
  • ASAP bay at full power with 8 h of slack.
  • Queue: 36 replayed + 60 late cars → waiting > 0, slackest cars tightened to now + e_rem/p_max, waiting cars get bays within 4 h, done events fire.
  • smoke.py: van on c41 at full power; PHEV form → 8 kWh declared, capped at 3.3. SMOKE OK.
  • prove.py unchanged: CO₂ −64.6 %, bill −2.9 %, peak −1.0 %, 0 fallbacks (564 solves now — done events re-solve).

🤖 Generated with Claude Code

https://claude.ai/code/session_017thvbGo7rTVnG2f46cLMzU

…ueue with move-by

- POST /sessions accepts vehicle{model,battery_kwh,max_kw}, soc_now,
  target_soc: kwh_needed = (target - now) * battery; need_confidence
  declared | history (bay median) | site (day median) replaces the 8.0 default.
  car() plans with min(bay, car); the sim draws min(limit, car_kw * taper).
- Observation guard: 5 min under 80 % of the limit (not tapering) -> max_kw =
  metered * 1.05 for the session, event cap_observed.
- site.json connectors_asap [c41, c42]: those bays are always ASAP.
- Sim.tick emits done (+ idle_since); Sim.waiting holds arrivals with no bay
  and plugs them FIFO as bays free; a done car idle >= 10 min is unplugged
  when someone waits (assumption A5). resolve() gives the slackest plugged
  cars a move-by deadline (now + e_rem / p_max), one per waiting car, never
  urgent or < 1 h slack; event move_by. /demo/oversubscribe queues instead
  of dropping.
- Additive contract: SessionOut/ConnectorMeter/MeterMsg/StatusOut fields,
  EventMsg names done | cap_observed | move_by. Contract files regenerated.
- 5 new tests (69): 3.3 kW car planned at 3.3 and full by its deadline;
  need from history/site; guard trips and the plan follows; asap bay at
  full power with 8 h slack; queue of 60 late cars tightens the slackest,
  waiting cars get bays, done events fire. smoke OK; prove unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017thvbGo7rTVnG2f46cLMzU
Copilot AI lite review requested due to automatic review settings September 13, 2026 00:46

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Neal006
Neal006 merged commit c3282de into main Sep 13, 2026
3 checks passed
@Neal006
Neal006 deleted the worktree-wp3-cars-queue branch September 13, 2026 00:57
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.

2 participants