Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
8ad6aaa
fix(control): one log of FTW's own EV offers
frahlg Oct 27, 2026
8fe5dbb
test(site): add P0 rig scenarios R1-R5
frahlg Oct 27, 2026
a840def
fix(control): battery fuse guard reads each phase with its direction
frahlg Oct 27, 2026
0af26e0
fix(control): battery waits only for a declared charger response time
frahlg Oct 27, 2026
2f793d8
fix(control): fuse guard reads phases after the hold caps the targets
frahlg Oct 27, 2026
3dc080f
test(site): make R2, R4, R5a and R5b judge what Core does on master
frahlg Oct 27, 2026
0cfe973
Merge remote-tracking branch 'origin/master' into f-1888-ff
frahlg Oct 27, 2026
6803ab2
test(site): judge R2-R5a at the fuse rating, not fuse - 0.5 A or - 1 A
frahlg Oct 27, 2026
51997bc
test(site): pin R5a's 3 s clock to the first sample at the fuse
frahlg Oct 27, 2026
f2ee596
test(site): the rig's "over the limit" is above the fuse, not fuse - 1 A
frahlg Oct 27, 2026
8274e40
test(site): the rig expects the room the fuse rating gives
frahlg Oct 27, 2026
b899d52
test(site): say S1-16's target is a floor while the battery covers th…
frahlg Oct 27, 2026
ae50212
fix(control): car and battery-beside-car work to the fuse rating less…
frahlg Oct 27, 2026
3860ee1
fix(control): keep covered offers whole and leave battery relief out …
frahlg Oct 27, 2026
784d0ba
fix(control): battery fuse guard reads each phase with its direction
frahlg Oct 27, 2026
7e453c0
fix(control): fuse guard reads phases after the hold caps the targets
frahlg Oct 27, 2026
a11706b
fix(control): battery relieves to the fuse less safety_margin_a
frahlg Oct 27, 2026
c311760
test(control): re-record golden records at the fuse less safety_margin_a
frahlg Oct 27, 2026
3efb3ed
fix(control): battery fuse cut lands on the line, not half a margin b…
frahlg Oct 27, 2026
f93b81f
docs(changeset): name the limit the battery cut lands on
frahlg Oct 27, 2026
fab8f6f
fix(config): fuse safety_margin_a defaults to 0
frahlg Oct 27, 2026
94f19b3
docs(changeset): say what the default change moves on its own
frahlg Oct 27, 2026
d8737e0
Merge origin/master into b-ev-fuse-line-at-rating
frahlg Oct 27, 2026
1d44a63
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 27, 2026
8a7c2be
test(control): relief stays at the line after a PV drop (C3, seed 207…
frahlg Oct 27, 2026
66e1caf
test(site): judge random runs by rig items R2-R7 of the 27 Oct triage
frahlg Oct 27, 2026
610e2a1
Merge a5-battery-fuse-signed-phases into c-battery-fuse-no-buffer
frahlg Oct 27, 2026
44e74f3
test(site): tighten the random judge after review of #1920
frahlg Oct 27, 2026
4493e94
Merge origin/master into b-ev-fuse-line-at-rating
frahlg Oct 27, 2026
e3d426b
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 27, 2026
b19d30d
test(control): phase relief reads each battery live, in the decision'…
frahlg Oct 27, 2026
fd07863
fix(control): battery relief holds when the battery's reading lags th…
frahlg Oct 27, 2026
4c48376
test(site): R8 counts a forced battery from when Core has the inverte…
frahlg Oct 27, 2026
8e2719a
test(site): R8 records the seconds Core's timers excuse
frahlg Oct 27, 2026
bb9703e
fix(control): a landed EV cut covers nothing later; a raise that no l…
frahlg Oct 27, 2026
ad1f994
fix(control): a one-phase house move is not the car's cut landing
frahlg Oct 27, 2026
43d38ff
fix(control): a battery charge rise fits each phase before it is sent
frahlg Oct 27, 2026
c94fa56
fix(control): battery rise check counts slow batteries and direction-…
frahlg Oct 27, 2026
a6bdd9e
fix(control): the car comes before battery charge
frahlg Oct 27, 2026
eb553dd
fix(control): peak shaving drops a running charge for the car
frahlg Oct 27, 2026
ef7ca51
fix(control): after a restart the battery credits the car the meter s…
frahlg Oct 27, 2026
e53aa4b
fix(control): credit a found car only from a current charger sample
frahlg Oct 27, 2026
1a75e9a
Merge ev-base-after-restart into d-fuse-margin-default-0
frahlg Oct 28, 2026
bbb5f1b
test(control): run the site sim at the new 0 A default margin
frahlg Oct 28, 2026
3cf26fd
docs(changeset): say what margin 0 moves once the fuse stack lands
frahlg Oct 28, 2026
427697e
Merge a5-battery-fuse-signed-phases into c-battery-fuse-no-buffer
frahlg Oct 28, 2026
2ee5b71
Merge c-battery-fuse-no-buffer into ev-cut-landed-and-unshown
frahlg Oct 28, 2026
e2faf1e
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
17dc7c2
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
8c1dfce
Merge car-before-battery-charge into ev-base-after-restart
frahlg Oct 28, 2026
021273a
Merge ev-base-after-restart into d-fuse-margin-default-0
frahlg Oct 28, 2026
4ecebfd
test(control): keep the load-balancer bug as a known line above the line
frahlg Oct 28, 2026
97eb612
fix(control): EV room reads battery relief through live telemetry
frahlg Oct 28, 2026
a6da34d
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 28, 2026
daad277
test(site): only a rise extends a stretch; raises after a step are FTW's
frahlg Oct 28, 2026
90d22d4
Merge branch 'rig-judges-r2-r7' into rig-r8-forced-mode-after-return
frahlg Oct 28, 2026
4985523
test(site): a raise over the fuse on import is FTW's own
frahlg Oct 28, 2026
8150b45
fix(control): an offline battery's fuse relief ends after evSettle
frahlg Oct 28, 2026
652df2c
test(site): judge FTW's battery orders as the inverter sees them
frahlg Oct 28, 2026
f8e0097
Merge branch 'rig-judges-r2-r7' into rig-r8-forced-mode-after-return
frahlg Oct 28, 2026
ddab122
fix(control): each offline battery's fuse relief ends after evSettle
frahlg Oct 28, 2026
2c1f827
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 28, 2026
6a5a5f5
fix(control): battery phase relief neither pins mixed phases nor wind…
frahlg Oct 28, 2026
c066892
fix(control): battery phase anti-windup stops only when the meter can…
frahlg Oct 28, 2026
8c3ae3c
fix(control): battery off the worst phase goes back, and a stale refe…
frahlg Oct 28, 2026
b36e951
test(control): the drift test also wants no verdict on the load change
frahlg Oct 28, 2026
3c9ceb7
Merge a5-battery-fuse-signed-phases into c-battery-fuse-no-buffer
frahlg Oct 28, 2026
7d59c5f
Merge c-battery-fuse-no-buffer into ev-cut-landed-and-unshown
frahlg Oct 28, 2026
27561de
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
0fbe100
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
281f9f6
test(control): our battery order's move is not the car's cut landing
frahlg Oct 28, 2026
074f197
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
f29e96c
test(control): the car-first discharge stop has its own test
frahlg Oct 28, 2026
255577e
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
c9b52c3
fix(control): the battery rise check reads only live battery power
frahlg Oct 28, 2026
2928990
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
ab02710
fix(control): judge a raise's landing from the meter's rise
frahlg Oct 28, 2026
53b8aa3
fix(control): a car not yet seen may take a raise on one phase
frahlg Oct 28, 2026
8a10b27
fix(control): judge a one-phase landing reading by reading
frahlg Oct 28, 2026
c0a5274
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
5babe51
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
f294e14
Merge car-before-battery-charge into ev-base-after-restart
frahlg Oct 28, 2026
6b10baa
fix(control): restart credit keeps room for the car's rise to its max
frahlg Oct 28, 2026
19d8a29
test(control): Charge now landing shown before Core logs its offer
frahlg Oct 28, 2026
3623603
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
caacc8d
fix(control): restart credit counts no sample newer than the meter
frahlg Oct 28, 2026
b152e84
Merge car-before-battery-charge into ev-base-after-restart
frahlg Oct 28, 2026
551febd
fix(control): restart credit holds against a charger clock behind Core's
frahlg Oct 28, 2026
b621bab
Merge origin/ev-base-after-restart into d-fuse-margin-default-0
frahlg Oct 28, 2026
a5cdeae
docs(control): the fuse margin is opt-in, and only the fuse ceilings …
frahlg Oct 28, 2026
358da3b
test(control): battery beside a minimum-step car holds the fuse line …
frahlg Oct 28, 2026
fdfbfec
test(config): an unset fuse margin reaches Core as 0
frahlg Oct 28, 2026
a059b6a
Merge branch 'c-battery-fuse-no-buffer' into ev-cut-landed-and-unshown
frahlg Oct 28, 2026
48fb649
Merge branch 'ev-cut-landed-and-unshown' into battery-rise-per-phase-cap
frahlg Oct 28, 2026
5c9c336
Merge branch 'battery-rise-per-phase-cap' into car-before-battery-charge
frahlg Oct 28, 2026
b82e44d
Merge branch 'car-before-battery-charge' into ev-base-after-restart
frahlg Oct 28, 2026
0befc58
Merge branch 'ev-base-after-restart' into d-fuse-margin-default-0
frahlg Oct 28, 2026
dbc4332
test(site): s18 judges own commands apart from the house's step
frahlg Oct 28, 2026
7bfa634
Merge origin/master into b-ev-fuse-line-at-rating
frahlg Oct 28, 2026
0415161
test(site): R8 reads Core's reconnect backoff from source
frahlg Oct 28, 2026
a67aa46
Merge b-ev-fuse-line-at-rating into a5-battery-fuse-signed-phases
frahlg Oct 28, 2026
dbc3a07
Merge a5-battery-fuse-signed-phases into c-battery-fuse-no-buffer
frahlg Oct 28, 2026
fb0b70e
Merge c-battery-fuse-no-buffer into ev-cut-landed-and-unshown
frahlg Oct 28, 2026
dcf4982
fix(control): no cut of an unseen car, no landing from a 1p house move
frahlg Oct 28, 2026
a0a56b7
Merge ev-cut-landed-and-unshown into battery-rise-per-phase-cap
frahlg Oct 28, 2026
7d7b450
Merge battery-rise-per-phase-cap into car-before-battery-charge
frahlg Oct 28, 2026
9793adf
Merge car-before-battery-charge into ev-base-after-restart
frahlg Oct 28, 2026
040ebb1
fix(control): judge a restart sample by its arrival, not its stamp
frahlg Oct 28, 2026
1422d70
Merge ev-base-after-restart into d-fuse-margin-default-0
frahlg Oct 28, 2026
2b30933
test(site): judge overages at the fuse rating, not fuse - 1 A
frahlg Oct 28, 2026
83f3e4a
Merge master into w0-4-rig-scenarios-r1-r5
frahlg Oct 28, 2026
959cae3
test(site): cap a stretch's events by the fuse heat; a car cut into e…
frahlg Oct 28, 2026
55286e3
Merge branch 'rig-judges-r2-r7' into rig-r8-forced-mode-after-return
frahlg Oct 28, 2026
62f1180
Merge pull request #1914 from srcfl/d-fuse-margin-default-0
frahlg Oct 28, 2026
a3f9a7b
Merge pull request #1926 from srcfl/ev-base-after-restart
frahlg Oct 28, 2026
773c4ed
Merge pull request #1925 from srcfl/car-before-battery-charge
frahlg Oct 28, 2026
3260c43
Merge pull request #1924 from srcfl/battery-rise-per-phase-cap
frahlg Oct 28, 2026
49f9699
Merge pull request #1923 from srcfl/ev-cut-landed-and-unshown
frahlg Oct 28, 2026
abd6b23
Merge pull request #1913 from srcfl/c-battery-fuse-no-buffer
frahlg Oct 28, 2026
9867c72
Merge pull request #1891 from srcfl/a5-battery-fuse-signed-phases
frahlg Oct 28, 2026
53d1088
Merge master into the fuse stack
frahlg Oct 28, 2026
7b2dd98
Merge pull request #1922 from srcfl/rig-r8-forced-mode-after-return
frahlg Oct 28, 2026
e9da335
Merge pull request #1908 from srcfl/e2-rig-room-at-fuse
frahlg Oct 28, 2026
cb1b17b
Merge pull request #1907 from srcfl/e1-rig-judges-at-fuse
frahlg Oct 28, 2026
a00c5a6
Merge pull request #1920 from srcfl/rig-judges-r2-r7
frahlg Oct 28, 2026
7a1b857
Merge the fuse stack and master into the rig judges
frahlg Oct 28, 2026
296f38b
Merge master into w0-4-rig-scenarios-r1-r5
frahlg Oct 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions go/test/site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ make siterig-judge DIR=/tmp/ftw-site-123 # judge a recorded run again
| `FTW_SITE_DEVSIM_SRC` | a device-simulator checkout at the pinned commit; without it the test clones the pin into the user cache |
| `FTW_SITE_FTW_BIN`, `FTW_SITE_DEVSIM_BIN` | prebuilt binaries |
| `FTW_SITE_CATALOG` | the fault catalog, for `TestCatalogCoverage` |
| `FTW_SITE_JUDGE` | a results directory: `TestJudge` judges its runs again with the criteria as they are now, and rewrites their `result.json` and the summary |
| `FTW_SITE_JUDGE` | a results directory: `TestJudge` judges its runs again with the criteria as they are now, random seeds included (from each run's `plan.json`), and rewrites their `result.json` and the summary |

Each run directory keeps `house/plant.jsonl` (the house once a second, with
every event and mark), `house/ocpp-<charger>.jsonl` (every OCPP frame the
Expand All @@ -64,7 +64,13 @@ that touch control, loadpoint, OCPP or telemetry code), `siterig/full`

A criterion named in a scenario's `known` map fails on master for the
finding it names. The run passes while it keeps failing, and fails once it
passes: a fix deletes its line in the same pull request.
passes: a fix deletes its line in the same pull request. The `r`
scenarios are R1-R5 of the stable plan; their known lines name the Wave 1
item whose fix deletes them.

A scenario with a `skip` waits for a device-simulator change the pinned
commit lacks. `TestSite` reports it as `skip` with the knob it needs; the
pull request that pins a simulator with the knob deletes the skip.

## The fault catalog

Expand All @@ -76,13 +82,15 @@ its sources (`provenance` in [catalog_test.go](catalog_test.go)).

"Over the limit" is the worst phase above the fuse rating, measured through
the fuse. A device's response time counts as 2 s, the meter and control
tick as 2 s more.
tick as 2 s more. The random cases, `r3` and `r5a` judge a phase between
the fuse and 1.2 × the fuse as Core does: it counts only once its 60 s heat
(I² filter) is above the fuse too.

| Scenario | House and steps | Criteria | Short |
|---|---|---|---|
| `s0-25` Idle charger | 25 A, 3 A per phase, a charger with no car, heartbeat 60 s, 300 s | Home use `measured` in 95 % of samples; no OCPP disconnect | yes |
| `s0b-25` | as s0, Core's heartbeat | as s0 | |
| `s1-16`, `s1-25` Charge now | 3 A per phase, Charge now 16 A for 180 s | the room the fuse gives (25 A: 11 040 W) within 60 s; held 95 %; fuse holds; on 25 A no `fuse_limit` | yes |
| `s1-16`, `s1-25` Charge now | 3 A per phase, Charge now 16 A for 180 s | the room the fuse gives (16 A: 8 970 W; 25 A: 11 040 W) within 60 s; held 95 %; fuse holds; on 25 A no `fuse_limit` | yes |
| `s2-16` Charge now during export | 16 A, 1 A house, 7 kW PV, full battery: 9.1 A export per phase | car starts within 60 s (**known**: export counted as import); fuse holds | |
| `s3-16`, `s3-25` Load step | car and a 3 kW battery hold charging, then 13 A (16 A) or 21 A (25 A) per phase for 180 s | fuse holds; over the limit at most 7 s after the step | yes |
| `s4-25`, `s4b-25` Saved unlock | `surplus_unlock_bat_soc` 0.9 saved, not armed; Charge now 3p, and bare (s4b) | no stops; no offer drops to 0 W; full power over the last minute | |
Expand All @@ -103,5 +111,12 @@ tick as 2 s more.
| `s15bat-16` One-phase charger, battery rising | 16 A, 3 A per phase, the s15 charger, battery at 50 % following its EMS 8 s late, `planner_self`; PV 2.1 kW rising every 30 s (+2.5 kW, then 1.5 kW) so Core charges the battery in steps; Charge now 6 s after the second step, while the raise is on its way | the battery order rose over 1 150 W in the 20 s before (setup check); car charging within 10 s; fuse holds; over the limit at most 3 s | |
| `s15p-25` One-phase charger, planned | as s15, a plan for 600 Wh by the first quarter hour 15 min out | fuse holds; 90 % of the plan by the ready time; never called not following | |
| `s14-25` One-phase car | an 11 kW charger with a one-phase car, a plan it cannot meet, 20 min | 3.4–3.8 kW over the last 10 min; never called not following | |
| `r1-25` Meter silent, then offline | 25 A, 15 A per phase, battery at 50 %, Charge now 16 A; the site meter silent (Modbus timeouts) for 120 s, then gone for 90 s. **Skipped**: the pinned simulator cannot silence the site meter | the battery relieved the fuse (setup); while silent no offer rises and the battery order only moves toward 0 (**known**: A1); a 0 W order and the battery back on its own within 64 s; the meter never shows live; Charge now back within 95 s of each return and held until the next event; fuse holds | |
| `r2-25`, `r2-60-25` Battery drops out | 25 A, 20 A per phase, the battery held at a 3 kW discharge, a car taking 10 A on Charge now, the charger at once or 60 s late; the inverter gone for 180 s. The site stays under 1.2 × the fuse, where Core cuts the car on its 60 s heat budget, not at once | the battery discharged (setup); fuse holds; over 1.2 × the fuse at most the charger's delay + 7 s; the 60 s heat under 1.13 × the fuse; no offer rises while it is gone; Home use shown as estimated throughout. The time over the fuse and when Core sends the cut are recorded | |
| `r3-25` Planner floor | 25 A, 15 A per phase, battery at 12 %, planner `soc_min` 10 %, inverter floor 5 %, charger 60 s late, Charge now 16 A for 600 s | the battery reaches the floor (setup); no discharge ordered below it (**known**: A4); the battery order swings at most 100 W over the last 5 min (**known**: A3, A4); over the fuse at most the delay + 7 s; fuse holds | |
| `r4-25` Hard kill | 25 A, 12 A per phase, Charge now 16 A; once the day's Home use is known and 10 min more, the battery held at a 3 kW discharge; 5 min later SIGKILL for 20 s, and 2 min after that for 120 s while the house steps to 16 A | Charge now back at its minimum within 60 s of each restart and held until the next kill or the end; the day's Home use kept within 1 % across the first kill; session energy counts again (**known**: E1); no state.db recovery in the log; fuse holds | |
| `r5a-25` Start beside a charging car | 25 A, 14 A per phase, battery at its 5 % floor, a car charging on its own at 16 A: 30 A per phase for 60 s before Core starts | the car charged and the site was over the fuse (setup); under the fuse within 30 s of Core answering, and over it at most 3 s after; Home use shown within 30 s; fuse holds | |
| `r5b-25` Start on a stale plan | a goal 40 → 60 % 8 h out, Core stopped for 20 min | no positive order in the first 30 s before a fresh plan; Home use shown within 30 s; fuse holds. It does not reach D6 on master: the saved plan is younger than 30 min and a fresh one lands within seconds | |
| `r5c-25` Start into a new session | Charge now, Core stopped for 10 min while the car leaves and another plugs in | Core sees the car within 60 s; Home use shown within 30 s; fuse holds. Whether Charge now carries over is recorded, not judged: ev-088 waits for the owner | |
| `s16-25` Import ceiling | 25 A, house 1.3 kW, battery idle at its floor, `peak_import_ceiling_w` 4 500, Charge now 16 A: house and the car's 4 140 W minimum are above the ceiling. Starts in an hour's first minutes or waits for :56, then runs one whole clock hour and 3 min | the car starts on the hour's room before :45; every clock hour's recorded import averages at most the ceiling + 1 %; the next hour stops the car within 60 s; while held it says `import_limit` 90 % of the time and never `fuse_limit`; fuse holds | |
| `s17-25` Two equal batteries | 25 A, house 3 kW, no PV, two hybrids with 10 kWh at 74 % and 60 %, Energyplan whatever `FTW_SITE_ENGINE` says (Core DP plans one battery), a 6 h horizon. Waits up to an hour for a quarter the plan discharges, then 15 min | Energyplan's plan moves the batteries in half the polls (setup); while the fleet moves 500 W or more, each battery takes at least a quarter of it 90 % of the time; while the plan moves them, the charge gap shrinks by over 0.2 points; fuse holds | |
8 changes: 8 additions & 0 deletions go/test/site/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ var provenance = map[string]struct {
"s15p-25": {nil, []string{"https://github.com/srcfl/ftw/pull/1804", "release blocker 22 Oct 2026: a one-phase charger, planned charging"}},
"s16-25": {nil, []string{"https://github.com/srcfl/ftw/pull/1828", "help report 25 Oct 2026: an idle car held at 0 W for an hour under a 4.5 kW import ceiling"}},
"s17-25": {nil, []string{"https://github.com/srcfl/ftw/pull/1814", "field report 23 Oct 2026, v0.155.1-beta.1: two equal Pixii batteries take turns"}},
"r1-25": {[]string{"tel-001", "tel-006", "tel-007", "bat-074"}, []string{"stable plan 27 Oct 2026, R1"}},
"r2-25": {[]string{"tel-007", "tel-022", "ev-090", "ev-075"}, []string{"stable plan 27 Oct 2026, R2"}},
"r2-60-25": {[]string{"tel-007", "tel-022", "ev-090", "ev-075"}, []string{"stable plan 27 Oct 2026, R2"}},
"r3-25": {[]string{"ev-099", "ev-090"}, []string{"stable plan 27 Oct 2026, R3"}},
"r4-25": {[]string{"ev-085", "ev-091", "home-061", "home-074", "ocpp-008", "upd-051"}, []string{"stable plan 27 Oct 2026, R4", "https://github.com/srcfl/ftw/pull/1787"}},
"r5a-25": {[]string{"ev-076", "dev-100"}, []string{"stable plan 27 Oct 2026, R5"}},
"r5b-25": {[]string{"ev-076"}, []string{"stable plan 27 Oct 2026, R5", "https://github.com/srcfl/ftw/issues/1718"}},
"r5c-25": {[]string{"ev-088"}, []string{"stable plan 27 Oct 2026, R5"}},
}

func TestEveryScenarioSaysWhereItComesFrom(t *testing.T) {
Expand Down
189 changes: 181 additions & 8 deletions go/test/site/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@ type plantDevice struct {
W float64 `json:"w"` // a charger's draw
BatteryW float64 `json:"battery_w"` // an inverter's battery, + charging
SoCPct float64 `json:"soc_pct"`
EMSCmd float64 `json:"ems_cmd"` // 170 charge, 187 discharge, 204 stop
EMSMode float64 `json:"ems_mode"` // 2 forced, as Core drives it
EMSCmd float64 `json:"ems_cmd"` // 170 charge, 187 discharge, 204 stop
EMSSetW float64 `json:"ems_setpoint_w"`
Connected bool `json:"connected"`
Running *bool `json:"running"` // an inverter that answers; nil when not recorded
}

type ftwStatus struct {
Drivers map[string]struct {
Status string `json:"status"`
} `json:"drivers"`
LoadQuality *string `json:"load_quality"`
LoadReason *string `json:"load_reason"`
LoadW *float64 `json:"load_w"`
Drivers map[string]ftwDriver `json:"drivers"`
Dispatch []ftwDispatch `json:"dispatch"` // Core's battery orders this tick
LoadQuality *string `json:"load_quality"`
LoadReason *string `json:"load_reason"`
LoadW *float64 `json:"load_w"`
Energy struct {
Today struct {
LoadWh *float64 `json:"load_wh"`
Expand All @@ -62,13 +63,26 @@ type ftwStatus struct {
} `json:"energy"`
}

// ftwDispatch is one battery order Core sent: + charge, - discharge.
type ftwDispatch struct {
Driver string `json:"driver"`
TargetW float64 `json:"target_w"`
}

type ftwDriver struct {
Status string `json:"status"`
EVSessionWh *float64 `json:"ev_session_wh"` // a charger's session energy
ConsecutiveErrors *int `json:"consecutive_errors"` // failed polls in a row; 0 once a poll reads
}

type ftwLoadpoint struct {
ID string `json:"id"`
Plugged bool `json:"plugged_in"`
Phases int `json:"phases"`
Charger struct {
Known bool `json:"known"`
} `json:"charger"`
ManualActive bool `json:"manual_active"`
CommandedReason string `json:"commanded_reason"`
Manual struct {
LimitReason string `json:"limit_reason"` // the clamp behind a limited Charge now
Expand Down Expand Up @@ -102,6 +116,7 @@ type sample struct {
Bat2 plantDevice // the second, if any
Status *ftwStatus
LPs []ftwLoadpoint
HeatA [3]float64 // each phase's 60 s heat, filled in by warm
}

type frame struct {
Expand All @@ -125,6 +140,7 @@ type runData struct {
events []houseEventLine
frames []frame // garage's charger
meta map[string]any
warmed bool // every sample's HeatA is filled in
}

type markLine struct {
Expand Down Expand Up @@ -340,6 +356,24 @@ func (d *runData) firstT(t0 float64, pred func(*sample) bool) *float64 {
return nil
}

// holdsFrom is the seconds from t0 to the start of the unbroken run of
// samples satisfying pred that lasts until t1, or nil when the last sample
// before t1 does not. A stop that begins after t0 resets it, so a car still
// running at t0 and stopped later does not count as back.
func (d *runData) holdsFrom(t0, t1 float64, pred func(*sample) bool) *float64 {
var from *float64
for _, r := range d.window(t0, t1) {
switch {
case !pred(r):
from = nil
case from == nil:
v := r.T - t0
from = &v
}
}
return from
}

// runsOver is the longest contiguous stretch and the total seconds with the
// worst phase above limit.
func (d *runData) runsOver(t0, t1, limit float64) (longest, total float64) {
Expand Down Expand Up @@ -367,10 +401,72 @@ func (d *runData) runsOver(t0, t1, limit float64) (longest, total float64) {
return round(longest, 1), round(total, 1)
}

// fuseHeatTauS is the time constant of Core's fuse heat model
// (control/fuse_heat.go).
const fuseHeatTauS = 60.0

// warm fills in each sample's HeatA: per phase, the 60 s I² filter of Core's
// fuse heat model, on the current through the fuse in either direction,
// from the record's first sample on.
func (d *runData) warm() {
if d.warmed {
return
}
d.warmed = true
var sq [3]float64
for i, r := range d.samples {
for k, a := range r.PhaseA {
if i == 0 {
sq[k] = a * a
} else {
sq[k] += (1 - math.Exp(-(r.T-d.samples[i-1].T)/fuseHeatTauS)) * (a*a - sq[k])
}
r.HeatA[k] = math.Sqrt(sq[k])
}
}
}

// heatOver is whether a phase is over the fuse as Core's heat model judges
// it (owner rule, 27 Oct 2026): above the fuse while its 60 s heat is above
// the fuse too, or above fuseInstantFactor x the fuse. Between the fuse and
// that factor the heat is the budget. Call warm first.
func heatOver(r *sample, fuse float64) bool {
for k, a := range r.PhaseA {
a = math.Abs(a)
if a > fuse && (r.HeatA[k] > fuse || a > fuseInstantFactor*fuse) {
return true
}
}
return false
}

// heatRunsOver is the longest stretch in [t0, t1] that heatOver holds,
// timed like runsOver.
func (d *runData) heatRunsOver(t0, t1, fuse float64) float64 {
d.warm()
longest := 0.0
var from *float64
var last float64
for _, r := range d.window(t0, t1) {
t := r.T
switch {
case heatOver(r, fuse) && from == nil:
from = &t
case !heatOver(r, fuse) && from != nil:
longest, from = math.Max(longest, t-*from), nil
}
last = t
}
if from != nil {
longest = math.Max(longest, last-*from)
}
return round(longest, 1)
}

// i2Over is the seconds the worst phase's I² filter (tau 60 s) is above
// limit, and the filter's peak.
func (d *runData) i2Over(t0, t1, limit float64) (over, peak float64) {
const tau = 60.0
const tau = fuseHeatTauS
var y, prev float64
started := false
for _, r := range d.window(t0, t1) {
Expand Down Expand Up @@ -686,3 +782,80 @@ func (d *runData) disconnects(t0, t1 float64) []float64 {
})
return out
}

// ---- the battery, the charger's orders and the log, for R1-R5 ----

// batOrder is Core's battery order as the inverter holds it: + charge, -
// discharge, 0 when not forced.
func batOrder(r *sample) float64 {
if r.Bat.EMSMode != 2 {
return 0
}
switch r.Bat.EMSCmd {
case 170:
return r.Bat.EMSSetW
case 187:
return -r.Bat.EMSSetW
}
return 0
}

// batForced is true while Core drives the battery: forced mode with a charge
// or discharge command.
func batForced(r *sample) bool {
return r.Bat.EMSMode == 2 && (r.Bat.EMSCmd == 170 || r.Bat.EMSCmd == 187)
}

// offers is every SetChargingProfile on connector 1 of charger 0, timed in
// Unix seconds.
func (d *runData) offers() []profile { return connector1(profiles(d.frames, 0, math.Inf(1))) }

// offerRises counts orders sent in [t0, t1) that offer more than the order
// before them.
func (d *runData) offerRises(t0, t1 float64) int {
n := 0
prs := d.offers()
for i := 1; i < len(prs); i++ {
if prs[i].T >= t0 && prs[i].T < t1 && prs[i].offerW() > prs[i-1].offerW()+1 {
n++
}
}
return n
}

// firstOffer is the seconds from t0 to the first order from t0 on that
// satisfies pred, or nil.
func (d *runData) firstOffer(t0 float64, pred func(profile) bool) *float64 {
for _, p := range d.offers() {
if p.T >= t0 && pred(p) {
v := p.T - t0
return &v
}
}
return nil
}

// logLines are the lines of FTW's log that hold any of subs.
func (d *runData) logLines(subs ...string) []string {
var out []string
readLines(filepath.Join(d.dir, "ftw.log"), func(b []byte) {
for _, s := range subs {
if strings.Contains(string(b), s) {
out = append(out, string(b))
return
}
}
})
return out
}

// todayLoadWh is the day's Home use FTW last showed in ws, or nil.
func todayLoadWh(ws []*sample) *float64 {
var v *float64
for _, r := range ws {
if r.Status != nil && r.Status.Energy.Today.LoadWh != nil {
v = r.Status.Energy.Today.LoadWh
}
}
return v
}
Loading
Loading