Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions go/test/site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ its sources (`provenance` in [catalog_test.go](catalog_test.go)).

## Scenarios

"Over the limit" is the worst phase above the fuse − 1 A, measured through
"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.

| 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 Down
3 changes: 1 addition & 2 deletions go/test/site/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ func le(p *float64, limit float64) bool { return p != nil && *p <= limit }
func (d *runData) overage(t0, t1, fuse float64) metrics {
w := d.window(t0, t1)
m := metrics{"max_i": round(maxOf(w, maxAbsI), 2)}
m["over_limit_longest_s"], m["over_limit_total_s"] = d.runsOver(t0, t1, fuse-1)
m["over_fuse_longest_s"], _ = d.runsOver(t0, t1, fuse)
m["over_limit_longest_s"], m["over_limit_total_s"] = d.runsOver(t0, t1, fuse)
m["fuse_damage_max"] = round(maxOf(w, damage), 4)
m["fuse_blown"] = anyBlown(w)
return m
Expand Down
9 changes: 5 additions & 4 deletions go/test/site/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ type eventWindow struct{ from, to float64 }

func judgeInvariants(d *runData) (metrics, []criterion) {
fuse := d.metaF("fuse")
limit := fuse - 1
h := d.timing()
t0, t1 := d.marks["start"], d.marks["end"]
run := d.window(t0, t1)
Expand Down Expand Up @@ -270,7 +269,7 @@ func judgeInvariants(d *runData) (metrics, []criterion) {
var firstBad float64
var start *sample
for i, r := range run {
over := maxAbsI(r) > limit
over := maxAbsI(r) > fuse
if over && start == nil {
start = r
}
Expand Down Expand Up @@ -368,8 +367,10 @@ func judgeInvariants(d *runData) (metrics, []criterion) {
for _, hw := range holds {
run4 = 0
for i, r := range d.window(hw.from+grace, hw.to) {
roomA := limit - (maxAbsI(r) - carW(r, 0)/(3*volt))
bad := carW(r, 0) < 0.5*1380 && roomA >= 7 && !inFault(r.T) && !nearRestart(r.T)
// Room below the fuse, the car's line in Core; 6 A is the car's
// minimum on three phases.
roomA := fuse - (maxAbsI(r) - carW(r, 0)/(3*volt))
bad := carW(r, 0) < 0.5*1380 && roomA >= 6 && !inFault(r.T) && !nearRestart(r.T)
if bad && i > 0 {
run4++
idle = math.Max(idle, run4)
Expand Down
124 changes: 123 additions & 1 deletion go/test/site/rig_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package site

import (
"encoding/json"
"slices"
"testing"
)

Expand Down Expand Up @@ -113,7 +114,7 @@ func TestInvariantsTellStepsFromOwnRaises(t *testing.T) {
for i := 0; i <= 100; i++ {
a := 10.0
if i >= 50 && i < 56 {
a = 26 // 6 s over the 24 A limit
a = 26 // 6 s over the 25 A fuse
}
d.samples = append(d.samples, &sample{T: float64(i), PhaseA: [3]float64{a, a, a}, Bat: plantDevice{SoCPct: 50}})
}
Expand All @@ -139,3 +140,124 @@ func TestInvariantsTellStepsFromOwnRaises(t *testing.T) {
t.Fatalf("without a step: %v", f)
}
}

// The limit is the fuse rating: a phase may sit at exactly the fuse until
// the end of the run, and 0.1 A above it fails once the time budget is up.
func TestInvariantsJudgeAtTheFuse(t *testing.T) {
const fuse = 25.0
const own = "over the limit at most 3 s after FTW's own raise"
const step = "over the limit no longer than an outside step allows"
for _, c := range []struct {
name string
a float64
to int // the level holds from 50 s until this second
withStep bool
want []string
}{
{"at the fuse", fuse, 101, false, nil},
{"at the fuse after a step", fuse, 101, true, nil},
// 20 s is past the 3 s for FTW's own raise, and past the
// 2 + 2 + 3 s a step allows while the battery can answer.
{"0.1 A over", fuse + 0.1, 70, false, []string{own}},
{"0.1 A over after a step", fuse + 0.1, 70, true, []string{step}},
} {
d := &runData{marks: map[string]float64{"start": 0, "end": 100}, meta: map[string]any{"fuse": fuse}}
for i := 0; i <= 100; i++ {
a := 10.0
if i >= 50 && i < c.to {
a = c.a
}
d.samples = append(d.samples, &sample{T: float64(i), PhaseA: [3]float64{a, a, a}, Bat: plantDevice{SoCPct: 50}})
}
if c.withStep {
d.events = append(d.events, houseEventLine{T: 49.5, Event: houseEvent{Do: "loads"}})
}
var failed []string
_, cs := judgeInvariants(d)
for _, x := range cs {
if !x.OK {
failed = append(failed, x.Name)
}
}
if !slices.Equal(failed, c.want) {
t.Errorf("%s: failed %v, want %v", c.name, failed, c.want)
}
}
}

// S1 expects the room the fuse rating gives: on 16 A with a 3 A house that
// is 13 A per phase, 8 970 W. The old line at fuse - 1 A (8 280 W) falls
// short of it.
func TestJudgeS1ExpectsTheRoomAtTheFuse(t *testing.T) {
const name = "target within 60 s"
for _, c := range []struct {
carW float64
want bool
}{{8970, true}, {8280, false}} {
d := synth(181, map[string]float64{"charge_now": 0, "end": 180}, map[string]any{"fuse": 16.0, "house_a": 3},
func(i int, r *sample) {
if i >= 10 {
r.CarW = []float64{c.carW}
}
})
m, cs := judgeS1(d)
if m["target_w"] != 8970.0 {
t.Fatalf("target_w = %v, want 8970", m["target_w"])
}
if got := verdictsOf(cs)[name]; got != c.want {
t.Errorf("car at %v W: %q = %v, want %v", c.carW, name, got, c.want)
}
}
}

// S12 counts a cut as one on room alone while every phase is under the fuse
// by more than 0.1 A, and records fuse_limit while the worst phase has 6 A.
func TestJudgeS12MeasuresRoomAtTheFuse(t *testing.T) {
const fuse = 20.0
for _, c := range []struct {
name string
a float64 // the worst phase when the order drops
cuts, limit int
}{
{"at the fuse", fuse, 0, 0},
{"0.1 A under", fuse - 0.1, 0, 0},
{"0.5 A under", fuse - 0.5, 1, 0},
{"5.5 A under", fuse - 5.5, 1, 0},
{"6.5 A under", fuse - 6.5, 1, 1},
} {
d := synth(121, map[string]float64{"plan": 0, "ready": 100, "end": 120}, map[string]any{"fuse": fuse, "plan_wh": 6600.0},
func(i int, r *sample) {
r.PhaseA = [3]float64{c.a, c.a - 1, c.a - 2}
if i == 30 {
r.LPs = []ftwLoadpoint{{CommandedReason: "fuse_limit"}}
}
})
d.frames = []frame{profileAt(10, 16), profileAt(20, 10)}
m, _ := judgeS12(d)
if m["cuts_with_room"] != c.cuts || m["fuse_limit_with_room_s"] != c.limit {
t.Errorf("%s: cuts %v, fuse_limit %v; want %d, %d", c.name, m["cuts_with_room"], m["fuse_limit_with_room_s"], c.cuts, c.limit)
}
}
}

// During Charge now an idle car is a fault once the house leaves the car's
// 6 A minimum under the fuse; with less room it is not.
func TestInvariantsChargeNowRoomAtTheFuse(t *testing.T) {
const fuse = 25.0
const name = "Charge now charges when there is room"
for _, c := range []struct {
houseA float64
want bool
}{{fuse - 6, false}, {fuse - 5.5, true}} {
d := synth(201, map[string]float64{"start": 0, "end": 200}, map[string]any{"fuse": fuse},
func(_ int, r *sample) {
r.PhaseA = [3]float64{c.houseA, c.houseA, c.houseA}
r.Bat.SoCPct = 50
})
d.allMarks = []markLine{{T: 1, Label: "ftw:charge_now"}, {T: 200, Label: "end"}}
_, cs := judgeInvariants(d)
if got := verdictsOf(cs)[name]; got != c.want {
t.Errorf("house %v A: %q = %v, want %v", c.houseA, name, got, c.want)
}
}
}
16 changes: 8 additions & 8 deletions go/test/site/scenarios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,10 @@ func judgeS12(d *runData) (metrics, []criterion) {
if p.Limit > 0 && p.phasesOr3() == 1 {
ones++
}
// A lower order while every phase has room is a cut on room alone,
// unless the plan itself asked for less (a pause between slots).
// A lower order while every phase is under the fuse is a cut on room
// alone, unless the plan itself asked for less (a pause between slots).
if i > 0 && p.offerW() < prs[i-1].offerW()-1 {
if r := d.at(t0 + p.T); r != nil && maxAbsI(r) < fuse-1-0.5 {
if r := d.at(t0 + p.T); r != nil && maxAbsI(r) < fuse-0.1 {
if after := d.at(t0 + p.T + 2); after == nil || firstLP(after).CommandedReason != "plan" {
cuts++
}
Expand All @@ -726,7 +726,7 @@ func judgeS12(d *runData) (metrics, []criterion) {
// recorded, not judged, since a slow charger's pending order may hold it.
limited := 0
for _, r := range w {
if r.LPs != nil && firstLP(r).CommandedReason == "fuse_limit" && maxAbsI(r) < fuse-1-6 {
if r.LPs != nil && firstLP(r).CommandedReason == "fuse_limit" && maxAbsI(r) < fuse-6 {
limited++
}
}
Expand Down Expand Up @@ -1015,21 +1015,21 @@ func judgeS15bat(d *runData) (metrics, []criterion) {
start := d.firstT(t0, func(r *sample) bool { return carW(r, 0) >= 0.95*1380 })
over, longest := 0.0, 0.0
for _, r := range d.window(t0, t1) {
if maxAbsI(r) > fuse-1 {
if maxAbsI(r) > fuse {
over++
longest = math.Max(longest, over)
} else {
over = 0
}
}
m := metrics{"battery_rise_w_20s_before": math.Round(rise), "car_start_s": roundp(start, 1),
"car_w_last60": math.Round(meanOf(d.window(t1-60, t1), func(r *sample) float64 { return carW(r, 0) })),
"over_fuse_minus1_longest_s": longest, "max_abs_i": round(maxOf(d.window(t0, t1), maxAbsI), 1)}
"car_w_last60": math.Round(meanOf(d.window(t1-60, t1), func(r *sample) float64 { return carW(r, 0) })),
"over_fuse_longest_s": longest, "max_abs_i": round(maxOf(d.window(t0, t1), maxAbsI), 1)}
return m, []criterion{
crit("the battery order rose over 1 150 W in the 20 s before Charge now", rise > 1150), // the setup
crit("car charging within 10 s of Charge now", le(start, 10)),
crit("fuse holds", !anyBlown(d.window(t0, t1))),
crit("over fuse - 1 A at most 3 s", longest <= 3),
crit("over the fuse at most 3 s", longest <= 3),
}
}

Expand Down
4 changes: 3 additions & 1 deletion go/test/site/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,9 @@ func (st *stack) ftwConfig() (string, error) {
cfg := map[string]any{
"site": map[string]any{"name": "rig", "control_interval_s": 2, "grid_target_w": 0,
"grid_tolerance_w": 42, "watchdog_timeout_s": 60},
"fuse": map[string]any{"max_amps": st.spec.fuseA, "phases": 3, "voltage": 230},
// safety_margin_a pinned at 0 so the rig judges Core at the rating
// whatever the default.
"fuse": map[string]any{"max_amps": st.spec.fuseA, "phases": 3, "voltage": 230, "safety_margin_a": 0},
"drivers": []map[string]any{
{"name": "meter", "lua": "drivers/sdm630.lua", "is_site_meter": true, "capabilities": modbus("meter")},
{"name": "sungrow", "lua": "drivers/sungrow.lua", "battery_capacity_wh": 10000, "capabilities": modbus("inverter")},
Expand Down
42 changes: 20 additions & 22 deletions go/test/site/verdicts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ func judgeS1(d *runData) (metrics, []criterion) {
fuse := d.metaF("fuse")
target := maxW
if fuse < 25 {
// Room on a 16 A fuse: fuse - 1 A margin - house, in 1 A steps.
target = math.Min(maxW, math.Floor(fuse-1-d.metaF("house_a"))*volt*3)
// Room on a 16 A fuse: fuse - house, in 1 A steps. Core works to
// the rating; safety_margin_a is a site's opt-in and the rig sets 0.
// The target is a floor, not the line: the battery (SoC 50) covers
// the house, so a Core that stops at fuse - 1 A also passes.
target = math.Min(maxW, math.Floor(fuse-d.metaF("house_a"))*volt*3)
}
m := d.carSummary(t0, t1, target)
m["target_w"] = target
Expand Down Expand Up @@ -87,11 +90,10 @@ func judgeS3(d *runData) (metrics, []criterion) {
"pre_step_max_i": round(maxOf(pre, maxAbsI), 2),
}
m["post_step_max_i"] = round(maxOf(d.window(tStep, tBack), maxAbsI), 2)
m["over_fuse_longest_s"], m["over_fuse_total_s"] = d.runsOver(tStep, tBack, fuse)
overLongest, overTotal := d.runsOver(tStep, tBack, fuse-1)
m["over_fuse_minus1_longest_s"], m["over_fuse_minus1_total_s"] = overLongest, overTotal
m["i2_over_fuse_minus1_s"], m["i2_peak_a"] = d.i2Over(tCN, t1, fuse-1)
m["back_under_fuse_minus1_s"] = roundp(d.firstT(tStep, func(r *sample) bool { return maxAbsI(r) <= fuse-1 && r.T > tStep+1 }), 1)
overLongest, overTotal := d.runsOver(tStep, tBack, fuse)
m["over_fuse_longest_s"], m["over_fuse_total_s"] = overLongest, overTotal
m["i2_over_fuse_s"], m["i2_peak_a"] = d.i2Over(tCN, t1, fuse)
m["back_under_fuse_s"] = roundp(d.firstT(tStep, func(r *sample) bool { return maxAbsI(r) <= fuse && r.T > tStep+1 }), 1)
last := d.window(tBack-60, tBack)
m["post_step_car_w_last60"] = math.Round(meanOf(last, func(r *sample) float64 { return carW(r, 0) }))
m["post_step_bat_w_last60"] = math.Round(meanOf(last, batSigned))
Expand All @@ -107,15 +109,12 @@ func judgeS3(d *runData) (metrics, []criterion) {
// Device response + meter and tick (2 + 2 s) + 3 s.
allowed := d.metaF("charger_delay_s") + 2 + 2 + 3
m["allowed_over_s"] = allowed
m["run_over_fuse_minus1_longest_s"], _ = d.runsOver(tCN, t1, fuse-1)
m["run_over_fuse_longest_s"], _ = d.runsOver(tCN, t1, fuse)
m["run_max_i"] = round(maxOf(after, maxAbsI), 2)
// Before the step, layers with different margins may hold a phase
// between fuse - 1 A and fuse - 0.5 A; reported, not judged.
m["pre_step_over_fuse_minus1_longest_s"], _ = d.runsOver(tCN, tStep, fuse-1)
m["pre_step_over_fuse_minus_half_longest_s"], _ = d.runsOver(tCN, tStep, fuse-0.5)
m["pre_step_over_fuse_longest_s"], _ = d.runsOver(tCN, tStep, fuse)
return m, []criterion{
crit("fuse holds", !isBlown),
crit("over fuse - 1 A no longer than the response time + 3 s after the step", overLongest <= allowed),
crit("over the fuse no longer than the response time + 3 s after the step", overLongest <= allowed),
}
}

Expand Down Expand Up @@ -414,10 +413,9 @@ func judgeS8(d *runData) (metrics, []criterion) {
fuse := d.metaF("fuse")
t0, t1 := d.marks["charge_now"], d.marks["end"]
m := d.carSummary(t0, t1, maxW)
m["over_fuse_longest_s"], m["over_fuse_total_s"] = d.runsOver(t0, t1, fuse)
overLongest, overTotal := d.runsOver(t0, t1, fuse-1)
m["over_fuse_minus1_longest_s"], m["over_fuse_minus1_total_s"] = overLongest, overTotal
m["i2_over_fuse_minus1_s"], m["i2_peak_a"] = d.i2Over(t0, t1, fuse-1)
overLongest, overTotal := d.runsOver(t0, t1, fuse)
m["over_fuse_longest_s"], m["over_fuse_total_s"] = overLongest, overTotal
m["i2_over_fuse_s"], m["i2_peak_a"] = d.i2Over(t0, t1, fuse)
var prs [][2]float64
for i, p := range connector1(profiles(d.frames, t0, t1)) {
if i >= 20 {
Expand All @@ -435,7 +433,7 @@ func judgeS8(d *runData) (metrics, []criterion) {
}
return m, []criterion{
crit("fuse holds", !m["fuse_blown"].(bool)),
crit("over fuse - 1 A no longer than the charger's delay + 7 s", overLongest <= allowed),
crit("over the fuse no longer than the charger's delay + 7 s", overLongest <= allowed),
}
}

Expand All @@ -461,8 +459,8 @@ func judgeS9(d *runData) (metrics, []criterion) {
m["profiles_after_switch"] = seq
return m, []criterion{
crit("fuse holds", !before["fuse_blown"].(bool) && !after["fuse_blown"].(bool)),
crit("over fuse - 1 A at most 3 s on 3p", before["over_limit_longest_s"].(float64) <= 3),
crit("over fuse - 1 A at most 3 s after the switch to 1p", after["over_limit_longest_s"].(float64) <= 3),
crit("over the fuse at most 3 s on 3p", before["over_limit_longest_s"].(float64) <= 3),
crit("over the fuse at most 3 s after the switch to 1p", after["over_limit_longest_s"].(float64) <= 3),
}
}

Expand Down Expand Up @@ -502,7 +500,7 @@ func judgeS10(d *runData) (metrics, []criterion) {
}
return m, []criterion{
crit("fuse holds", !before["fuse_blown"].(bool) && !after["fuse_blown"].(bool)),
crit("over fuse - 1 A at most 3 s after the step", after["over_limit_longest_s"].(float64) <= 3),
crit("over the fuse at most 3 s after the step", after["over_limit_longest_s"].(float64) <= 3),
}
}

Expand Down Expand Up @@ -549,7 +547,7 @@ func judgeS11(d *runData) (metrics, []criterion) {
}
return m, []criterion{
crit("an offer within 60 s of the restart", le(firstPosS, 60)),
crit("over fuse - 1 A at most 3 s", run["over_limit_longest_s"].(float64) <= 3),
crit("over the fuse at most 3 s", run["over_limit_longest_s"].(float64) <= 3),
crit("fuse holds", !run["fuse_blown"].(bool)),
}
}
Expand Down