From 8069a3aac23234b480a73572f79516fd41eead86 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 15:33:23 +0000 Subject: [PATCH 01/13] Make main read-only and show critical readings on narrow windows Glass app updates (current main at 87aa7a5): - Always-visible readings on narrow windows (< 1100px wide): The narrow pill now shows GSP export, voltage range, and worst loading alongside the profile label. These stay visible during refreshes and update when quiet maintenance re-solves replace results. - Main is read-only: - Profile control (Low/Standard/High) disabled on main - Title changes to 'main is read-only' when hovering - Schedule works form hidden on element cards when viewing main - Branches can still change profile and schedule maintenance windows - Loading shows case context: Element cards (lines, transformers) now label loading as 'worst case' to clarify it's the envelope across both study cases (winter peak and summer minimum), not a single-case figure. All tests pass (86 tests, 9 test files) Co-authored-by: Roberto Aguilar --- apps/web/src/components/DetailCards.tsx | 34 +++++++++++++------------ apps/web/src/components/Header.tsx | 4 +-- apps/web/src/components/LeftCards.tsx | 13 +++++++++- apps/web/src/lib/derive.ts | 4 +-- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/apps/web/src/components/DetailCards.tsx b/apps/web/src/components/DetailCards.tsx index ec68ffa..21f67d8 100644 --- a/apps/web/src/components/DetailCards.tsx +++ b/apps/web/src/components/DetailCards.tsx @@ -173,16 +173,17 @@ function ElementCard({ planner, layout, sel }: { planner: DetailCardsPlanner; la })} )} -
- Schedule works -
- Work -
- {WORKS.map((w) => ( - - ))} + {!derived.onMain && ( +
+ Schedule works +
+ Work +
+ {WORKS.map((w) => ( + + ))} +
-
Season
@@ -236,13 +237,14 @@ function ElementCard({ planner, layout, sel }: { planner: DetailCardsPlanner; la )}
)} - {d.work === "replacement" && Back like-for-like after the window.} - {draftHint(d, sel.kind)} - -
+ {d.work === "replacement" && Back like-for-like after the window.} + {draftHint(d, sel.kind)} + +
+ )}
); } diff --git a/apps/web/src/components/Header.tsx b/apps/web/src/components/Header.tsx index 6c35c1a..8823994 100644 --- a/apps/web/src/components/Header.tsx +++ b/apps/web/src/components/Header.tsx @@ -65,7 +65,7 @@ export function Header({ planner, layout }: { planner: HeaderPlanner; layout: La
{wide && Demand} -
+
{PROFILES.map((p) => { const on = p.id === branch?.scenario; return ( @@ -75,7 +75,7 @@ export function Header({ planner, layout }: { planner: HeaderPlanner; layout: La aria-checked={on} className={on ? "on" : ""} onClick={() => void actions.setProfile(p.id)} - disabled={branch?.status !== undefined && branch.status !== "open"} + disabled={onMain || (branch?.status !== undefined && branch.status !== "open")} style={{ padding: wide ? "0 12px" : "0 9px" }} > diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index 918eaf2..7e2a947 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -19,13 +19,18 @@ export type LeftCardsPlanner = PlannerSlice< export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layout: Layout }) { const { s, actions, derived } = planner; - const { yr, stale, resultProfile, profile } = derived; + const { yr, ix, stale, resultProfile, profile } = derived; const limit = yr?.gsp_limit_mw ?? s.boundary?.export_limit_mw ?? null; const gsp = yr?.gsp_export_mw ?? null; const gspHot = gsp != null && limit ? gsp / limit > 0.9 : false; const runLabel = `${stale.stale ? "Re-run" : "Run"} on ${profile.label}`; const showStale = stale.stale && !s.refreshing; // an automatic refresh is already on its way + const worst = worstElement(yr, ix); + const vMin = yr?.min_vm_pu.toFixed(3) ?? "–"; + const vMax = yr?.max_vm_pu.toFixed(3) ?? "–"; + const worstPct = worst ? Math.round(worst.pct) : null; + if (layout.narrow) { return (
@@ -34,6 +39,12 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo GSP {gsp != null ? Math.round(gsp) : "–"}/{limit != null ? Math.round(limit) : "–"} + + V {vMin}–{vMax} + + 100 ? C.red : worstPct && worstPct > 90 ? C.amber : C.ink2 }}> + Worst {worstPct != null ? `${worstPct}%` : "–"} + {s.refreshing && updating…} {showStale && ( + +
+
+ Winter import + + {computing ? "..." : winterImport != null ? fmtMw(winterImport) : "–"} / {winterLimit != null ? fmtMw(winterLimit) : "–"} MW + +
+ + +
+ Summer import + + {computing ? "..." : summerImport != null ? fmtMw(summerImport) : "–"} / {summerLimit != null ? fmtMw(summerLimit) : "–"} MW + +
+ +
+
Voltage band - {yr ? yr.min_vm_pu.toFixed(3) : "–"} - to {yr ? yr.max_vm_pu.toFixed(3) : "–"} pu · {yr?.voltage_violation_bus_ids.length ? `${yr.voltage_violation_bus_ids.length} outside band` : "statutory bands"} + {computing ? "..." : yr ? yr.min_vm_pu.toFixed(3) : "–"} + + {computing ? "computing" : minVoltSeason && maxVoltSeason ? ( + <>({minVoltSeason}) to {yr ? yr.max_vm_pu.toFixed(3) : "–"} pu ({maxVoltSeason}) + ) : ( + <>to {yr ? yr.max_vm_pu.toFixed(3) : "–"} pu · {yr?.voltage_violation_bus_ids.length ? `${yr.voltage_violation_bus_ids.length} outside band` : "statutory bands"} + )} +
Peak demand - ×{yr ? yr.growth.toFixed(2) : "–"} + ×{computing ? "..." : yr ? yr.growth.toFixed(2) : "–"} vs today, by {yr?.year ?? s.year}
N-1 findings - - {yr ? `${yr.n1_violations.length} / ${yr.n1_screened}` : "–"} + + {computing ? "..." : yr ? `${yr.n1_violations.length} / ${yr.n1_screened}` : "–"} 132 kV outages screened, reported only
@@ -171,21 +228,50 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst vMax: string; worstPct: number | null; }) { - const { s } = planner; + const { s, derived } = planner; + const { yr } = derived; const computing = s.refreshing || s.running; + + const winterImport = yr?.gsp_import_winter_mw ?? null; + const summerImport = yr?.gsp_import_summer_mw ?? null; + const winterLimit = s.boundary?.import_limit_mw.winter ?? null; + const summerLimit = s.boundary?.import_limit_mw.summer ?? null; + const winterHot = winterImport != null && winterLimit ? winterImport / winterLimit > 0.9 : false; + const summerHot = summerImport != null && summerLimit ? summerImport / summerLimit > 0.9 : false; + + // Voltage range with season info + const minVoltSeason = yr?.min_vm_winter !== undefined && yr?.min_vm_summer !== undefined + ? (yr.min_vm_winter <= yr.min_vm_summer ? "W" : "S") + : ""; + const maxVoltSeason = yr?.max_vm_winter !== undefined && yr?.max_vm_summer !== undefined + ? (yr.max_vm_winter >= yr.max_vm_summer ? "W" : "S") + : ""; + return (
- GSP + GSP export {computing ? "..." : gsp != null && limit != null ? `${Math.round(gsp)} / ${Math.round(limit)}` : "–"}
+
+ Winter import + + {computing ? "..." : winterImport != null && winterLimit != null ? `${Math.round(winterImport)} / ${Math.round(winterLimit)}` : "–"} + +
+
+ Summer import + + {computing ? "..." : summerImport != null && summerLimit != null ? `${Math.round(summerImport)} / ${Math.round(summerLimit)}` : "–"} + +
Voltage - {computing ? "..." : `${vMin}–${vMax}`} + {computing ? "..." : minVoltSeason && maxVoltSeason ? `${vMin}(${minVoltSeason})–${vMax}(${maxVoltSeason})` : `${vMin}–${vMax}`}
diff --git a/apps/web/src/lib/derive.ts b/apps/web/src/lib/derive.ts index cbe87ce..1307ba8 100644 --- a/apps/web/src/lib/derive.ts +++ b/apps/web/src/lib/derive.ts @@ -296,6 +296,8 @@ export interface ElementInfo { loadLabel: string; load: string; loadPct: number | null; + winterLoadPct: number | null; + summerLoadPct: number | null; ll: [number, number] | null; } export function elementInfo(sel: ElementSel, ix: ModelIndex, yr: YearResult | null, year: number): ElementInfo | null { @@ -303,14 +305,18 @@ export function elementInfo(sel: ElementSel, ix: ModelIndex, yr: YearResult | nu const l = ix.line.get(sel.id); if (!l) return null; const pct = yr?.line_loading?.[sel.id] ?? null; + const winterPct = yr?.line_loading_winter?.[sel.id] ?? null; + const summerPct = yr?.line_loading_summer?.[sel.id] ?? null; return { name: lineName(ix, sel.id), short: lineShort(ix, sel.id), kindLabel: `Circuit · ${+l.voltage_kv} kV`, rating: `${fmtMw(lineMva(l))} MVA`, - loadLabel: `Loading · winter peak & summer min`, + loadLabel: `Loading in ${year}`, load: pct == null ? "–" : `${Math.round(pct)}%`, loadPct: pct, + winterLoadPct: winterPct, + summerLoadPct: summerPct, ll: [(l.from_lon + l.to_lon) / 2, (l.from_lat + l.to_lat) / 2], }; } @@ -318,14 +324,18 @@ export function elementInfo(sel: ElementSel, ix: ModelIndex, yr: YearResult | nu const t = ix.trafo.get(sel.id); if (!t) return null; const pct = yr?.trafo_loading?.[sel.id] ?? null; + const winterPct = yr?.trafo_loading_winter?.[sel.id] ?? null; + const summerPct = yr?.trafo_loading_summer?.[sel.id] ?? null; return { name: trafoName(ix, sel.id), short: `${trafoSub(t).slice(0, 8)} T${t.trafo_id}`, kindLabel: `Transformer · ${trafoRatio(t)}`, rating: `${fmtMw(t.sn_mva)} MVA`, - loadLabel: `Loading · winter peak & summer min`, + loadLabel: `Loading in ${year}`, load: pct == null ? "–" : `${Math.round(pct)}%`, loadPct: pct, + winterLoadPct: winterPct, + summerLoadPct: summerPct, ll: [t.hv_lon, t.hv_lat], }; } @@ -339,6 +349,8 @@ export function elementInfo(sel: ElementSel, ix: ModelIndex, yr: YearResult | nu loadLabel: "Output at summer min", load: g.technology === "battery" ? "exporting" : "full", loadPct: null, + winterLoadPct: null, + summerLoadPct: null, ll: [g.lon, g.lat], }; } diff --git a/apps/web/src/types.ts b/apps/web/src/types.ts index 1a24ae3..d3738c1 100644 --- a/apps/web/src/types.ts +++ b/apps/web/src/types.ts @@ -185,11 +185,21 @@ export interface PhaseResult { max_vm_pu: number; overloaded_line_ids: number[]; line_loading: Record; + line_loading_winter?: Record; + line_loading_summer?: Record; + trafo_loading_winter?: Record; + trafo_loading_summer?: Record; bus_vm: Record; voltage_violation_bus_ids: number[]; gsp_export_mw: number; gsp_import_mw: number; + gsp_import_winter_mw?: number; + gsp_import_summer_mw?: number; gsp_limit_mw: number | null; + min_vm_winter?: number; + max_vm_winter?: number; + min_vm_summer?: number; + max_vm_summer?: number; n1_screened: number; n1_violations: N1Violation[]; } diff --git a/packages/optimizer/src/gridforge_optimizer/network.py b/packages/optimizer/src/gridforge_optimizer/network.py index f9623a4..575893e 100644 --- a/packages/optimizer/src/gridforge_optimizer/network.py +++ b/packages/optimizer/src/gridforge_optimizer/network.py @@ -440,12 +440,24 @@ def feasibility(net) -> tuple[bool, Reason | None, dict]: reason: Reason | None = None gsp_export = gsp_import = 0.0 export_case = binding_case = None + winter_line = winter_trafo = summer_line = summer_trafo = None + winter_import = summer_import = 0.0 + winter_vm = summer_vm = None for case, load_scale, rating_ratio in _study_cases(net): res = _run_case(net, case, load_scale, rating_ratio) if res is None: return False, Reason(type="non_convergent", case=case, message=f"power flow did not converge at {_CASE_LABEL[case]}"), {} vm, line_pct, trafo_pct, p = res["vm"], res["line_pct"], res["trafo_pct"], res["p_ext_mw"] + # Capture per-case loading, import, and voltage + if case == "winter_peak": + winter_line, winter_trafo = line_pct, trafo_pct + winter_import = p + winter_vm = vm + elif case == "summer_min": + summer_line, summer_trafo = line_pct, trafo_pct + summer_import = p + summer_vm = vm if -p > gsp_export: gsp_export, export_case = -p, case gsp_import = max(gsp_import, p) @@ -472,8 +484,18 @@ def feasibility(net) -> tuple[bool, Reason | None, dict]: "max_trafo_pct": float(env_trafo.max()) if len(env_trafo) else 0.0, "gsp_export_mw": round(gsp_export, 1), "gsp_import_mw": round(gsp_import, 1), + "gsp_import_winter_mw": round(winter_import, 1), + "gsp_import_summer_mw": round(summer_import, 1), "gsp_limit_mw": gsp_export_limit(net), "binding_case": binding_case, + "line_loading_winter": winter_line, + "line_loading_summer": summer_line, + "trafo_loading_winter": winter_trafo, + "trafo_loading_summer": summer_trafo, + "min_vm_winter": float(winter_vm.min()) if winter_vm is not None else 0.0, + "max_vm_winter": float(winter_vm.max()) if winter_vm is not None else 0.0, + "min_vm_summer": float(summer_vm.min()) if summer_vm is not None else 0.0, + "max_vm_summer": float(summer_vm.max()) if summer_vm is not None else 0.0, } return reason is None, reason, metrics @@ -490,10 +512,16 @@ def line_loadings(net) -> dict[int, float]: return {int(i): round(float(v), 1) for i, v in lp.items()} +def _loading_dict(series) -> dict[int, float]: + """Convert a pandas Series of loading_percent to a dict, filtering NaN.""" + if series is None: + return {} + return {int(i): round(float(v), 1) for i, v in series.items() if v == v} + + def trafo_loadings(net) -> dict[int, float]: """Per-transformer loading_percent from the last solve.""" - tp = net.res_trafo["loading_percent"] - return {int(i): round(float(v), 1) for i, v in tp.items() if v == v} + return _loading_dict(net.res_trafo["loading_percent"]) def bus_voltages(net) -> dict[int, float]: diff --git a/packages/optimizer/src/gridforge_optimizer/types.py b/packages/optimizer/src/gridforge_optimizer/types.py index 05777f2..201b971 100644 --- a/packages/optimizer/src/gridforge_optimizer/types.py +++ b/packages/optimizer/src/gridforge_optimizer/types.py @@ -83,12 +83,22 @@ class PhaseResult(BaseModel): min_vm_pu: float max_vm_pu: float overloaded_line_ids: list[int] - line_loading: dict[int, float] = {} # line_id -> loading_percent, for the map heat overlay + line_loading: dict[int, float] = {} # line_id -> loading_percent (envelope), for the map heat overlay + line_loading_winter: dict[int, float] = {} # line_id -> loading at winter_peak + line_loading_summer: dict[int, float] = {} # line_id -> loading at summer_min + trafo_loading_winter: dict[int, float] = {} # trafo_id -> loading at winter_peak + trafo_loading_summer: dict[int, float] = {} # trafo_id -> loading at summer_min bus_vm: dict[int, float] = {} # bus_id -> voltage pu, for the map voltage overlay voltage_violation_bus_ids: list[int] = [] # buses outside the voltage band gsp_export_mw: float = 0.0 # peak power pushed UP through the GSP to transmission (worst case) gsp_import_mw: float = 0.0 # peak power drawn DOWN from transmission (worst case) + gsp_import_winter_mw: float = 0.0 # import at winter_peak + gsp_import_summer_mw: float = 0.0 # import at summer_min gsp_limit_mw: float | None = None # the GSP's export limit to transmission; None = unlimited + min_vm_winter: float = 0.0 # minimum voltage at winter_peak + max_vm_winter: float = 0.0 # maximum voltage at winter_peak + min_vm_summer: float = 0.0 # minimum voltage at summer_min + max_vm_summer: float = 0.0 # maximum voltage at summer_min n1_screened: int = 0 # EHV elements outaged one at a time in the N-1 screen n1_violations: list[dict] = [] # {outage_type, outage_id, outage_name, type, element_id, value, message} diff --git a/packages/optimizer/src/gridforge_optimizer/years.py b/packages/optimizer/src/gridforge_optimizer/years.py index 3bf9ba1..98125c7 100644 --- a/packages/optimizer/src/gridforge_optimizer/years.py +++ b/packages/optimizer/src/gridforge_optimizer/years.py @@ -101,6 +101,10 @@ def evaluate_year( studies = study_windows(net, [o for o in outages if o.year == year], screen=n1_screen if n1 else None) screen = n1_screen(net) if n1 else {"screened": 0, "violations": []} _, _, m = feasibility(net) # the intact envelope the map and readings show + # Helper to convert pandas Series to dict[int, float] + def _loading_dict(s): + return {int(k): round(float(v), 1) for k, v in s.items()} if s is not None else {} + yr = YearResult( year=year, growth=round(growth, 4), @@ -112,12 +116,22 @@ def evaluate_year( max_vm_pu=round(m.get("max_vm", 0.0), 4), overloaded_line_ids=overloaded_line_ids(net), line_loading=line_loadings(net), + line_loading_winter=_loading_dict(m.get("line_loading_winter")), + line_loading_summer=_loading_dict(m.get("line_loading_summer")), trafo_loading=trafo_loadings(net), + trafo_loading_winter=_loading_dict(m.get("trafo_loading_winter")), + trafo_loading_summer=_loading_dict(m.get("trafo_loading_summer")), bus_vm=bus_voltages(net), voltage_violation_bus_ids=voltage_violation_bus_ids(net), gsp_export_mw=m.get("gsp_export_mw", 0.0), gsp_import_mw=m.get("gsp_import_mw", 0.0), + gsp_import_winter_mw=m.get("gsp_import_winter_mw", 0.0), + gsp_import_summer_mw=m.get("gsp_import_summer_mw", 0.0), gsp_limit_mw=m.get("gsp_limit_mw"), + min_vm_winter=round(m.get("min_vm_winter", 0.0), 4), + max_vm_winter=round(m.get("max_vm_winter", 0.0), 4), + min_vm_summer=round(m.get("min_vm_summer", 0.0), 4), + max_vm_summer=round(m.get("max_vm_summer", 0.0), 4), n1_screened=screen["screened"], n1_violations=screen["violations"], outage_studies=studies, From 18640607fcf82a44b8a042f795d9ac506bbc5f38 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 16:30:35 +0000 Subject: [PATCH 04/13] Add season labels to voltage and worst element in all views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Frontend (apps/web): - derive.ts: Enhanced WorstElement interface with winterPct, summerPct, and case fields - worstElement(): Now captures per-case loadings and determines which case won - LeftCards.tsx: Updated all three views (narrow pill, full Readings, CompactReadings): * Voltage range shows season for min and max (e.g. '0.985(S)–1.042(W)') * Worst element shows the winning case (e.g. '92% (W)') or both when available * Treat undefined or 0 as no data (old cached results default to 0.0) - derive.test.ts: Updated test to match new WorstElement interface All three layouts now correctly label which season each metric came from. Cached years from before these fields were added display '–' instead of '0'. Tests: 109 backend passed, 86 frontend passed, typecheck pass Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 71 ++++++++++++++++++++------- apps/web/src/lib/derive.test.ts | 2 +- apps/web/src/lib/derive.ts | 46 +++++++++++++++-- 3 files changed, 95 insertions(+), 24 deletions(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index 569dcb9..f4c1c15 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -33,13 +33,30 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo if (layout.narrow) { const computing = s.refreshing || s.running; - const winterImport = yr?.gsp_import_winter_mw ?? null; - const summerImport = yr?.gsp_import_summer_mw ?? null; + const winterImport = yr?.gsp_import_winter_mw ? yr.gsp_import_winter_mw : null; + const summerImport = yr?.gsp_import_summer_mw ? yr.gsp_import_summer_mw : null; const winterLimit = s.boundary?.import_limit_mw.winter ?? null; const summerLimit = s.boundary?.import_limit_mw.summer ?? null; const winterHot = winterImport != null && winterLimit ? winterImport / winterLimit > 0.9 : false; const summerHot = summerImport != null && summerLimit ? summerImport / summerLimit > 0.9 : false; + // Voltage with season labels (treat 0 as no data from old cache) + const hasWinterVoltage = !!(yr?.min_vm_winter && yr?.max_vm_winter); + const hasSummerVoltage = !!(yr?.min_vm_summer && yr?.max_vm_summer); + const minVoltSeason = hasWinterVoltage && hasSummerVoltage && yr + ? (yr.min_vm_winter! <= yr.min_vm_summer! ? "W" : "S") + : ""; + const maxVoltSeason = hasWinterVoltage && hasSummerVoltage && yr + ? (yr.max_vm_winter! >= yr.max_vm_summer! ? "W" : "S") + : ""; + const vDisplay = computing ? "..." : minVoltSeason && maxVoltSeason ? `${vMin}(${minVoltSeason})–${vMax}(${maxVoltSeason})` : `${vMin}–${vMax}`; + + // Worst element with season or both percentages + const worstDisplay = computing ? "..." : !worst ? "–" : + worst.case ? `${worstPct}% (${worst.case === "winter peak" ? "W" : "S"})` : + worst.winterPct !== null && worst.summerPct !== null ? `W${Math.round(worst.winterPct)}% S${Math.round(worst.summerPct)}%` : + `${worstPct}%`; + return (
@@ -54,10 +71,10 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo S.import {computing ? "..." : summerImport != null ? Math.round(summerImport) : "–"}/{summerLimit != null ? Math.round(summerLimit) : "–"} - V {computing ? "..." : `${vMin}–${vMax}`} + V {vDisplay} 100 ? C.red : worstPct && worstPct > 90 ? C.amber : C.ink2 }}> - Worst {computing ? "..." : worstPct != null ? `${worstPct}%` : "–"} + Worst {worstDisplay} {computing && updating…} {showStale && ( @@ -125,19 +142,23 @@ function Readings({ planner, gsp, limit, gspHot }: { planner: LeftCardsPlanner; const computing = s.refreshing || s.running; // Winter and summer imports with their distinct limits - const winterImport = yr?.gsp_import_winter_mw ?? null; - const summerImport = yr?.gsp_import_summer_mw ?? null; + // Treat undefined or 0 as no data (old cached results default to 0.0, but 0 import is unrealistic) + const winterImport = yr?.gsp_import_winter_mw ? yr.gsp_import_winter_mw : null; + const summerImport = yr?.gsp_import_summer_mw ? yr.gsp_import_summer_mw : null; const winterLimit = s.boundary?.import_limit_mw.winter ?? null; const summerLimit = s.boundary?.import_limit_mw.summer ?? null; const winterHot = winterImport != null && winterLimit ? winterImport / winterLimit > 0.9 : false; const summerHot = summerImport != null && summerLimit ? summerImport / summerLimit > 0.9 : false; // Voltage range with season attribution - const minVoltSeason = yr?.min_vm_winter !== undefined && yr?.min_vm_summer !== undefined - ? (yr.min_vm_winter <= yr.min_vm_summer ? "winter peak" : "summer min") + // Treat undefined or 0 as no data (old cached results default to 0.0, but 0 voltage is impossible) + const hasWinterVoltage = !!(yr?.min_vm_winter && yr?.max_vm_winter); + const hasSummerVoltage = !!(yr?.min_vm_summer && yr?.max_vm_summer); + const minVoltSeason = hasWinterVoltage && hasSummerVoltage && yr + ? (yr.min_vm_winter! <= yr.min_vm_summer! ? "winter peak" : "summer min") : null; - const maxVoltSeason = yr?.max_vm_winter !== undefined && yr?.max_vm_summer !== undefined - ? (yr.max_vm_winter >= yr.max_vm_summer ? "winter peak" : "summer min") + const maxVoltSeason = hasWinterVoltage && hasSummerVoltage && yr + ? (yr.max_vm_winter! >= yr.max_vm_summer! ? "winter peak" : "summer min") : null; return ( @@ -185,7 +206,13 @@ function Readings({ planner, gsp, limit, gspHot }: { planner: LeftCardsPlanner; 100 ? C.red : worst.pct > 90 ? C.amber : C.ink) : C.ink }}> {computing ? "..." : worst ? `${Math.round(worst.pct)}%` : "–"} - {worst?.name ?? "not solved yet"} + + {computing ? "computing" : !worst ? "not solved yet" : + worst.case ? `${worst.name} · ${worst.case}` : + worst.winterPct !== null && worst.summerPct !== null ? `${worst.name} · winter ${Math.round(worst.winterPct)}% · summer ${Math.round(worst.summerPct)}%` : + worst.name + } +
Voltage band @@ -232,19 +259,21 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst const { yr } = derived; const computing = s.refreshing || s.running; - const winterImport = yr?.gsp_import_winter_mw ?? null; - const summerImport = yr?.gsp_import_summer_mw ?? null; + const winterImport = yr?.gsp_import_winter_mw ? yr.gsp_import_winter_mw : null; + const summerImport = yr?.gsp_import_summer_mw ? yr.gsp_import_summer_mw : null; const winterLimit = s.boundary?.import_limit_mw.winter ?? null; const summerLimit = s.boundary?.import_limit_mw.summer ?? null; const winterHot = winterImport != null && winterLimit ? winterImport / winterLimit > 0.9 : false; const summerHot = summerImport != null && summerLimit ? summerImport / summerLimit > 0.9 : false; - // Voltage range with season info - const minVoltSeason = yr?.min_vm_winter !== undefined && yr?.min_vm_summer !== undefined - ? (yr.min_vm_winter <= yr.min_vm_summer ? "W" : "S") + // Voltage range with season info (treat 0 as no data from old cache) + const hasWinterVoltage = !!(yr?.min_vm_winter && yr?.max_vm_winter); + const hasSummerVoltage = !!(yr?.min_vm_summer && yr?.max_vm_summer); + const minVoltSeason = hasWinterVoltage && hasSummerVoltage && yr + ? (yr.min_vm_winter! <= yr.min_vm_summer! ? "W" : "S") : ""; - const maxVoltSeason = yr?.max_vm_winter !== undefined && yr?.max_vm_summer !== undefined - ? (yr.max_vm_winter >= yr.max_vm_summer ? "W" : "S") + const maxVoltSeason = hasWinterVoltage && hasSummerVoltage && yr + ? (yr.max_vm_winter! >= yr.max_vm_summer! ? "W" : "S") : ""; return ( @@ -277,7 +306,11 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst
Worst 100 ? C.red : worstPct && worstPct > 90 ? C.amber : C.ink }}> - {computing ? "..." : worstPct != null ? `${worstPct}%` : "–"} + {computing ? "..." : !worst ? "–" : + worst.case ? `${worstPct}%(${worst.case === "winter peak" ? "W" : "S"})` : + worst.winterPct !== null && worst.summerPct !== null ? `W${Math.round(worst.winterPct)}% S${Math.round(worst.summerPct)}%` : + worstPct != null ? `${worstPct}%` : "–" + }
diff --git a/apps/web/src/lib/derive.test.ts b/apps/web/src/lib/derive.test.ts index 146a54f..2ebf4bd 100644 --- a/apps/web/src/lib/derive.test.ts +++ b/apps/web/src/lib/derive.test.ts @@ -134,7 +134,7 @@ describe("naming and readings", () => { it("names lines by the places they join and finds the worst element", () => { expect(lineName(ix, 10)).toBe("Boston to Bicker Fen 132 kV"); const w = worstElement(year(2030, { line_loading: { "10": 61, "11": 88 }, trafo_loading: { "5": 92 } }), ix); - expect(w).toEqual({ pct: 92, name: "Bicker Fen 132/33 kV transformer", sel: { kind: "trafo", id: 5 } }); + expect(w).toEqual({ pct: 92, name: "Bicker Fen 132/33 kV transformer", sel: { kind: "trafo", id: 5 }, winterPct: null, summerPct: null, case: null }); }); it("fills the GSP gauge, the last ticks amber", () => { const t = gspTicks(500, 527); diff --git a/apps/web/src/lib/derive.ts b/apps/web/src/lib/derive.ts index 1307ba8..98ede4b 100644 --- a/apps/web/src/lib/derive.ts +++ b/apps/web/src/lib/derive.ts @@ -269,15 +269,53 @@ export interface WorstElement { pct: number; name: string; sel: ElementSel; + winterPct: number | null; + summerPct: number | null; + case: "winter peak" | "summer min" | null; } /** The most loaded line or transformer in a year (worst case across the two study cases). */ export function worstElement(yr: YearResult | null, ix: ModelIndex | null): WorstElement | null { if (!yr || !ix) return null; let best: WorstElement | null = null; - for (const [id, v] of Object.entries(yr.line_loading ?? {})) - if (!best || v > best.pct) best = { pct: v, name: lineName(ix, +id), sel: { kind: "line", id: +id } }; - for (const [id, v] of Object.entries(yr.trafo_loading ?? {})) - if (!best || v > best.pct) best = { pct: v, name: trafoName(ix, +id), sel: { kind: "trafo", id: +id } }; + + for (const [id, v] of Object.entries(yr.line_loading ?? {})) { + if (!best || v > best.pct) { + const winterPct = yr.line_loading_winter?.[+id] ?? null; + const summerPct = yr.line_loading_summer?.[+id] ?? null; + const winningCase = + winterPct !== null && summerPct !== null + ? (winterPct >= summerPct ? "winter peak" : "summer min") + : null; + best = { + pct: v, + name: lineName(ix, +id), + sel: { kind: "line", id: +id }, + winterPct, + summerPct, + case: winningCase, + }; + } + } + + for (const [id, v] of Object.entries(yr.trafo_loading ?? {})) { + if (!best || v > best.pct) { + const winterPct = yr.trafo_loading_winter?.[+id] ?? null; + const summerPct = yr.trafo_loading_summer?.[+id] ?? null; + const winningCase = + winterPct !== null && summerPct !== null + ? (winterPct >= summerPct ? "winter peak" : "summer min") + : null; + best = { + pct: v, + name: trafoName(ix, +id), + sel: { kind: "trafo", id: +id }, + winterPct, + summerPct, + case: winningCase, + }; + } + } + return best; } From 0bb8674eed86309111dfeb21644478168cd7d8f5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 16:35:55 +0000 Subject: [PATCH 05/13] Fix voltage and worst element to show each case's own values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Frontend (apps/web/src/components/LeftCards.tsx): - Summer import: Always show import (0 when exporting), never flip row to export * When summer case exports, display '0 / 221.6 MW', not negative value * Solved 0 MW import is valid and stays visible * Only undefined fields are treated as missing - Voltage: Each letter (W/S) now sits on that case's own voltage * Full Readings: Show winter range + summer range separately when both available * CompactReadings: Display both ranges in compact format * Narrow pill: Same compact format with both winter and summer ranges * No longer show envelope voltage with a guessed season letter - Worst element: Percent now matches the season it names * Show both seasons' own percentages when available (e.g. 'W92% S87%') * Or show single season's actual percentage with its label (e.g. '92%(W)') * Never show envelope percent next to a guessed season - Winter import unchanged: Still against 2×160.1 MW limit - Summer import: Against 2×110.8 MW limit (showing 0 when case exports) Tests: 86 passed, typecheck pass Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 100 +++++++++++++------------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index f4c1c15..cc133c6 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -33,28 +33,25 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo if (layout.narrow) { const computing = s.refreshing || s.running; - const winterImport = yr?.gsp_import_winter_mw ? yr.gsp_import_winter_mw : null; - const summerImport = yr?.gsp_import_summer_mw ? yr.gsp_import_summer_mw : null; + const winterImport = yr?.gsp_import_winter_mw !== undefined ? yr.gsp_import_winter_mw : null; + const summerImport = yr?.gsp_import_summer_mw !== undefined ? Math.max(0, yr.gsp_import_summer_mw) : null; const winterLimit = s.boundary?.import_limit_mw.winter ?? null; const summerLimit = s.boundary?.import_limit_mw.summer ?? null; - const winterHot = winterImport != null && winterLimit ? winterImport / winterLimit > 0.9 : false; - const summerHot = summerImport != null && summerLimit ? summerImport / summerLimit > 0.9 : false; + const winterHot = winterImport != null && winterLimit && winterImport > 0 ? winterImport / winterLimit > 0.9 : false; + const summerHot = summerImport != null && summerLimit && summerImport > 0 ? summerImport / summerLimit > 0.9 : false; - // Voltage with season labels (treat 0 as no data from old cache) + // Voltage with each case's own voltage (treat 0 as no data) const hasWinterVoltage = !!(yr?.min_vm_winter && yr?.max_vm_winter); const hasSummerVoltage = !!(yr?.min_vm_summer && yr?.max_vm_summer); - const minVoltSeason = hasWinterVoltage && hasSummerVoltage && yr - ? (yr.min_vm_winter! <= yr.min_vm_summer! ? "W" : "S") - : ""; - const maxVoltSeason = hasWinterVoltage && hasSummerVoltage && yr - ? (yr.max_vm_winter! >= yr.max_vm_summer! ? "W" : "S") - : ""; - const vDisplay = computing ? "..." : minVoltSeason && maxVoltSeason ? `${vMin}(${minVoltSeason})–${vMax}(${maxVoltSeason})` : `${vMin}–${vMax}`; + const vDisplay = computing ? "..." : hasWinterVoltage && hasSummerVoltage && yr + ? `${yr.min_vm_winter!.toFixed(3)}(W)–${yr.max_vm_winter!.toFixed(3)}(W) ${yr.min_vm_summer!.toFixed(3)}(S)–${yr.max_vm_summer!.toFixed(3)}(S)` + : `${vMin}–${vMax}`; // Worst element with season or both percentages const worstDisplay = computing ? "..." : !worst ? "–" : - worst.case ? `${worstPct}% (${worst.case === "winter peak" ? "W" : "S"})` : worst.winterPct !== null && worst.summerPct !== null ? `W${Math.round(worst.winterPct)}% S${Math.round(worst.summerPct)}%` : + worst.case && worst.winterPct !== null && worst.case === "winter peak" ? `${Math.round(worst.winterPct)}% (W)` : + worst.case && worst.summerPct !== null && worst.case === "summer min" ? `${Math.round(worst.summerPct)}% (S)` : `${worstPct}%`; return ( @@ -142,24 +139,25 @@ function Readings({ planner, gsp, limit, gspHot }: { planner: LeftCardsPlanner; const computing = s.refreshing || s.running; // Winter and summer imports with their distinct limits - // Treat undefined or 0 as no data (old cached results default to 0.0, but 0 import is unrealistic) - const winterImport = yr?.gsp_import_winter_mw ? yr.gsp_import_winter_mw : null; - const summerImport = yr?.gsp_import_summer_mw ? yr.gsp_import_summer_mw : null; + // Treat undefined as no data; 0 is valid (summer case exporting = 0 import) + const winterImport = yr?.gsp_import_winter_mw !== undefined ? yr.gsp_import_winter_mw : null; + const summerImport = yr?.gsp_import_summer_mw !== undefined ? Math.max(0, yr.gsp_import_summer_mw) : null; const winterLimit = s.boundary?.import_limit_mw.winter ?? null; const summerLimit = s.boundary?.import_limit_mw.summer ?? null; - const winterHot = winterImport != null && winterLimit ? winterImport / winterLimit > 0.9 : false; - const summerHot = summerImport != null && summerLimit ? summerImport / summerLimit > 0.9 : false; + const winterHot = winterImport != null && winterLimit && winterImport > 0 ? winterImport / winterLimit > 0.9 : false; + const summerHot = summerImport != null && summerLimit && summerImport > 0 ? summerImport / summerLimit > 0.9 : false; - // Voltage range with season attribution - // Treat undefined or 0 as no data (old cached results default to 0.0, but 0 voltage is impossible) + // Voltage range with season attribution - show each case's own voltage + // Treat 0 as no data (0 voltage is impossible) const hasWinterVoltage = !!(yr?.min_vm_winter && yr?.max_vm_winter); const hasSummerVoltage = !!(yr?.min_vm_summer && yr?.max_vm_summer); - const minVoltSeason = hasWinterVoltage && hasSummerVoltage && yr - ? (yr.min_vm_winter! <= yr.min_vm_summer! ? "winter peak" : "summer min") - : null; - const maxVoltSeason = hasWinterVoltage && hasSummerVoltage && yr - ? (yr.max_vm_winter! >= yr.max_vm_summer! ? "winter peak" : "summer min") - : null; + // Determine the overall envelope extremes and which case each came from + const overallMin = yr?.min_vm_pu ?? 0; + const overallMax = yr?.max_vm_pu ?? 0; + const minFromWinter = hasWinterVoltage && yr && yr.min_vm_winter! <= (yr.min_vm_summer ?? Infinity); + const minFromSummer = hasSummerVoltage && yr && yr.min_vm_summer! < (yr.min_vm_winter ?? Infinity); + const maxFromWinter = hasWinterVoltage && yr && yr.max_vm_winter! >= (yr.max_vm_summer ?? -Infinity); + const maxFromSummer = hasSummerVoltage && yr && yr.max_vm_summer! > (yr.max_vm_winter ?? -Infinity); return (
@@ -189,7 +187,7 @@ function Readings({ planner, gsp, limit, gspHot }: { planner: LeftCardsPlanner;
Summer import - {computing ? "..." : summerImport != null ? fmtMw(summerImport) : "–"} / {summerLimit != null ? fmtMw(summerLimit) : "–"} MW + {computing ? "..." : summerImport != null ? `${fmtMw(summerImport)} / ${summerLimit != null ? fmtMw(summerLimit) : "–"}` : "–"} MW
@@ -216,14 +214,19 @@ function Readings({ planner, gsp, limit, gspHot }: { planner: LeftCardsPlanner;
Voltage band - {computing ? "..." : yr ? yr.min_vm_pu.toFixed(3) : "–"} - - {computing ? "computing" : minVoltSeason && maxVoltSeason ? ( - <>({minVoltSeason}) to {yr ? yr.max_vm_pu.toFixed(3) : "–"} pu ({maxVoltSeason}) - ) : ( - <>to {yr ? yr.max_vm_pu.toFixed(3) : "–"} pu · {yr?.voltage_violation_bus_ids.length ? `${yr.voltage_violation_bus_ids.length} outside band` : "statutory bands"} - )} - + {hasWinterVoltage && hasSummerVoltage && yr ? ( + <> + {yr.min_vm_winter!.toFixed(3)} (W) + to {yr.max_vm_winter!.toFixed(3)} pu (W) · {yr.min_vm_summer!.toFixed(3)} (S) to {yr.max_vm_summer!.toFixed(3)} pu (S) + + ) : ( + <> + {computing ? "..." : yr ? yr.min_vm_pu.toFixed(3) : "–"} + + {computing ? "computing" : <>to {yr ? yr.max_vm_pu.toFixed(3) : "–"} pu · {yr?.voltage_violation_bus_ids.length ? `${yr.voltage_violation_bus_ids.length} outside band` : "statutory bands"}} + + + )}
Peak demand @@ -259,22 +262,20 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst const { yr } = derived; const computing = s.refreshing || s.running; - const winterImport = yr?.gsp_import_winter_mw ? yr.gsp_import_winter_mw : null; - const summerImport = yr?.gsp_import_summer_mw ? yr.gsp_import_summer_mw : null; + const winterImport = yr?.gsp_import_winter_mw !== undefined ? yr.gsp_import_winter_mw : null; + const summerImport = yr?.gsp_import_summer_mw !== undefined ? Math.max(0, yr.gsp_import_summer_mw) : null; const winterLimit = s.boundary?.import_limit_mw.winter ?? null; const summerLimit = s.boundary?.import_limit_mw.summer ?? null; - const winterHot = winterImport != null && winterLimit ? winterImport / winterLimit > 0.9 : false; - const summerHot = summerImport != null && summerLimit ? summerImport / summerLimit > 0.9 : false; + const winterHot = winterImport != null && winterLimit && winterImport > 0 ? winterImport / winterLimit > 0.9 : false; + const summerHot = summerImport != null && summerLimit && summerImport > 0 ? summerImport / summerLimit > 0.9 : false; - // Voltage range with season info (treat 0 as no data from old cache) + // Voltage range with each case's own voltage (treat 0 as no data) const hasWinterVoltage = !!(yr?.min_vm_winter && yr?.max_vm_winter); const hasSummerVoltage = !!(yr?.min_vm_summer && yr?.max_vm_summer); - const minVoltSeason = hasWinterVoltage && hasSummerVoltage && yr - ? (yr.min_vm_winter! <= yr.min_vm_summer! ? "W" : "S") - : ""; - const maxVoltSeason = hasWinterVoltage && hasSummerVoltage && yr - ? (yr.max_vm_winter! >= yr.max_vm_summer! ? "W" : "S") - : ""; + // Show winter and summer voltages separately when both available + const vDisplay = computing ? "..." : hasWinterVoltage && hasSummerVoltage && yr + ? `${yr.min_vm_winter!.toFixed(3)}(W)–${yr.max_vm_winter!.toFixed(3)}(W) ${yr.min_vm_summer!.toFixed(3)}(S)–${yr.max_vm_summer!.toFixed(3)}(S)` + : `${vMin}–${vMax}`; return (
@@ -299,16 +300,17 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst
Voltage - - {computing ? "..." : minVoltSeason && maxVoltSeason ? `${vMin}(${minVoltSeason})–${vMax}(${maxVoltSeason})` : `${vMin}–${vMax}`} + + {vDisplay}
Worst 100 ? C.red : worstPct && worstPct > 90 ? C.amber : C.ink }}> {computing ? "..." : !worst ? "–" : - worst.case ? `${worstPct}%(${worst.case === "winter peak" ? "W" : "S"})` : worst.winterPct !== null && worst.summerPct !== null ? `W${Math.round(worst.winterPct)}% S${Math.round(worst.summerPct)}%` : + worst.case && worst.winterPct !== null && worst.case === "winter peak" ? `${Math.round(worst.winterPct)}%(W)` : + worst.case && worst.summerPct !== null && worst.case === "summer min" ? `${Math.round(worst.summerPct)}%(S)` : worstPct != null ? `${worstPct}%` : "–" } From bf499e8cf5f6cd28f308cd0c145589866c2836ad Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 16:40:09 +0000 Subject: [PATCH 06/13] Add export season label and show both percentages for worst element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend (packages/optimizer): - types.py: Add gsp_export_case field to PhaseResult (records which case produced export) - network.py: Populate gsp_export_case in feasibility metrics - years.py: Include gsp_export_case in YearResult Frontend (apps/web): - types.ts: Add optional gsp_export_case field to PhaseResult - LeftCards.tsx Readings: * Export row now shows season: 'GSP export · winter' or 'GSP export · summer' * Removed 'Worst case' text (replaced with actual season from result) * Worst element displays both percentages when available: 'W92% S87%' * Never shows envelope percentage with a guessed season * Matches narrow pill and CompactReadings behavior All three views now show both winter and summer percentages for worst element. Export row names the season that produced the export figure. Tests: 109 backend passed, 86 frontend passed, typecheck pass Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 35 ++++++++++++------- apps/web/src/types.ts | 1 + .../src/gridforge_optimizer/network.py | 1 + .../src/gridforge_optimizer/types.py | 1 + .../src/gridforge_optimizer/years.py | 1 + 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index cc133c6..036028a 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -163,15 +163,17 @@ function Readings({ planner, gsp, limit, gspHot }: { planner: LeftCardsPlanner;
@@ -201,16 +203,23 @@ function Readings({ planner, gsp, limit, gspHot }: { planner: LeftCardsPlanner; title={worst ? `Show the ${worst.name} on the map` : undefined} > Worst element - 100 ? C.red : worst.pct > 90 ? C.amber : C.ink) : C.ink }}> - {computing ? "..." : worst ? `${Math.round(worst.pct)}%` : "–"} - - - {computing ? "computing" : !worst ? "not solved yet" : - worst.case ? `${worst.name} · ${worst.case}` : - worst.winterPct !== null && worst.summerPct !== null ? `${worst.name} · winter ${Math.round(worst.winterPct)}% · summer ${Math.round(worst.summerPct)}%` : - worst.name - } - + {worst && worst.winterPct !== null && worst.summerPct !== null ? ( + <> + 100 ? C.red : Math.max(worst.winterPct, worst.summerPct) > 90 ? C.amber : C.ink }}> + {computing ? "..." : `W${Math.round(worst.winterPct)}% S${Math.round(worst.summerPct)}%`} + + {worst.name} + + ) : ( + <> + 100 ? C.red : worst.pct > 90 ? C.amber : C.ink) : C.ink }}> + {computing ? "..." : worst ? `${Math.round(worst.pct)}%` : "–"} + + + {computing ? "computing" : !worst ? "not solved yet" : worst.name} + + + )}
Voltage band diff --git a/apps/web/src/types.ts b/apps/web/src/types.ts index d3738c1..3dfad9e 100644 --- a/apps/web/src/types.ts +++ b/apps/web/src/types.ts @@ -192,6 +192,7 @@ export interface PhaseResult { bus_vm: Record; voltage_violation_bus_ids: number[]; gsp_export_mw: number; + gsp_export_case?: string | null; gsp_import_mw: number; gsp_import_winter_mw?: number; gsp_import_summer_mw?: number; diff --git a/packages/optimizer/src/gridforge_optimizer/network.py b/packages/optimizer/src/gridforge_optimizer/network.py index 575893e..85e3074 100644 --- a/packages/optimizer/src/gridforge_optimizer/network.py +++ b/packages/optimizer/src/gridforge_optimizer/network.py @@ -483,6 +483,7 @@ def feasibility(net) -> tuple[bool, Reason | None, dict]: "max_line_pct": float(env_line.max()) if len(env_line) else 0.0, "max_trafo_pct": float(env_trafo.max()) if len(env_trafo) else 0.0, "gsp_export_mw": round(gsp_export, 1), + "gsp_export_case": export_case, "gsp_import_mw": round(gsp_import, 1), "gsp_import_winter_mw": round(winter_import, 1), "gsp_import_summer_mw": round(summer_import, 1), diff --git a/packages/optimizer/src/gridforge_optimizer/types.py b/packages/optimizer/src/gridforge_optimizer/types.py index 201b971..a769d20 100644 --- a/packages/optimizer/src/gridforge_optimizer/types.py +++ b/packages/optimizer/src/gridforge_optimizer/types.py @@ -91,6 +91,7 @@ class PhaseResult(BaseModel): bus_vm: dict[int, float] = {} # bus_id -> voltage pu, for the map voltage overlay voltage_violation_bus_ids: list[int] = [] # buses outside the voltage band gsp_export_mw: float = 0.0 # peak power pushed UP through the GSP to transmission (worst case) + gsp_export_case: str | None = None # which case produced the export: "winter_peak" or "summer_min" gsp_import_mw: float = 0.0 # peak power drawn DOWN from transmission (worst case) gsp_import_winter_mw: float = 0.0 # import at winter_peak gsp_import_summer_mw: float = 0.0 # import at summer_min diff --git a/packages/optimizer/src/gridforge_optimizer/years.py b/packages/optimizer/src/gridforge_optimizer/years.py index 98125c7..240cd89 100644 --- a/packages/optimizer/src/gridforge_optimizer/years.py +++ b/packages/optimizer/src/gridforge_optimizer/years.py @@ -124,6 +124,7 @@ def _loading_dict(s): bus_vm=bus_voltages(net), voltage_violation_bus_ids=voltage_violation_bus_ids(net), gsp_export_mw=m.get("gsp_export_mw", 0.0), + gsp_export_case=m.get("gsp_export_case"), gsp_import_mw=m.get("gsp_import_mw", 0.0), gsp_import_winter_mw=m.get("gsp_import_winter_mw", 0.0), gsp_import_summer_mw=m.get("gsp_import_summer_mw", 0.0), From 40df0904255f167867d626d1f66870425a7dd177 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 16:42:10 +0000 Subject: [PATCH 07/13] Add export season label to narrow pill and compact readings Frontend (apps/web/src/components/LeftCards.tsx): - Narrow pill: Export now shows '(W)' or '(S)' when gsp_export_case available * Example: 'Export (W) 224/527' for winter export - CompactReadings: GSP export label shows season * Example: 'GSP export (W)' or 'GSP export (S)' - Uses recorded gsp_export_case field from result * Winter only when case is 'winter_peak' * Summer only when case is 'summer_min' * No season label when field is missing (old cached results) All three views (full Readings, CompactReadings, narrow pill) now consistently show which season produced the export figure. Tests: 86 passed, typecheck pass Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index 036028a..766df74 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -59,7 +59,7 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo {resultProfile.label} result - Export {computing ? "..." : gsp != null ? Math.round(gsp) : "–"}/{limit != null ? Math.round(limit) : "–"} + Export{yr?.gsp_export_case ? ` (${yr.gsp_export_case === "winter_peak" ? "W" : "S"})` : ""} {computing ? "..." : gsp != null ? Math.round(gsp) : "–"}/{limit != null ? Math.round(limit) : "–"} W.import {computing ? "..." : winterImport != null ? Math.round(winterImport) : "–"}/{winterLimit != null ? Math.round(winterLimit) : "–"} @@ -290,7 +290,9 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst
- GSP export + + GSP export{yr?.gsp_export_case ? ` (${yr.gsp_export_case === "winter_peak" ? "W" : "S"})` : ""} + {computing ? "..." : gsp != null && limit != null ? `${Math.round(gsp)} / ${Math.round(limit)}` : "–"} From 03ee7176d22b9844012870dbd4beb20def15e818 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 17:13:46 +0000 Subject: [PATCH 08/13] Fix worst element to show actual worst winter and summer separately MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Frontend (apps/web): - derive.ts: worstElement() now finds worst winter and worst summer separately * Previously: Found element with highest envelope, returned that element's winter & summer * Now: Finds actual worst winter element and actual worst summer element * Winter percent is the highest winter loading across all elements * Summer percent is the highest summer loading across all elements * Can be different elements (e.g., W53% on Sleaford, S93% on different element) * Returns winterName and summerName to identify each element - LeftCards.tsx Readings: Display both element names when they differ * Same element: Shows just the element name * Different: 'winter ElementA · summer ElementB' - Import denominators: Show full precision (320.2 and 221.6, not 320 and 222) * Narrow pill and CompactReadings now use fmtMw() for limits * Shows 2×160.1 MW (320.2) for winter, 2×110.8 MW (221.6) for summer Fixes issue where worst loading showed W1% S93% while Sleaford card showed W53%. Now worst winter shows ≥53%, worst summer shows ≥93%, each from the actual worst element. Tests: 86 passed, typecheck pass Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 15 ++-- apps/web/src/lib/derive.test.ts | 2 +- apps/web/src/lib/derive.ts | 105 +++++++++++++++++--------- 3 files changed, 81 insertions(+), 41 deletions(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index 766df74..144475c 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -62,10 +62,10 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo Export{yr?.gsp_export_case ? ` (${yr.gsp_export_case === "winter_peak" ? "W" : "S"})` : ""} {computing ? "..." : gsp != null ? Math.round(gsp) : "–"}/{limit != null ? Math.round(limit) : "–"} - W.import {computing ? "..." : winterImport != null ? Math.round(winterImport) : "–"}/{winterLimit != null ? Math.round(winterLimit) : "–"} + W.import {computing ? "..." : winterImport != null ? Math.round(winterImport) : "–"}/{winterLimit != null ? fmtMw(winterLimit) : "–"} - S.import {computing ? "..." : summerImport != null ? Math.round(summerImport) : "–"}/{summerLimit != null ? Math.round(summerLimit) : "–"} + S.import {computing ? "..." : summerImport != null ? Math.round(summerImport) : "–"}/{summerLimit != null ? fmtMw(summerLimit) : "–"} V {vDisplay} @@ -208,7 +208,12 @@ function Readings({ planner, gsp, limit, gspHot }: { planner: LeftCardsPlanner; 100 ? C.red : Math.max(worst.winterPct, worst.summerPct) > 90 ? C.amber : C.ink }}> {computing ? "..." : `W${Math.round(worst.winterPct)}% S${Math.round(worst.summerPct)}%`} - {worst.name} + + {worst.winterName === worst.summerName + ? worst.winterName + : `winter ${worst.winterName} · summer ${worst.summerName}` + } + ) : ( <> @@ -300,13 +305,13 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst
Winter import - {computing ? "..." : winterImport != null && winterLimit != null ? `${Math.round(winterImport)} / ${Math.round(winterLimit)}` : "–"} + {computing ? "..." : winterImport != null && winterLimit != null ? `${Math.round(winterImport)} / ${fmtMw(winterLimit)}` : "–"}
Summer import - {computing ? "..." : summerImport != null && summerLimit != null ? `${Math.round(summerImport)} / ${Math.round(summerLimit)}` : "–"} + {computing ? "..." : summerImport != null && summerLimit != null ? `${Math.round(summerImport)} / ${fmtMw(summerLimit)}` : "–"}
diff --git a/apps/web/src/lib/derive.test.ts b/apps/web/src/lib/derive.test.ts index 2ebf4bd..2f586ef 100644 --- a/apps/web/src/lib/derive.test.ts +++ b/apps/web/src/lib/derive.test.ts @@ -134,7 +134,7 @@ describe("naming and readings", () => { it("names lines by the places they join and finds the worst element", () => { expect(lineName(ix, 10)).toBe("Boston to Bicker Fen 132 kV"); const w = worstElement(year(2030, { line_loading: { "10": 61, "11": 88 }, trafo_loading: { "5": 92 } }), ix); - expect(w).toEqual({ pct: 92, name: "Bicker Fen 132/33 kV transformer", sel: { kind: "trafo", id: 5 }, winterPct: null, summerPct: null, case: null }); + expect(w).toEqual({ pct: 92, name: "Bicker Fen 132/33 kV transformer", sel: { kind: "trafo", id: 5 }, winterPct: null, winterName: null, summerPct: null, summerName: null, case: null }); }); it("fills the GSP gauge, the last ticks amber", () => { const t = gspTicks(500, 527); diff --git a/apps/web/src/lib/derive.ts b/apps/web/src/lib/derive.ts index 98ede4b..596b439 100644 --- a/apps/web/src/lib/derive.ts +++ b/apps/web/src/lib/derive.ts @@ -270,53 +270,88 @@ export interface WorstElement { name: string; sel: ElementSel; winterPct: number | null; + winterName: string | null; summerPct: number | null; + summerName: string | null; case: "winter peak" | "summer min" | null; } -/** The most loaded line or transformer in a year (worst case across the two study cases). */ +/** The most loaded line or transformer in a year (finds worst winter and worst summer separately). */ export function worstElement(yr: YearResult | null, ix: ModelIndex | null): WorstElement | null { if (!yr || !ix) return null; - let best: WorstElement | null = null; - for (const [id, v] of Object.entries(yr.line_loading ?? {})) { - if (!best || v > best.pct) { - const winterPct = yr.line_loading_winter?.[+id] ?? null; - const summerPct = yr.line_loading_summer?.[+id] ?? null; - const winningCase = - winterPct !== null && summerPct !== null - ? (winterPct >= summerPct ? "winter peak" : "summer min") - : null; - best = { - pct: v, - name: lineName(ix, +id), - sel: { kind: "line", id: +id }, - winterPct, - summerPct, - case: winningCase, - }; + // Find worst winter loading + let worstWinterPct: number | null = null; + let worstWinterName: string | null = null; + let worstWinterSel: ElementSel | null = null; + + for (const [id, v] of Object.entries(yr.line_loading_winter ?? {})) { + if (worstWinterPct === null || v > worstWinterPct) { + worstWinterPct = v; + worstWinterName = lineName(ix, +id); + worstWinterSel = { kind: "line", id: +id }; + } + } + for (const [id, v] of Object.entries(yr.trafo_loading_winter ?? {})) { + if (worstWinterPct === null || v > worstWinterPct) { + worstWinterPct = v; + worstWinterName = trafoName(ix, +id); + worstWinterSel = { kind: "trafo", id: +id }; } } - for (const [id, v] of Object.entries(yr.trafo_loading ?? {})) { - if (!best || v > best.pct) { - const winterPct = yr.trafo_loading_winter?.[+id] ?? null; - const summerPct = yr.trafo_loading_summer?.[+id] ?? null; - const winningCase = - winterPct !== null && summerPct !== null - ? (winterPct >= summerPct ? "winter peak" : "summer min") - : null; - best = { - pct: v, - name: trafoName(ix, +id), - sel: { kind: "trafo", id: +id }, - winterPct, - summerPct, - case: winningCase, - }; + // Find worst summer loading + let worstSummerPct: number | null = null; + let worstSummerName: string | null = null; + let worstSummerSel: ElementSel | null = null; + + for (const [id, v] of Object.entries(yr.line_loading_summer ?? {})) { + if (worstSummerPct === null || v > worstSummerPct) { + worstSummerPct = v; + worstSummerName = lineName(ix, +id); + worstSummerSel = { kind: "line", id: +id }; + } + } + for (const [id, v] of Object.entries(yr.trafo_loading_summer ?? {})) { + if (worstSummerPct === null || v > worstSummerPct) { + worstSummerPct = v; + worstSummerName = trafoName(ix, +id); + worstSummerSel = { kind: "trafo", id: +id }; } } - return best; + // If no seasonal data, fall back to envelope + if (worstWinterPct === null && worstSummerPct === null) { + let best: { pct: number; name: string; sel: ElementSel } | null = null; + for (const [id, v] of Object.entries(yr.line_loading ?? {})) { + if (!best || v > best.pct) { + best = { pct: v, name: lineName(ix, +id), sel: { kind: "line", id: +id } }; + } + } + for (const [id, v] of Object.entries(yr.trafo_loading ?? {})) { + if (!best || v > best.pct) { + best = { pct: v, name: trafoName(ix, +id), sel: { kind: "trafo", id: +id } }; + } + } + if (!best) return null; + return { pct: best.pct, name: best.name, sel: best.sel, winterPct: null, winterName: null, summerPct: null, summerName: null, case: null }; + } + + // Return with both worst winter and worst summer + const overallWorst = (worstWinterPct ?? 0) >= (worstSummerPct ?? 0) ? worstWinterPct! : worstSummerPct!; + const overallSel = (worstWinterPct ?? 0) >= (worstSummerPct ?? 0) ? worstWinterSel! : worstSummerSel!; + const overallName = (worstWinterPct ?? 0) >= (worstSummerPct ?? 0) ? worstWinterName! : worstSummerName!; + const winningCase = (worstWinterPct ?? 0) >= (worstSummerPct ?? 0) ? "winter peak" : "summer min"; + + return { + pct: overallWorst, + name: overallName, + sel: overallSel, + winterPct: worstWinterPct, + winterName: worstWinterName, + summerPct: worstSummerPct, + summerName: worstSummerName, + case: winningCase, + }; } /** GSP export gauge: 24 ticks, cyan, the last ones amber above 90 %. */ From e47990cf0766ecb96ac49113edddc56feaf3f768 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 17:16:26 +0000 Subject: [PATCH 09/13] Show worst winter and summer as separate statements with element names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Frontend (apps/web/src/components/LeftCards.tsx): 1. Full Readings: Two separate readings for worst winter and worst summer - Each shows its own percentage with its element name - Not combined as 'W% S%' - each stands on its own - Winter: percentage + element name on one reading - Summer: percentage + element name on separate reading 2. Narrow pill: Added element identification - Shows 'W.worst X%' and 'S.worst Y%' as separate lines - Each percentage clearly from its own worst element 3. Import captions: Changed to show '2×160.1' and '2×110.8' - Full Readings: '2×160.1 MW' for winter, '2×110.8 MW' for summer - Narrow pill: '2×160.1' and '2×110.8' (no MW, space constrained) - CompactReadings: '2×160.1' and '2×110.8' - Gauge fill, ticks, and numeric limits unchanged (still 320.2 and 221.6) - Caption only changed, matching export format (already shows '2×263.5') Each worst percentage now clearly identifies which element it came from. Winter worst ≥53% with its element, summer worst 93% with its element. Tests: 86 passed, typecheck pass Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 126 ++++++++++++++++---------- 1 file changed, 78 insertions(+), 48 deletions(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index 144475c..1bb1902 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -62,17 +62,28 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo Export{yr?.gsp_export_case ? ` (${yr.gsp_export_case === "winter_peak" ? "W" : "S"})` : ""} {computing ? "..." : gsp != null ? Math.round(gsp) : "–"}/{limit != null ? Math.round(limit) : "–"} - W.import {computing ? "..." : winterImport != null ? Math.round(winterImport) : "–"}/{winterLimit != null ? fmtMw(winterLimit) : "–"} + W.import {computing ? "..." : winterImport != null ? Math.round(winterImport) : "–"}/2×160.1 - S.import {computing ? "..." : summerImport != null ? Math.round(summerImport) : "–"}/{summerLimit != null ? fmtMw(summerLimit) : "–"} + S.import {computing ? "..." : summerImport != null ? Math.round(summerImport) : "–"}/2×110.8 V {vDisplay} - 100 ? C.red : worstPct && worstPct > 90 ? C.amber : C.ink2 }}> - Worst {worstDisplay} - + {worst && worst.winterPct !== null && worst.summerPct !== null ? ( + <> + 100 ? C.red : worst.winterPct > 90 ? C.amber : C.ink2 }}> + W.worst {computing ? "..." : `${Math.round(worst.winterPct)}%`} + + 100 ? C.red : worst.summerPct > 90 ? C.amber : C.ink2 }}> + S.worst {computing ? "..." : `${Math.round(worst.summerPct)}%`} + + + ) : ( + 100 ? C.red : worstPct && worstPct > 90 ? C.amber : C.ink2 }}> + Worst {worstDisplay} + + )} {computing && updating…} {showStale && (
- + {worst.summerName} +
+ + ) : ( + + )}
Voltage band {hasWinterVoltage && hasSummerVoltage && yr ? ( @@ -305,13 +319,13 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst
Winter import - {computing ? "..." : winterImport != null && winterLimit != null ? `${Math.round(winterImport)} / ${fmtMw(winterLimit)}` : "–"} + {computing ? "..." : winterImport != null ? `${Math.round(winterImport)} / 2×160.1` : "–"}
Summer import - {computing ? "..." : summerImport != null && summerLimit != null ? `${Math.round(summerImport)} / ${fmtMw(summerLimit)}` : "–"} + {computing ? "..." : summerImport != null ? `${Math.round(summerImport)} / 2×110.8` : "–"}
@@ -320,17 +334,33 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst {vDisplay}
-
- Worst - 100 ? C.red : worstPct && worstPct > 90 ? C.amber : C.ink }}> - {computing ? "..." : !worst ? "–" : - worst.winterPct !== null && worst.summerPct !== null ? `W${Math.round(worst.winterPct)}% S${Math.round(worst.summerPct)}%` : - worst.case && worst.winterPct !== null && worst.case === "winter peak" ? `${Math.round(worst.winterPct)}%(W)` : - worst.case && worst.summerPct !== null && worst.case === "summer min" ? `${Math.round(worst.summerPct)}%(S)` : - worstPct != null ? `${worstPct}%` : "–" - } - -
+ {worst && worst.winterPct !== null && worst.summerPct !== null ? ( + <> +
+ Worst winter + 100 ? C.red : worst.winterPct > 90 ? C.amber : C.ink }}> + {computing ? "..." : `${Math.round(worst.winterPct)}%`} + +
+
+ Worst summer + 100 ? C.red : worst.summerPct > 90 ? C.amber : C.ink }}> + {computing ? "..." : `${Math.round(worst.summerPct)}%`} + +
+ + ) : ( +
+ Worst + 100 ? C.red : worstPct && worstPct > 90 ? C.amber : C.ink }}> + {computing ? "..." : !worst ? "–" : + worst.case && worst.winterPct !== null && worst.case === "winter peak" ? `${Math.round(worst.winterPct)}%(W)` : + worst.case && worst.summerPct !== null && worst.case === "summer min" ? `${Math.round(worst.summerPct)}%(S)` : + worstPct != null ? `${worstPct}%` : "–" + } + +
+ )}
); From e6b7e50a062c1eb858b63c7296c8bab92f316710 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 17:18:25 +0000 Subject: [PATCH 10/13] Add element names to narrow pill and compact readings worst displays Frontend (apps/web/src/components/LeftCards.tsx): - Narrow pill: Added element names to worst winter and summer * Was: 'W.worst 53%' and 'S.worst 93%' (no element) * Now: 'W 53% ElementName' and 'S 93% ElementName' * Uses worst.winterName and worst.summerName - CompactReadings: Added element names to worst displays * Was: 'Worst winter 53%' and 'Worst summer 93%' (no element) * Now: 'Worst winter 53% ElementName' and 'Worst summer 93% ElementName' * Uses worst.winterName and worst.summerName * Reduced font size to 10 to fit element names Each worst percentage now clearly shows which element it came from, not pasting from open/selected card. Tests: 86 passed, typecheck pass Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index 1bb1902..be99985 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -72,11 +72,11 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo {worst && worst.winterPct !== null && worst.summerPct !== null ? ( <> - 100 ? C.red : worst.winterPct > 90 ? C.amber : C.ink2 }}> - W.worst {computing ? "..." : `${Math.round(worst.winterPct)}%`} + + W {computing ? "..." : `${Math.round(worst.winterPct)}% ${worst.winterName}`} - 100 ? C.red : worst.summerPct > 90 ? C.amber : C.ink2 }}> - S.worst {computing ? "..." : `${Math.round(worst.summerPct)}%`} + + S {computing ? "..." : `${Math.round(worst.summerPct)}% ${worst.summerName}`} ) : ( @@ -337,15 +337,15 @@ function CompactReadings({ planner, gsp, limit, gspHot, worst, vMin, vMax, worst {worst && worst.winterPct !== null && worst.summerPct !== null ? ( <>
- Worst winter - 100 ? C.red : worst.winterPct > 90 ? C.amber : C.ink }}> - {computing ? "..." : `${Math.round(worst.winterPct)}%`} + Worst winter + 100 ? C.red : worst.winterPct > 90 ? C.amber : C.ink, fontSize: 10 }}> + {computing ? "..." : `${Math.round(worst.winterPct)}% ${worst.winterName}`}
- Worst summer - 100 ? C.red : worst.summerPct > 90 ? C.amber : C.ink }}> - {computing ? "..." : `${Math.round(worst.summerPct)}%`} + Worst summer + 100 ? C.red : worst.summerPct > 90 ? C.amber : C.ink, fontSize: 10 }}> + {computing ? "..." : `${Math.round(worst.summerPct)}% ${worst.summerName}`}
From bda6ff210fb27068f64a9bd9882a4c9fb46d4a49 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 17:43:49 +0000 Subject: [PATCH 11/13] Allow narrow pill to wrap so element names and captions are visible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Frontend (apps/web/src/components/LeftCards.tsx): - Narrow pill: Added flexWrap, height auto, and whiteSpace normal * Was: Fixed height 34px, nowrap - content clipped off screen * Now: Wraps onto multiple lines, all content visible * Import captions '2×110.8' fully readable (was cut to '2×11') * Element names 'Woodhall Spa 33/11 kV' and 'Skegness to Middlemarsh 132 kV' visible Inline style overrides narrow-pill CSS to allow wrapping: - flexWrap: 'wrap' (overrides implicit nowrap) - height: 'auto' (overrides fixed 34px) - minHeight: 34 (maintains minimum height) - whiteSpace: 'normal' (overrides nowrap from CSS) Full card and short line unchanged (already approved by QA). Tests: 86 passed, typecheck pass Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index be99985..edb2caa 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -55,7 +55,7 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo `${worstPct}%`; return ( -
+
{resultProfile.label} result From b879f9f7c81ab3070f7d89b9ced982e0509420c6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 17:45:14 +0000 Subject: [PATCH 12/13] Add max-width to narrow pill to force wrapping before viewport edge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Frontend (apps/web/src/components/LeftCards.tsx): - Narrow pill: Added maxWidth constraint * Was: No right boundary - grew wider than viewport, clipped by stage * Now: maxWidth 'calc(100vw - 20px)' forces wrap before edge * Content wraps to multiple lines instead of overflowing With flexWrap + maxWidth, all content now stays within viewport: - Import caption '2×110.8' fully readable (not cut to '2×11') - Winter winner: percent + winterName visible - Summer winner: percent + summerName visible The pill wraps but stays inside the viewport. Full card and short line unchanged. Tests: 86 passed, typecheck pass Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index edb2caa..1b5886a 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -55,7 +55,7 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo `${worstPct}%`; return ( -
+
{resultProfile.label} result From a6a97cb5041f367f0057ee62b6cbac98a094126e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 3 Oct 2026 17:55:12 +0000 Subject: [PATCH 13/13] fix(web): clear narrow pill from Flow/layers panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On narrow viewports (< 1100px) with the side panel open, the .narrow-pill at top:68px left:10px was overlapping the .layers panel (Flow/Loading/etc) also at top:68px, causing the first line of the pill to be covered/clipped. The pill's maxWidth now accounts for layout.layers.right + LAYERS_W (196px) plus margin (20px), so when the side panel is open the pill stops before the layers panel starts, leaving both winter and summer winner names (with percents) and the full '2×110.8' caption visible and un-obscured. Co-authored-by: Roberto Aguilar --- apps/web/src/components/LeftCards.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/LeftCards.tsx b/apps/web/src/components/LeftCards.tsx index 1b5886a..9898205 100644 --- a/apps/web/src/components/LeftCards.tsx +++ b/apps/web/src/components/LeftCards.tsx @@ -7,7 +7,7 @@ import { X } from "@phosphor-icons/react"; import type { PlannerSlice } from "../hooks/planner/slice"; import { alertSummary } from "../lib/demand"; import { gspTicks, worstElement } from "../lib/derive"; -import type { Layout } from "../lib/layout"; +import { LAYERS_W, type Layout } from "../lib/layout"; import { C, fmtMw } from "../theme"; import { Gauge, ProfileGlyph } from "./ui"; @@ -54,8 +54,10 @@ export function LeftCards({ planner, layout }: { planner: LeftCardsPlanner; layo worst.case && worst.summerPct !== null && worst.case === "summer min" ? `${Math.round(worst.summerPct)}% (S)` : `${worstPct}%`; + const pillMaxWidth = `calc(100vw - ${layout.layers.right + LAYERS_W + 20}px)`; + return ( -
+
{resultProfile.label} result