hostcap-screen 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hostcap_screen/__init__.py +5 -0
- hostcap_screen/cli.py +67 -0
- hostcap_screen/criteria.py +123 -0
- hostcap_screen/dashboard.py +596 -0
- hostcap_screen/data/__init__.py +0 -0
- hostcap_screen/data/layout_ieee39.yaml +53 -0
- hostcap_screen/engine.py +514 -0
- hostcap_screen/errors.py +5 -0
- hostcap_screen/network.py +166 -0
- hostcap_screen/psse.py +659 -0
- hostcap_screen/redispatch.py +85 -0
- hostcap_screen/report.py +135 -0
- hostcap_screen-0.1.0.dist-info/METADATA +249 -0
- hostcap_screen-0.1.0.dist-info/RECORD +18 -0
- hostcap_screen-0.1.0.dist-info/WHEEL +5 -0
- hostcap_screen-0.1.0.dist-info/entry_points.txt +2 -0
- hostcap_screen-0.1.0.dist-info/licenses/LICENSE +674 -0
- hostcap_screen-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
"""Interactive dashboard: one self-contained HTML file that works offline.
|
|
2
|
+
|
|
3
|
+
The page follows the same design system as the other screening tools in this
|
|
4
|
+
suite (neutral grays, light and dark mode, sidebar navigation). HostCap-Screen
|
|
5
|
+
is identified by its indigo sidebar.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import math
|
|
12
|
+
from datetime import datetime, timezone
|
|
13
|
+
from html import escape
|
|
14
|
+
from importlib.resources import files
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import yaml
|
|
18
|
+
|
|
19
|
+
from . import __doi__, __version__
|
|
20
|
+
from .report import DISCLAIMER
|
|
21
|
+
|
|
22
|
+
FIXED_LAYOUTS = {"IEEE 39-bus (pandapower case39)": "layout_ieee39.yaml"}
|
|
23
|
+
AUTHOR = "Shaibu Ibrahim, P.E."
|
|
24
|
+
LICENSE = "GPL-3.0"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# ------------------------------------------------------------------ map data
|
|
28
|
+
def _edges(net):
|
|
29
|
+
edges = []
|
|
30
|
+
for i in net.line.index:
|
|
31
|
+
edges.append({"id": f"line:{i}", "a": str(net.bus.at[net.line.at[i, "from_bus"], "label"]),
|
|
32
|
+
"b": str(net.bus.at[net.line.at[i, "to_bus"], "label"]), "t": 0})
|
|
33
|
+
for i in net.trafo.index:
|
|
34
|
+
edges.append({"id": f"trafo:{i}", "a": str(net.bus.at[net.trafo.at[i, "hv_bus"], "label"]),
|
|
35
|
+
"b": str(net.bus.at[net.trafo.at[i, "lv_bus"], "label"]), "t": 1})
|
|
36
|
+
return edges
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _positions(net, edges):
|
|
40
|
+
"""Bus positions in [0, 1] (y downward) and a note on where they come from."""
|
|
41
|
+
labels = [str(x) for x in net.bus["label"]]
|
|
42
|
+
name = FIXED_LAYOUTS.get(str(net.get("hostcap_case", "")))
|
|
43
|
+
pos = None
|
|
44
|
+
if name:
|
|
45
|
+
data = yaml.safe_load(files("hostcap_screen.data").joinpath(name).read_text(encoding="utf-8"))
|
|
46
|
+
cand = {str(b): (float(x), float(y)) for b, (x, y) in data["positions"].items()}
|
|
47
|
+
if set(cand) == set(labels):
|
|
48
|
+
pos, note = cand, "Bus positions follow the usual one-line drawing of this test system; they are not geographic."
|
|
49
|
+
if pos is None:
|
|
50
|
+
import networkx as nx
|
|
51
|
+
g = nx.Graph()
|
|
52
|
+
g.add_nodes_from(labels)
|
|
53
|
+
g.add_edges_from((e["a"], e["b"]) for e in edges)
|
|
54
|
+
lay = nx.kamada_kawai_layout(g) if len(labels) <= 150 else nx.spring_layout(g, seed=1)
|
|
55
|
+
pos = {k: (float(v[0]), -float(v[1])) for k, v in lay.items()}
|
|
56
|
+
note = "Bus positions are computed from the network connections (the case has no drawing); they are not geographic."
|
|
57
|
+
xs = [p[0] for p in pos.values()]
|
|
58
|
+
ys = [p[1] for p in pos.values()]
|
|
59
|
+
sx, sy = (max(xs) - min(xs)) or 1.0, (max(ys) - min(ys)) or 1.0
|
|
60
|
+
s = max(sx, sy)
|
|
61
|
+
return {k: (round((x - min(xs)) / s, 4), round((y - min(ys)) / s, 4)) for k, (x, y) in pos.items()}, note, sx / s, sy / s
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def map_data(net):
|
|
65
|
+
edges = _edges(net)
|
|
66
|
+
pos, note, w, h = _positions(net, edges)
|
|
67
|
+
gen = {str(net.bus.at[b, "label"]) for b in net.gen.loc[net.gen.in_service, "bus"]}
|
|
68
|
+
slack = {str(net.bus.at[b, "label"]) for b in net.ext_grid.loc[net.ext_grid.in_service, "bus"]}
|
|
69
|
+
if "slack" in net.gen:
|
|
70
|
+
slack |= {str(net.bus.at[b, "label"]) for b in net.gen.loc[net.gen.in_service & net.gen.slack.fillna(False).astype(bool), "bus"]}
|
|
71
|
+
nodes = [{"bus": k, "x": x, "y": y, "g": int(k in gen), "s": int(k in slack)} for k, (x, y) in pos.items()]
|
|
72
|
+
gens = {f"gen:{i}": str(net.bus.at[net.gen.at[i, "bus"], "label"]) for i in net.gen.index}
|
|
73
|
+
return {"nodes": nodes, "edges": edges, "gens": gens, "note": note, "w": w, "h": h}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# ------------------------------------------------------------------ result data
|
|
77
|
+
def _num(x, nd=4):
|
|
78
|
+
if x is None:
|
|
79
|
+
return None
|
|
80
|
+
try:
|
|
81
|
+
x = float(x)
|
|
82
|
+
except (TypeError, ValueError):
|
|
83
|
+
return None
|
|
84
|
+
return None if math.isnan(x) or math.isinf(x) else round(x, nd)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _viol(v):
|
|
88
|
+
return {"kind": v.kind, "el": v.element, "eid": v.element_id, "cond": v.condition,
|
|
89
|
+
"oid": v.outage_id, "val": _num(v.value), "lim": _num(v.limit), "ff": v.flow_from}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def dataset(name, screener, results):
|
|
93
|
+
rows = []
|
|
94
|
+
for r in results:
|
|
95
|
+
b = r.binding
|
|
96
|
+
rows.append({
|
|
97
|
+
"bus": r.bus, "mw": _num(r.capability_mw, 1), "status": r.status,
|
|
98
|
+
"b": _viol(b) if b else None,
|
|
99
|
+
"q": _num(r.plant_q_mvar, 2), "ql": bool(r.plant_q_limited),
|
|
100
|
+
"warn": list(r.warnings), "all": [_viol(v) for v in r.violations_at_limit[:40]],
|
|
101
|
+
"nall": len(r.violations_at_limit),
|
|
102
|
+
"nx": _num(r.next_mw, 1), "nb": _viol(r.next_binding) if r.next_binding else None, "nn": r.next_note,
|
|
103
|
+
})
|
|
104
|
+
c = screener.crit
|
|
105
|
+
return {
|
|
106
|
+
"name": name,
|
|
107
|
+
"policy": c.preexisting_policy,
|
|
108
|
+
"rows": rows,
|
|
109
|
+
"pre": [_viol(v) for v in screener.preexisting],
|
|
110
|
+
"studied": [{"name": screener.state_name(s), "id": f"{s[0]}:{s[1]}"} for s in screener.contingencies],
|
|
111
|
+
"skipped": [{"name": n, "why": w} for n, w in screener.skipped],
|
|
112
|
+
"settings": {
|
|
113
|
+
"redispatch": screener.redispatch, "reactive": screener.reactive, "pf": screener.pf_limit,
|
|
114
|
+
"pmax": screener.pmax, "tol": screener.tol,
|
|
115
|
+
"headroom": None if math.isinf(screener.headroom) else _num(screener.headroom, 1),
|
|
116
|
+
"genout": bool(screener.include_gen_outages), "next": bool(screener.next_limit),
|
|
117
|
+
},
|
|
118
|
+
"criteria": {
|
|
119
|
+
"profile": c.profile_name,
|
|
120
|
+
"vn": [c.v_min_normal, c.v_max_normal], "vc": [c.v_min_contingency, c.v_max_contingency],
|
|
121
|
+
"tn": c.thermal_normal_pct, "tc": c.thermal_limit_pct(True), "erat": c.emergency_rating_pct_of_normal,
|
|
122
|
+
"tolpu": c.preexisting_tol_pu, "tolpct": c.preexisting_tol_pct, "minkv": c.monitor_min_kv,
|
|
123
|
+
"bands": len(c.voltage_bands), "overrides": len(c.bus_overrides),
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def dashboard_data(screener, datasets):
|
|
129
|
+
return {
|
|
130
|
+
"tool": "HostCap-Screen", "version": __version__, "doi": __doi__, "author": AUTHOR, "license": LICENSE,
|
|
131
|
+
"case": str(screener.base.get("hostcap_case", "network")),
|
|
132
|
+
"run": datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC"),
|
|
133
|
+
"disclaimer": DISCLAIMER,
|
|
134
|
+
"notes": list(screener.base.get("hostcap_notes", []) or []),
|
|
135
|
+
"pickup": getattr(screener, "pickup_basis", "maximum MW"),
|
|
136
|
+
"map": map_data(screener.base),
|
|
137
|
+
"sets": datasets,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def render_dashboard(data) -> str:
|
|
142
|
+
payload = json.dumps(data, separators=(",", ":"), allow_nan=False)
|
|
143
|
+
payload = payload.replace("</", "<\\/").replace("<!--", "<\\!--") # cannot close the script tag
|
|
144
|
+
title = f"HostCap-Screen · {escape(data['case'])}"
|
|
145
|
+
return (TEMPLATE.replace("__TITLE__", title)
|
|
146
|
+
.replace("__DATA__", payload))
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def write_dashboard(path, screener, results, compare=None) -> None:
|
|
150
|
+
"""Write the dashboard. `compare` is an optional (name, screener, results)
|
|
151
|
+
for a second policy shown with a switch (used for the public demo)."""
|
|
152
|
+
first = "Strict (pre-existing violations may not worsen)" if screener.crit.preexisting_policy == "worsen" \
|
|
153
|
+
else "Lenient (pre-existing violations ignored)"
|
|
154
|
+
sets = [dataset(first, screener, results)]
|
|
155
|
+
if compare is not None:
|
|
156
|
+
sets.append(dataset(*compare))
|
|
157
|
+
Path(path).write_text(render_dashboard(dashboard_data(screener, sets)), encoding="utf-8")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
# ------------------------------------------------------------------ page
|
|
161
|
+
TEMPLATE = r"""<!DOCTYPE html>
|
|
162
|
+
<html lang="en"><head><meta charset="utf-8">
|
|
163
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
164
|
+
<meta name="color-scheme" content="light dark">
|
|
165
|
+
<title>__TITLE__</title>
|
|
166
|
+
<style>
|
|
167
|
+
:root{--bg:#fff;--fg:#1d2939;--muted:#667085;--line:#e4e7ec;--card:#f8f9fb;--page:#eef1f4;--accent:#0a9396;
|
|
168
|
+
--ok:#079455;--okbg:#ecfdf3;--wk:#dc6803;--wkbg:#fffaeb;--vw:#d92d20;--vwbg:#fef3f2;
|
|
169
|
+
--side:#2b2a5e;--side-on:#3b3a7a;--side-fg:#d9d8f0;--side-mut:#a9a7d6;--side-hl:#a5a3ff;
|
|
170
|
+
--th:#4b48a8;--vo:#0a9396;--nl:#98a2b3;
|
|
171
|
+
--c0:#e3e2f6;--c1:#bdbaeb;--c2:#8f8ad8;--c3:#5d58bb;--c4:#2b2a5e;--cs:#6e6ab8}
|
|
172
|
+
@media (prefers-color-scheme:dark){:root{--bg:#101828;--fg:#f2f4f7;--muted:#98a2b3;--line:#344054;--card:#1d2939;--page:#0b1220;
|
|
173
|
+
--okbg:#0b3321;--wkbg:#3a2508;--vwbg:#3b1512;--side:#1c1b42;--side-on:#2c2b62;--th:#8a87e8;--vo:#3cc2c4;
|
|
174
|
+
--c0:#34336a;--c1:#4c49a0;--c2:#6f6bd2;--c3:#9f9bf2;--c4:#d6d4ff;--cs:#8a87e8}}
|
|
175
|
+
*{box-sizing:border-box}
|
|
176
|
+
html,body{margin:0}
|
|
177
|
+
body{font:15px/1.55 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;color:var(--fg);background:var(--page)}
|
|
178
|
+
h1,h2,h3{line-height:1.25;margin:0}
|
|
179
|
+
.skip{position:absolute;left:-999px}.skip:focus{left:8px;top:8px;z-index:20;background:var(--bg);padding:6px 10px}
|
|
180
|
+
.app{display:grid;grid-template-columns:224px minmax(0,1fr);min-height:100vh}
|
|
181
|
+
.side{position:sticky;top:0;height:100vh;overflow:auto;background:var(--side);color:var(--side-fg);display:flex;flex-direction:column;padding:18px 0 0;z-index:6}
|
|
182
|
+
.brand{padding:0 18px 14px;display:flex;gap:10px;align-items:flex-start}
|
|
183
|
+
.brand svg{flex:none;margin-top:3px}
|
|
184
|
+
.brand b{display:block;font-size:18px;color:#fff}
|
|
185
|
+
.brand small{display:block;font-size:12px;color:var(--side-mut);margin-top:2px}
|
|
186
|
+
.nav{display:flex;flex-direction:column}
|
|
187
|
+
.nav button{font:inherit;font-size:14px;text-align:left;display:flex;justify-content:space-between;align-items:center;gap:8px;
|
|
188
|
+
padding:9px 18px;border:0;border-left:3px solid transparent;background:none;color:var(--side-fg);cursor:pointer}
|
|
189
|
+
.nav button:hover{background:rgba(255,255,255,.07)}
|
|
190
|
+
.nav button[aria-current=page]{background:var(--side-on);border-left-color:var(--side-hl);color:#fff;font-weight:600}
|
|
191
|
+
button:focus-visible,input:focus-visible,select:focus-visible,tr:focus-visible,g.bus:focus-visible{outline:2px solid var(--side-hl);outline-offset:-2px}
|
|
192
|
+
.badge{font-size:11px;font-weight:600;border-radius:999px;padding:1px 7px;background:#4a4890;color:#fff;font-variant-numeric:tabular-nums}
|
|
193
|
+
.badge.wk{background:var(--wk)}.badge.vw{background:var(--vw)}.badge:empty{display:none}
|
|
194
|
+
.sfoot{margin-top:auto;padding:14px 18px;font-size:11.5px;color:var(--side-mut);line-height:1.5}
|
|
195
|
+
.main{min-width:0;display:flex;flex-direction:column}
|
|
196
|
+
.dtop{position:sticky;top:0;z-index:5;background:var(--bg);border-bottom:2px solid var(--accent)}
|
|
197
|
+
.dhead{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;padding:10px 22px}
|
|
198
|
+
.dhead h1{font-size:18px}.dhead .meta{font-size:13px;color:var(--muted)}
|
|
199
|
+
.dbtns{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
|
|
200
|
+
.dbtn,select{font:inherit;font-size:13px;padding:6px 11px;border-radius:7px;border:1px solid var(--line);background:var(--bg);color:var(--fg);cursor:pointer}
|
|
201
|
+
.setsw{display:flex;gap:6px;align-items:center;font-size:13px;color:var(--muted);min-width:0;max-width:100%}
|
|
202
|
+
.setsw select{min-width:0;max-width:100%;text-overflow:ellipsis}
|
|
203
|
+
[hidden]{display:none!important}
|
|
204
|
+
.dbtns{min-width:0;max-width:100%}.dhead>div{min-width:0}
|
|
205
|
+
.chips{display:flex;gap:6px;flex-wrap:wrap;padding:0 22px 10px}
|
|
206
|
+
.chip{font-size:12px;border:1px solid var(--line);border-radius:999px;padding:2px 9px;color:var(--muted);background:var(--card)}
|
|
207
|
+
.chip b{color:var(--fg);font-weight:600}
|
|
208
|
+
.kpis{padding:12px 22px 0}
|
|
209
|
+
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:10px}
|
|
210
|
+
.card{background:var(--bg);border:1px solid var(--line);border-radius:10px;padding:10px 14px;min-width:0}
|
|
211
|
+
.card .k{font-size:11px;text-transform:uppercase;letter-spacing:.04em;color:var(--muted)}
|
|
212
|
+
.card .v{font-size:22px;font-weight:700;font-variant-numeric:tabular-nums}
|
|
213
|
+
.card .v.vw{color:var(--vw)}.card .v.wk{color:var(--wk)}
|
|
214
|
+
.card .sub{font-size:12.5px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
215
|
+
body:not(.v-overview) .card{padding:6px 12px}body:not(.v-overview) .card .v{font-size:17px}body:not(.v-overview) .card .sub{display:none}
|
|
216
|
+
.views{padding:14px 22px 26px;flex:1}
|
|
217
|
+
.view{display:none}.view.on{display:block}
|
|
218
|
+
.panel{background:var(--bg);border:1px solid var(--line);border-radius:10px;padding:14px 16px;min-width:0}
|
|
219
|
+
.panel+.panel{margin-top:14px}
|
|
220
|
+
.panel h2{font-size:16px;margin-bottom:6px}
|
|
221
|
+
.panel p.note{font-size:13px;color:var(--muted);margin:2px 0 10px}
|
|
222
|
+
.ov{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(280px,1fr);gap:14px;align-items:start}
|
|
223
|
+
.ov .panel+.panel{margin-top:0}
|
|
224
|
+
.mapwrap{border-radius:8px;background:var(--card);overflow:hidden}
|
|
225
|
+
svg.netmap{display:block;width:100%;height:auto}
|
|
226
|
+
.netmap .e{stroke:var(--nl);stroke-width:2;fill:none}.netmap .e.t{stroke-dasharray:4 4}
|
|
227
|
+
.netmap .e.bind{stroke:var(--vw);stroke-width:6;stroke-linecap:round;animation:bindpulse 1.6s ease-in-out infinite}
|
|
228
|
+
.netmap .ants{stroke:#fff;stroke-width:2;stroke-dasharray:6 10;fill:none;pointer-events:none;animation:flow .9s linear infinite}
|
|
229
|
+
.netmap .e.out{stroke:var(--fg);stroke-width:3;stroke-dasharray:2 6;animation:fadeout 1.2s ease forwards}
|
|
230
|
+
.netmap .xmark{font-size:16px;font-weight:700;fill:var(--fg);stroke:var(--card);stroke-width:3px;paint-order:stroke;text-anchor:middle;dominant-baseline:central}
|
|
231
|
+
.netmap .halo{fill:none;stroke:var(--vw);stroke-width:2.5;transform-box:fill-box;transform-origin:center;display:none;pointer-events:none}
|
|
232
|
+
.netmap g.bus.hl .halo{display:block;animation:pulse 1.8s ease-out infinite}
|
|
233
|
+
.mctl{display:flex;gap:10px 14px;flex-wrap:wrap;align-items:center;margin:0 0 10px;font-size:13px}
|
|
234
|
+
.seg{display:inline-flex;border:1px solid var(--line);border-radius:8px;overflow:hidden}
|
|
235
|
+
.seg button{font:inherit;font-size:13px;border:0;background:var(--bg);color:var(--muted);padding:5px 11px;cursor:pointer}
|
|
236
|
+
.seg button[aria-pressed=true]{background:var(--side);color:#fff}
|
|
237
|
+
.psl{accent-color:var(--accent);width:180px;vertical-align:middle}
|
|
238
|
+
.pv{font-variant-numeric:tabular-nums;min-width:64px;display:inline-block}
|
|
239
|
+
.pc,.nxv{color:var(--muted)}
|
|
240
|
+
.bars .gh{position:absolute;top:0;height:100%;border-radius:4px;background:repeating-linear-gradient(45deg,color-mix(in srgb,var(--th) 35%,transparent) 0 4px,transparent 4px 8px)}
|
|
241
|
+
.bars .tr .br{position:relative;z-index:1}
|
|
242
|
+
.netmap g.bus{cursor:pointer}.netmap .hit{fill:transparent}
|
|
243
|
+
.netmap .node{stroke:var(--cs);stroke-width:1.5;transition:fill .35s ease}
|
|
244
|
+
.netmap g.bus.sel .node{stroke:var(--fg);stroke-width:3}
|
|
245
|
+
.netmap g.bus.vb .ring{stroke:var(--vw);stroke-width:3;fill:none}
|
|
246
|
+
.netmap text{font-size:11px;fill:var(--muted);paint-order:stroke;stroke:var(--card);stroke-width:3px}
|
|
247
|
+
.netmap text.mw{font-size:10px;font-weight:600;fill:var(--fg)}
|
|
248
|
+
.legend{display:flex;gap:6px 14px;flex-wrap:wrap;font-size:12.5px;color:var(--muted);margin-top:8px;align-items:center}
|
|
249
|
+
.legend i{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;vertical-align:-1px}
|
|
250
|
+
.legend i.sq{border-radius:2px}.legend i.ln{width:18px;height:0;border-radius:0;border-top:4px solid var(--vw)}
|
|
251
|
+
.legend i.ld{width:18px;height:0;border-radius:0;border-top:3px dotted var(--fg)}
|
|
252
|
+
.det h3{font-size:17px;margin-bottom:8px}
|
|
253
|
+
.dgrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 12px;margin:6px 0 10px}
|
|
254
|
+
.dgrid>div>span{display:block;font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.04em}
|
|
255
|
+
.dgrid b{font-variant-numeric:tabular-nums;font-weight:600}
|
|
256
|
+
.det .why{font-size:13.5px;margin:6px 0}
|
|
257
|
+
.det .empty{color:var(--muted);font-size:13.5px}
|
|
258
|
+
.pill{display:inline-block;font-size:11.5px;font-weight:600;border-radius:999px;padding:1px 8px;white-space:nowrap}
|
|
259
|
+
.pill.th{background:color-mix(in srgb,var(--th) 15%,transparent);color:var(--th)}
|
|
260
|
+
.pill.vo{background:color-mix(in srgb,var(--vo) 15%,transparent);color:var(--vo)}
|
|
261
|
+
.pill.nl{background:var(--card);color:var(--muted)}
|
|
262
|
+
.pill.wk{background:var(--wkbg);color:var(--wk)}.pill.vw{background:var(--vwbg);color:var(--vw)}
|
|
263
|
+
.tw{overflow-x:auto}
|
|
264
|
+
table{border-collapse:collapse;width:100%;font-size:13.5px}
|
|
265
|
+
th,td{padding:6px 8px;border-bottom:1px solid var(--line);text-align:left;vertical-align:top}
|
|
266
|
+
th{font-size:11.5px;text-transform:uppercase;letter-spacing:.04em;color:var(--muted);font-weight:600;white-space:nowrap}
|
|
267
|
+
th.s{cursor:pointer}th.s:after{content:" ↕";opacity:.4}th.s.asc:after{content:" ↑";opacity:1}th.s.desc:after{content:" ↓";opacity:1}
|
|
268
|
+
td.n,th.n{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
269
|
+
tbody tr.click{cursor:pointer}tbody tr.click:hover td{background:var(--card)}tr.sel td{background:var(--card);font-weight:600}
|
|
270
|
+
.tools{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin:0 0 10px;font-size:13px}
|
|
271
|
+
.tools input[type=search]{font:inherit;font-size:13px;padding:5px 9px;border:1px solid var(--line);border-radius:7px;background:var(--bg);color:var(--fg);min-width:200px}
|
|
272
|
+
.bars{display:grid;grid-template-columns:auto minmax(120px,1fr) auto;gap:5px 10px;align-items:center;font-size:13px}
|
|
273
|
+
.bars .nm{white-space:nowrap;font-weight:600}
|
|
274
|
+
.bars .tr{height:14px;background:var(--card);border-radius:4px;position:relative;overflow:hidden;cursor:pointer}
|
|
275
|
+
.bars .br{height:100%;border-radius:4px}
|
|
276
|
+
.bars .br.th{background:var(--th)}.bars .br.vo{background:var(--vo)}.bars .br.nl{background:var(--nl)}
|
|
277
|
+
.bars .n{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
278
|
+
.kv{display:grid;grid-template-columns:max-content 1fr;gap:4px 16px;font-size:14px}
|
|
279
|
+
.kv dt{color:var(--muted)}.kv dd{margin:0}
|
|
280
|
+
ul.plain{margin:4px 0;padding-left:18px;font-size:14px}
|
|
281
|
+
.disc{font-size:13px;background:var(--card);border-left:4px solid var(--accent);padding:8px 12px;border-radius:4px;margin-bottom:12px}
|
|
282
|
+
.pfoot{padding:12px 22px 18px;font-size:12px;color:var(--muted);border-top:1px solid var(--line);background:var(--bg)}
|
|
283
|
+
@keyframes fade{from{opacity:0}}
|
|
284
|
+
@keyframes rise{from{opacity:0;transform:translateY(8px)}}
|
|
285
|
+
@keyframes grow{from{width:0}}
|
|
286
|
+
@keyframes pop{0%{transform:scale(0)}70%{transform:scale(1.3)}100%{transform:scale(1)}}
|
|
287
|
+
@keyframes pulse{0%{transform:scale(1);opacity:.8}100%{transform:scale(2.4);opacity:0}}
|
|
288
|
+
@keyframes flow{to{stroke-dashoffset:-32}}
|
|
289
|
+
@keyframes bindpulse{50%{stroke-opacity:.55}}
|
|
290
|
+
@keyframes fadeout{from{opacity:1}to{opacity:.35}}
|
|
291
|
+
body.intro .card{animation:rise .5s ease both}
|
|
292
|
+
body.intro .card:nth-child(2){animation-delay:.06s}body.intro .card:nth-child(3){animation-delay:.12s}
|
|
293
|
+
body.intro .card:nth-child(4){animation-delay:.18s}body.intro .card:nth-child(5){animation-delay:.24s}body.intro .card:nth-child(6){animation-delay:.3s}
|
|
294
|
+
body.intro .netmap .e{animation:fade .6s ease both}
|
|
295
|
+
body.intro .netmap .node{transform-box:fill-box;transform-origin:center;animation:pop .45s ease-out both}
|
|
296
|
+
body.intro .netmap text{animation:fade .5s ease 1s both}
|
|
297
|
+
body.intro .bars .br{animation:grow .8s cubic-bezier(.2,.8,.2,1) both}
|
|
298
|
+
@media (prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}
|
|
299
|
+
@media (max-width:860px){
|
|
300
|
+
.app{grid-template-columns:minmax(0,1fr)}
|
|
301
|
+
.side{position:sticky;height:auto;padding:10px 0 0;min-width:0;max-width:100vw}
|
|
302
|
+
.nav{max-width:100%;scrollbar-width:thin}
|
|
303
|
+
.nav{flex-direction:row;overflow-x:auto}
|
|
304
|
+
.nav button{border-left:0;border-bottom:3px solid transparent;white-space:nowrap;padding:8px 12px}
|
|
305
|
+
.nav button[aria-current=page]{border-bottom-color:var(--side-hl)}
|
|
306
|
+
.sfoot{display:none}.ov{grid-template-columns:minmax(0,1fr)}.dtop{position:static}
|
|
307
|
+
.kv{grid-template-columns:minmax(0,1fr)}.kv dd{margin-bottom:6px;overflow-wrap:anywhere}
|
|
308
|
+
.disc,.panel p,.why{overflow-wrap:anywhere}
|
|
309
|
+
.views,.kpis,.dhead,.chips{padding-left:12px;padding-right:12px}
|
|
310
|
+
}
|
|
311
|
+
@media print{
|
|
312
|
+
*{animation:none!important;transition:none!important}
|
|
313
|
+
.side,.dbtns,.tools,.mctl .seg,.psl{display:none!important}.app{display:block}.dtop{position:static;border-bottom:1px solid #999}
|
|
314
|
+
body{background:#fff}.view{display:block!important;break-before:page}.view:first-child{break-before:auto}
|
|
315
|
+
.panel{break-inside:avoid}.ov{grid-template-columns:1fr}.tw{overflow:visible}
|
|
316
|
+
}
|
|
317
|
+
</style></head>
|
|
318
|
+
<body class="v-overview">
|
|
319
|
+
<a class="skip" href="#main">Skip to content</a>
|
|
320
|
+
<div class="app">
|
|
321
|
+
<aside class="side" aria-label="Views">
|
|
322
|
+
<div class="brand">
|
|
323
|
+
<svg width="26" height="26" viewBox="0 0 26 26" aria-hidden="true"><path d="M3 19a10 10 0 0 1 20 0" fill="none" stroke="#a5a3ff" stroke-width="2.6" stroke-linecap="round"/><path d="M13 19l5.5-6.5" stroke="#fff" stroke-width="2.4" stroke-linecap="round"/><circle cx="13" cy="19" r="2.2" fill="#fff"/></svg>
|
|
324
|
+
<div><b>HostCap-Screen</b><small id="brandsub"></small></div>
|
|
325
|
+
</div>
|
|
326
|
+
<nav class="nav" id="nav" aria-label="Views"></nav>
|
|
327
|
+
<div class="sfoot">Screening results, not a study. Criteria are user values.</div>
|
|
328
|
+
</aside>
|
|
329
|
+
<div class="main">
|
|
330
|
+
<div class="dtop">
|
|
331
|
+
<div class="dhead">
|
|
332
|
+
<div><h1>Hosting capacity screening results</h1><div class="meta" id="meta"></div></div>
|
|
333
|
+
<div class="dbtns">
|
|
334
|
+
<label class="setsw" id="setsw" hidden>Results <select id="setsel"></select></label>
|
|
335
|
+
<button class="dbtn" id="csv" type="button">Download CSV</button>
|
|
336
|
+
<button class="dbtn" id="prt" type="button">Print / PDF</button>
|
|
337
|
+
</div>
|
|
338
|
+
</div>
|
|
339
|
+
<div class="chips" id="chips"></div>
|
|
340
|
+
</div>
|
|
341
|
+
<div class="kpis"><div class="cards" id="cards"></div></div>
|
|
342
|
+
<main class="views" id="main"></main>
|
|
343
|
+
<footer class="pfoot" id="pfoot"></footer>
|
|
344
|
+
</div>
|
|
345
|
+
</div>
|
|
346
|
+
<script id="data" type="application/json">__DATA__</script>
|
|
347
|
+
<script>
|
|
348
|
+
(function(){
|
|
349
|
+
"use strict";
|
|
350
|
+
const D=JSON.parse(document.getElementById("data").textContent);
|
|
351
|
+
let S=D.sets[0], sel=null, sortK="mw", sortD=1, q="", mode="cap", proj=100;
|
|
352
|
+
const $=id=>document.getElementById(id);
|
|
353
|
+
const esc=s=>String(s==null?"":s).replace(/[&<>"']/g,c=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[c]));
|
|
354
|
+
const f0=x=>x==null?"–":Number(x).toLocaleString("en-US",{maximumFractionDigits:0});
|
|
355
|
+
const f3=x=>x==null?"–":Number(x).toFixed(3);
|
|
356
|
+
const unit=k=>k&&k.startsWith("voltage")?"pu":"%";
|
|
357
|
+
const fv=(v,k)=>v==null?"–":(unit(k)==="pu"?Number(v).toFixed(4)+" pu":Number(v).toFixed(2)+" %");
|
|
358
|
+
const typ=r=>!r.b?"nl":(r.b.kind.startsWith("voltage")?"vo":(r.b.kind.startsWith("thermal")?"th":"nl"));
|
|
359
|
+
const TYPN={th:"Thermal",vo:"Voltage",nl:"No network limit"};
|
|
360
|
+
const KIND={voltage_low:"Low voltage",voltage_high:"High voltage",thermal_line:"Line overload",thermal_trafo:"Transformer overload",non_convergence:"Load flow did not converge"};
|
|
361
|
+
const VIEWS=[["overview","Overview"],["map","Network map"],["rank","Rankings"],["table","Results table"],["pre","Pre-existing issues"],["outages","Outages"],["method","Method & assumptions"]];
|
|
362
|
+
|
|
363
|
+
/* ---------- colors ----------
|
|
364
|
+
Capability mode: fixed MW bins on one indigo scale (deeper = more room),
|
|
365
|
+
so a color means the same MW in every run.
|
|
366
|
+
My project mode: status colors, since fit / tight / no fit is a result. */
|
|
367
|
+
const BINS=[25,100,250,500];
|
|
368
|
+
function cbin(mw){if(mw==null)return -1;let i=0;while(i<BINS.length&&mw>=BINS[i])i++;return i;}
|
|
369
|
+
function pclass(mw){if(mw==null)return "na";if(mw<proj)return "no";if(mw<proj*1.1)return "tight";return "fit";}
|
|
370
|
+
const PC={fit:"var(--ok)",tight:"var(--wk)",no:"var(--vw)",na:"var(--nl)"};
|
|
371
|
+
const PN={fit:"fits",tight:"fits, under 10% margin",no:"does not fit",na:"not screened"};
|
|
372
|
+
function lowest5(){return new Set([...S.rows].filter(r=>r.mw!=null).sort((a,b)=>a.mw-b.mw).slice(0,5).map(r=>r.bus));}
|
|
373
|
+
function nodeFill(r){if(!r||r.mw==null)return "var(--nl)";return mode==="proj"?PC[pclass(r.mw)]:CV[cbin(r.mw)];}
|
|
374
|
+
function haloOn(r,low){if(!r||r.mw==null)return false;return mode==="proj"?pclass(r.mw)==="no":low.has(r.bus);}
|
|
375
|
+
const CV=["var(--c0)","var(--c1)","var(--c2)","var(--c3)","var(--c4)"];
|
|
376
|
+
|
|
377
|
+
/* ---------- shell ---------- */
|
|
378
|
+
function shell(){
|
|
379
|
+
$("brandsub").textContent=D.case.split(" (")[0]+" · v"+D.version;
|
|
380
|
+
$("meta").textContent=S.rows.length+" bus(es) screened · "+D.case+" · "+D.run;
|
|
381
|
+
const st=S.settings, c=S.criteria;
|
|
382
|
+
$("chips").innerHTML=[
|
|
383
|
+
["Redispatch",st.redispatch==="proportional"?"proportional":"slack only"],
|
|
384
|
+
["Reactive",st.reactive==="voltage"?"voltage control ±"+st.pf+" pf":"unity pf"],
|
|
385
|
+
["Pre-existing",S.policy==="worsen"?"strict":"ignored"],
|
|
386
|
+
["Criteria",c.profile.length>34?c.profile.slice(0,32)+"…":c.profile]
|
|
387
|
+
].map(([k,v])=>`<span class="chip">${esc(k)}: <b>${esc(v)}</b></span>`).join("");
|
|
388
|
+
if(D.sets.length>1){$("setsw").hidden=false;$("setsel").innerHTML=D.sets.map((s,i)=>`<option value="${i}">${esc(s.name)}</option>`).join("");$("setsel").value=String(D.sets.indexOf(S));}
|
|
389
|
+
const cite=D.doi?`Cite: <a href="https://doi.org/${esc(D.doi)}">doi:${esc(D.doi)}</a>`:"Cite: see the repository's CITATION.cff";
|
|
390
|
+
$("pfoot").innerHTML=`Screening only · HostCap-Screen v${esc(D.version)} · Developed by ${esc(D.author)} · ${cite} · ${esc(D.license)}`;
|
|
391
|
+
const m=$("main");
|
|
392
|
+
m.innerHTML=VIEWS.map(([k])=>`<section class="view" id="v-${k}" aria-labelledby="h-${k}"></section>`).join("");
|
|
393
|
+
}
|
|
394
|
+
function nav(){
|
|
395
|
+
const nPre=S.pre.length, nSk=S.skipped.length;
|
|
396
|
+
const badge={pre:[nPre,nPre?"wk":""],outages:[nSk,""]};
|
|
397
|
+
$("nav").innerHTML=VIEWS.map(([k,t])=>{const b=badge[k];return `<button type="button" data-v="${k}">${esc(t)}<span class="badge ${b?b[1]:""}">${b&&b[0]?b[0]:""}</span></button>`}).join("");
|
|
398
|
+
$("nav").querySelectorAll("button").forEach(b=>b.onclick=()=>show(b.dataset.v));
|
|
399
|
+
}
|
|
400
|
+
function show(k){
|
|
401
|
+
document.querySelectorAll(".view").forEach(v=>v.classList.toggle("on",v.id==="v-"+k));
|
|
402
|
+
$("nav").querySelectorAll("button").forEach(b=>{if(b.dataset.v===k)b.setAttribute("aria-current","page");else b.removeAttribute("aria-current");});
|
|
403
|
+
const intro=document.body.classList.contains("intro");document.body.className="v-"+k+(intro?" intro":"");
|
|
404
|
+
/* Bookmarkable view in the address bar. Sandboxed previews (e.g. embedded
|
|
405
|
+
viewers) forbid this, so it is skipped silently there. */
|
|
406
|
+
try{if(location.hash!=="#"+k)history.replaceState(null,"","#"+k);}catch(e){}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/* ---------- KPI cards ---------- */
|
|
410
|
+
function cards(){
|
|
411
|
+
const r=S.rows.filter(x=>x.mw!=null), v=r.map(x=>x.mw).sort((a,b)=>a-b);
|
|
412
|
+
const med=v.length?(v.length%2?v[(v.length-1)/2]:(v[v.length/2-1]+v[v.length/2])/2):null;
|
|
413
|
+
const hi=r.reduce((a,b)=>!a||b.mw>a.mw?b:a,null), lo=r.reduce((a,b)=>!a||b.mw<a.mw?b:a,null);
|
|
414
|
+
const nth=r.filter(x=>typ(x)==="th").length, nvo=r.filter(x=>typ(x)==="vo").length;
|
|
415
|
+
const C=[
|
|
416
|
+
["Buses screened",S.rows.length,"","search max "+f0(S.settings.pmax)+" MW"],
|
|
417
|
+
["Highest capability",hi?f0(hi.mw)+" MW":"–","","bus "+(hi?hi.bus:"–")],
|
|
418
|
+
["Median capability",med!=null?f0(med)+" MW":"–","",""],
|
|
419
|
+
["Lowest capability",lo?f0(lo.mw)+" MW":"–","","bus "+(lo?lo.bus:"–")],
|
|
420
|
+
["Binding limit type",nth+" / "+nvo,"","thermal / voltage"],
|
|
421
|
+
["Pre-existing issues",S.pre.length,S.pre.length?"wk":"","at 0 MW added"]];
|
|
422
|
+
$("cards").innerHTML=C.map(([k,v,c,s])=>`<div class="card"><div class="k">${esc(k)}</div><div class="v ${c}">${esc(v)}</div><div class="sub">${esc(s)}</div></div>`).join("");
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/* ---------- network map ---------- */
|
|
426
|
+
function mapSVG(big){
|
|
427
|
+
const M=D.map, W=900, H=Math.max(380,Math.round(W*M.h/Math.max(M.w,.01)*0.92)), P=34;
|
|
428
|
+
const sx=x=>P+x/Math.max(M.w,.01)*(W-2*P), sy=y=>P+y/Math.max(M.h,.01)*(H-2*P);
|
|
429
|
+
const pos={};M.nodes.forEach(n=>pos[n.bus]=[sx(n.x),sy(n.y)]);
|
|
430
|
+
const byBus={};S.rows.forEach(r=>byBus[r.bus]=r);
|
|
431
|
+
const cur=sel?byBus[sel]:null, b=cur&&cur.b?cur.b:null, bid=b?b.eid:"", oid=b?b.oid:"";
|
|
432
|
+
const outGenBus=oid.startsWith("gen:")?M.gens[oid]:null, low=lowest5();
|
|
433
|
+
const ne=Math.max(M.edges.length,1), nn=Math.max(M.nodes.length,1);
|
|
434
|
+
let s=`<svg class="netmap" viewBox="0 0 ${W} ${H}" role="img" aria-label="Network map, buses colored by injection capability"><g>`, top="";
|
|
435
|
+
M.edges.forEach((e,i)=>{const a=pos[e.a],c=pos[e.b];if(!a||!c)return;
|
|
436
|
+
const isB=e.id===bid, isO=e.id===oid;
|
|
437
|
+
const cls="e"+(e.t?" t":"")+(isB?" bind":"")+(isO?" out":"");
|
|
438
|
+
const d=`style="animation-delay:${Math.round(i*700/ne)}ms"`;
|
|
439
|
+
s+=`<line class="${cls}" ${isB||isO?"":d} x1="${a[0].toFixed(1)}" y1="${a[1].toFixed(1)}" x2="${c[0].toFixed(1)}" y2="${c[1].toFixed(1)}"><title>${esc((e.t?"Transformer ":"Line ")+e.a+"-"+e.b)}</title></line>`;
|
|
440
|
+
if(isB){/* moving dashes run from the bus the power flows from */
|
|
441
|
+
const [p1,p2]=b.ff===e.b?[c,a]:[a,c];
|
|
442
|
+
top+=`<line class="ants" x1="${p1[0].toFixed(1)}" y1="${p1[1].toFixed(1)}" x2="${p2[0].toFixed(1)}" y2="${p2[1].toFixed(1)}"/>`;}
|
|
443
|
+
if(isO)top+=`<text class="xmark" x="${((a[0]+c[0])/2).toFixed(1)}" y="${((a[1]+c[1])/2).toFixed(1)}">✕</text>`;});
|
|
444
|
+
s+="</g>"+top;
|
|
445
|
+
M.nodes.forEach((n,i)=>{const [x,y]=pos[n.bus],r=byBus[n.bus],fill=nodeFill(r);
|
|
446
|
+
const isb=bid==="bus:"+n.bus, rad=big?9:8, dl=`style="animation-delay:${300+Math.round(i*900/nn)}ms"`;
|
|
447
|
+
const shape=n.g||n.s?`<rect class="node" ${dl} x="${(x-rad).toFixed(1)}" y="${(y-rad).toFixed(1)}" width="${2*rad}" height="${2*rad}" rx="2" fill="${fill}"/>`:`<circle class="node" ${dl} cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${rad}" fill="${fill}"/>`;
|
|
448
|
+
const tip=r?`Bus ${n.bus}: ${f0(r.mw)} MW`+(r.b?` · ${KIND[r.b.kind]||r.b.kind}: ${r.b.el}`:""):`Bus ${n.bus}: not screened`;
|
|
449
|
+
s+=`<g class="bus${n.bus===sel?" sel":""}${isb?" vb":""}${haloOn(r,low)?" hl":""}" data-bus="${esc(n.bus)}" tabindex="0" role="button" aria-label="${esc(tip)}"><title>${esc(tip)}</title><circle class="hit" cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${rad+7}"/><circle class="halo" cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${rad}"/>${isb?`<circle class="ring" cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${rad+6}"/>`:""}${shape}<text x="${(x+rad+3).toFixed(1)}" y="${(y-rad+2).toFixed(1)}">${esc(n.bus)}</text>${big&&r?`<text class="mw" x="${(x+rad+3).toFixed(1)}" y="${(y+rad+5).toFixed(1)}">${f0(r.mw)}</text>`:""}${outGenBus===n.bus?`<text class="xmark" x="${x.toFixed(1)}" y="${(y+rad+12).toFixed(1)}">✕</text>`:""}</g>`;});
|
|
450
|
+
s+="</svg>";
|
|
451
|
+
return s;
|
|
452
|
+
}
|
|
453
|
+
function legendHTML(){
|
|
454
|
+
const tail=`<span><i class="sq" style="background:var(--nl)"></i>square: generator bus</span><span><i class="ln"></i>binding element (moving dashes show flow)</span><span><i class="ld"></i>✕ outage causing it</span><span>dashed line: transformer</span>`;
|
|
455
|
+
if(mode==="proj")return `${["fit","tight","no"].map(k=>`<span><i style="background:${PC[k]}"></i>${esc(PN[k])}</span>`).join("")}<span><i style="background:transparent;border:2px solid var(--vw)"></i>pulsing ring: does not fit</span>`+tail;
|
|
456
|
+
const lab=["< 25 MW","25–100 MW","100–250 MW","250–500 MW","≥ 500 MW"];
|
|
457
|
+
return `Capability: ${lab.map((l,i)=>`<span><i style="background:${CV[i]};border:1px solid var(--cs)"></i>${l}</span>`).join("")}<span><i style="background:transparent;border:2px solid var(--vw)"></i>pulsing ring: 5 lowest</span>`+tail;
|
|
458
|
+
}
|
|
459
|
+
function legend(){return `<div class="legend">${legendHTML()}</div>`;}
|
|
460
|
+
function counter(){const n=S.rows.filter(r=>r.mw!=null&&r.mw>=proj).length;return `${n} of ${S.rows.length} buses can take ${f0(proj)} MW`;}
|
|
461
|
+
function mctl(){
|
|
462
|
+
const mx=Math.max(100,Math.ceil(S.settings.pmax/100)*100);
|
|
463
|
+
return `<div class="mctl"><div class="seg" role="group" aria-label="Map mode"><button type="button" data-m="cap" aria-pressed="${mode==="cap"}">Capability</button><button type="button" data-m="proj" aria-pressed="${mode==="proj"}">My project</button></div>
|
|
464
|
+
<span class="slw"${mode==="proj"?"":" hidden"}><label>Project size <input type="range" class="psl" min="10" max="${mx}" step="10" value="${proj}" aria-label="Project size in MW"></label> <b class="pv">${f0(proj)} MW</b> <span class="pc">${esc(counter())}</span></span></div>`;
|
|
465
|
+
}
|
|
466
|
+
/* Slider and mode changes recolor in place (smooth fill transition, no re-draw). */
|
|
467
|
+
function recolor(){
|
|
468
|
+
const byBus={};S.rows.forEach(r=>byBus[r.bus]=r);const low=lowest5();
|
|
469
|
+
document.querySelectorAll("svg.netmap g.bus").forEach(g=>{const r=byBus[g.dataset.bus];
|
|
470
|
+
g.querySelector(".node").setAttribute("fill",nodeFill(r));g.classList.toggle("hl",haloOn(r,low));});
|
|
471
|
+
document.querySelectorAll(".legend.map").forEach(l=>l.innerHTML=legendHTML());
|
|
472
|
+
document.querySelectorAll(".pv").forEach(e=>e.textContent=f0(proj)+" MW");
|
|
473
|
+
document.querySelectorAll(".pc").forEach(e=>e.textContent=counter());
|
|
474
|
+
document.querySelectorAll(".psl").forEach(e=>{if(+e.value!==proj)e.value=proj;});
|
|
475
|
+
document.querySelectorAll(".seg button").forEach(b=>b.setAttribute("aria-pressed",String(b.dataset.m===mode)));
|
|
476
|
+
document.querySelectorAll(".slw").forEach(e=>e.hidden=mode!=="proj");
|
|
477
|
+
}
|
|
478
|
+
function wireMap(root){
|
|
479
|
+
root.querySelectorAll("g.bus").forEach(g=>{const go=()=>select(g.dataset.bus);g.onclick=go;g.onkeydown=e=>{if(e.key==="Enter"||e.key===" "){e.preventDefault();go();}};});
|
|
480
|
+
}
|
|
481
|
+
function wireCtl(){
|
|
482
|
+
document.querySelectorAll(".seg button").forEach(b=>b.onclick=()=>{mode=b.dataset.m;recolor();});
|
|
483
|
+
document.querySelectorAll(".psl").forEach(sl=>sl.oninput=e=>{proj=+e.target.value;recolor();});
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/* ---------- details ---------- */
|
|
487
|
+
function details(){
|
|
488
|
+
const r=S.rows.find(x=>x.bus===sel);
|
|
489
|
+
if(!r)return `<h2>Bus details</h2><p class="empty">Select a bus on the map, in the rankings or in the table.</p>`;
|
|
490
|
+
const t=typ(r), b=r.b;
|
|
491
|
+
let h=`<h3>Bus ${esc(r.bus)}</h3><div class="dgrid">
|
|
492
|
+
<div><span>Injection capability</span><b>${f0(r.mw)} MW</b></div>
|
|
493
|
+
<div><span>Limit type</span><b><span class="pill ${t}">${TYPN[t]}</span></b></div>
|
|
494
|
+
<div><span>Plant reactive power</span><b>${r.q==null?"–":Number(r.q).toFixed(1)+" Mvar"}${r.ql?" (at limit)":""}</b></div>
|
|
495
|
+
<div><span>Status</span><b style="font-weight:500">${esc(r.status)}</b></div></div>`;
|
|
496
|
+
if(b){h+=`<p class="why"><b>${esc(KIND[b.kind]||b.kind)}</b> on <b>${esc(b.el)}</b>${b.oid?` after the <b>${esc(b.cond.replace(/^Outage of /,"outage of "))}</b>`:" in the <b>base case</b>"}: ${fv(b.val,b.kind)} against a limit of ${fv(b.lim,b.kind)}, just above ${f0(r.mw)} MW.</p>`;
|
|
497
|
+
if(r.nx!=null){const nb=r.nb;h+=`<p class="why"><span class="pill th">If upgraded</span> With <b>${esc(b.el.replace(/ \(pre-existing, worsened\)/,""))}</b> upgraded, capability rises to <b>${f0(r.nx)} MW</b> (+${f0(r.nx-r.mw)} MW)${nb?`, where <b>${esc(nb.el)}</b> limits next (${esc(nb.cond.replace(/^Outage of /,"outage of "))})`:""}${r.nn?". "+esc(r.nn):""}.</p>`;}
|
|
498
|
+
else if(r.nn){h+=`<p class="why"><span class="pill nl">If upgraded</span> ${esc(r.nn)}.</p>`;}
|
|
499
|
+
if(r.nall>1){h+=`<details><summary>All ${r.nall} violations at the limit</summary><div class="tw"><table><thead><tr><th>Type</th><th>Element</th><th>Condition</th><th class="n">Value</th><th class="n">Limit</th></tr></thead><tbody>${r.all.map(v=>`<tr><td>${esc(KIND[v.kind]||v.kind)}</td><td>${esc(v.el)}</td><td>${esc(v.cond)}</td><td class="n">${fv(v.val,v.kind)}</td><td class="n">${fv(v.lim,v.kind)}</td></tr>`).join("")}</tbody></table></div>${r.nall>r.all.length?`<p class="note">First ${r.all.length} shown; all are in the JSON output.</p>`:""}</details>`;}}
|
|
500
|
+
if(r.warn.length)h+=`<p class="why">${r.warn.map(w=>`<span class="pill wk">Note</span> ${esc(w)}`).join("<br>")}</p>`;
|
|
501
|
+
return h;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/* ---------- views ---------- */
|
|
505
|
+
function vOverview(){
|
|
506
|
+
const lows=[...S.rows].filter(r=>r.mw!=null).sort((a,b)=>a.mw-b.mw).slice(0,8);
|
|
507
|
+
return `<div class="ov"><div class="panel"><h2 id="h-overview">Network map</h2><p class="note">Each bus is colored by the MW a new plant there could inject before a thermal or voltage limit is reached (base case or any single outage). Select a bus for details.</p>${mctl()}<div class="mapwrap">${mapSVG(false)}</div><div class="legend map">${legendHTML()}</div></div>
|
|
508
|
+
<div><div class="panel det" id="det-o">${details()}</div><div class="panel"><h2>Lowest capability</h2>${miniTable(lows)}</div></div></div>`;
|
|
509
|
+
}
|
|
510
|
+
function miniTable(rows){
|
|
511
|
+
return `<div class="tw"><table><thead><tr><th>Bus</th><th class="n">MW</th><th>Binding</th></tr></thead><tbody>${rows.map(r=>`<tr class="click${r.bus===sel?" sel":""}" data-bus="${esc(r.bus)}" tabindex="0"><td>${esc(r.bus)}</td><td class="n">${f0(r.mw)}</td><td>${r.b?esc(r.b.el.replace(/ \(pre-existing, worsened\)/," *")):"–"}</td></tr>`).join("")}</tbody></table></div>${rows.some(r=>r.b&&r.b.el.includes("pre-existing"))?`<p class="note">* pre-existing violation, worsened beyond tolerance</p>`:""}`;
|
|
512
|
+
}
|
|
513
|
+
function vMap(){return `<div class="ov"><div class="panel"><h2 id="h-map">Network map</h2><p class="note">${esc(D.map.note)} Labels under each bus give the capability in MW.</p>${mctl()}<div class="mapwrap">${mapSVG(true)}</div><div class="legend map">${legendHTML()}</div></div><div class="panel det">${details()}</div></div>`;}
|
|
514
|
+
function vRank(){
|
|
515
|
+
const r=[...S.rows].sort((a,b)=>(b.mw??-1)-(a.mw??-1)), mx=Math.max(1,...r.map(x=>Math.max(x.mw||0,x.nx||0)));
|
|
516
|
+
return `<div class="panel"><h2 id="h-rank">Capability by bus</h2><p class="note">Sorted from highest to lowest. Bar color shows what limits each bus. Select a bar for details.</p>
|
|
517
|
+
<div class="legend" style="margin:0 0 10px"><span><i class="sq" style="background:var(--th)"></i>thermal limit</span><span><i class="sq" style="background:var(--vo)"></i>voltage limit</span><span><i class="sq" style="background:var(--nl)"></i>no network limit found</span><span><i class="sq" style="background:repeating-linear-gradient(45deg,var(--th) 0 3px,transparent 3px 6px)"></i>hatched: capability if the binding branch is upgraded (→ MW)</span></div>
|
|
518
|
+
<div class="bars">${r.map(x=>{const t=typ(x);return `<span class="nm">Bus ${esc(x.bus)}</span><div class="tr" data-bus="${esc(x.bus)}" title="${esc(TYPN[t])}${x.nx!=null?" · if upgraded: "+f0(x.nx)+" MW":""}">${x.nx!=null?`<div class="gh" style="width:${(Math.min(x.nx,mx)/mx*100).toFixed(1)}%"></div>`:""}<div class="br ${t}" style="width:${((x.mw||0)/mx*100).toFixed(1)}%"></div></div><span class="n">${f0(x.mw)} MW${x.nx!=null?` <span class="nxv">→ ${f0(x.nx)}</span>`:""}</span>`}).join("")}</div></div>`;
|
|
519
|
+
}
|
|
520
|
+
function vTable(){
|
|
521
|
+
const cols=[["bus","Bus",0],["mw","Capability (MW)",1],["type","Limit",0],["el","Binding element",0],["cond","Condition",0],["val","Value",1],["lim","Limit value",1],["nx","If upgraded (MW)",1],["q","Q (Mvar)",1]];
|
|
522
|
+
return `<div class="panel"><h2 id="h-table">Results table</h2><div class="tools"><input type="search" id="q" placeholder="Filter by bus or element" value="${esc(q)}" aria-label="Filter results"><span class="note" id="cnt"></span></div>
|
|
523
|
+
<div class="tw"><table id="rt"><thead><tr>${cols.map(([k,t,n])=>`<th class="s${n?" n":""}${sortK===k?(sortD>0?" asc":" desc"):""}" data-k="${k}">${esc(t)}</th>`).join("")}</tr></thead><tbody id="rtb"></tbody></table></div></div>`;
|
|
524
|
+
}
|
|
525
|
+
function rowVal(r,k){const b=r.b||{};return {bus:isNaN(+r.bus)?r.bus:+r.bus,mw:r.mw,type:TYPN[typ(r)],el:b.el||"",cond:b.cond||"",val:b.val,lim:b.lim,nx:r.nx,q:r.q}[k];}
|
|
526
|
+
function fillTable(){
|
|
527
|
+
const tb=$("rtb");if(!tb)return;
|
|
528
|
+
const ql=q.trim().toLowerCase();
|
|
529
|
+
let rows=S.rows.filter(r=>!ql||("bus "+r.bus+" "+(r.b?r.b.el+" "+r.b.cond:"")).toLowerCase().includes(ql));
|
|
530
|
+
rows.sort((a,b)=>{const x=rowVal(a,sortK),y=rowVal(b,sortK);if(x==null)return 1;if(y==null)return -1;return (x>y?1:x<y?-1:0)*sortD;});
|
|
531
|
+
tb.innerHTML=rows.map(r=>{const b=r.b;return `<tr class="click${r.bus===sel?" sel":""}" data-bus="${esc(r.bus)}" tabindex="0"><td>${esc(r.bus)}</td><td class="n">${f0(r.mw)}</td><td><span class="pill ${typ(r)}">${TYPN[typ(r)]}</span></td><td>${b?esc(b.el):"–"}</td><td>${b?esc(b.cond):"–"}</td><td class="n">${b?fv(b.val,b.kind):"–"}</td><td class="n">${b?fv(b.lim,b.kind):"–"}</td><td class="n">${r.nx==null?"–":f0(r.nx)}</td><td class="n">${r.q==null?"–":Number(r.q).toFixed(1)}</td></tr>`}).join("");
|
|
532
|
+
$("cnt").textContent=rows.length+" of "+S.rows.length+" buses";
|
|
533
|
+
wireRows(tb);
|
|
534
|
+
}
|
|
535
|
+
function vPre(){
|
|
536
|
+
const p=S.pre;
|
|
537
|
+
return `<div class="panel"><h2 id="h-pre">Pre-existing issues at 0 MW</h2><p class="note">These violations exist before any plant is added. ${S.policy==="worsen"?`Under the strict policy a plant is limited if it worsens one by more than ${S.criteria.tolpu} pu (voltage) or ${S.criteria.tolpct}% (loading).`:"Under the lenient policy they never limit a plant."} They usually point to a model, dispatch or rating issue to review before relying on the results.</p>
|
|
538
|
+
${p.length?`<div class="tw"><table><thead><tr><th>Type</th><th>Element</th><th>Condition</th><th class="n">Value</th><th class="n">Limit</th></tr></thead><tbody>${p.map(v=>`<tr><td>${esc(KIND[v.kind]||v.kind)}</td><td>${esc(v.el)}</td><td>${esc(v.cond)}</td><td class="n">${fv(v.val,v.kind)}</td><td class="n">${fv(v.lim,v.kind)}</td></tr>`).join("")}</tbody></table></div>`:`<p class="empty">None.</p>`}</div>`;
|
|
539
|
+
}
|
|
540
|
+
function vOut(){
|
|
541
|
+
return `<div class="panel"><h2 id="h-outages">Outages not studied (${S.skipped.length})</h2><p class="note">Branch outages that cut buses off from the rest of the system are skipped. ${S.settings.genout?"When the cut-off part holds only a generator, the generator outage studied covers it.":"Generator outages were turned off for this run."}</p>
|
|
542
|
+
${S.skipped.length?`<div class="tw"><table><thead><tr><th>Outage</th><th>Reason</th></tr></thead><tbody>${S.skipped.map(s=>`<tr><td>${esc(s.name)}</td><td>${esc(s.why)}</td></tr>`).join("")}</tbody></table></div>`:`<p class="empty">None.</p>`}</div>
|
|
543
|
+
<div class="panel"><h2>Outages studied (${S.studied.length})</h2><ul class="plain">${S.studied.map(s=>`<li>${esc(s.name)}</li>`).join("")}</ul></div>`;
|
|
544
|
+
}
|
|
545
|
+
function vMethod(){
|
|
546
|
+
const c=S.criteria, st=S.settings;
|
|
547
|
+
return `<div class="panel"><h2 id="h-method">Method</h2><p class="disc">${esc(D.disclaimer)}</p>
|
|
548
|
+
<ol class="plain"><li>A new plant is added at the bus.</li><li>${st.redispatch==="proportional"?"Existing synchronous generators are reduced in proportion to their output (never below their minimum) to balance it.":"The slack source absorbs the added output."}</li>
|
|
549
|
+
<li>AC load flow is run for the base case and every single line, transformer${S.settings.genout?" and generator":""} outage.${S.settings.genout?" A lost generator's output is picked up by the other units in proportion to their ${esc(D.pickup)}, up to their maximum; the slack source covers any rest. The slack generator is never redispatched or tripped.":""}</li><li>A bisection search finds the largest output with no new or worsened violation, then lower outputs are spot-checked.</li>${S.settings.next?"<li>If a line or transformer limits the bus, the search is repeated with that element treated as upgraded, to show the value of the upgrade.</li>":""}</ol></div>
|
|
550
|
+
<div class="panel"><h2>Criteria and settings</h2><dl class="kv">
|
|
551
|
+
<dt>Criteria profile</dt><dd>${esc(c.profile)}</dd>
|
|
552
|
+
<dt>Voltage, base case</dt><dd>${(+c.vn[0]).toFixed(2)}–${(+c.vn[1]).toFixed(2)} pu</dd><dt>Voltage, after an outage</dt><dd>${(+c.vc[0]).toFixed(2)}–${(+c.vc[1]).toFixed(2)} pu</dd>
|
|
553
|
+
<dt>Thermal, base case</dt><dd>${c.tn}% of normal rating</dd><dt>Thermal, after an outage</dt><dd>${c.tc}% of normal rating (emergency rating = ${c.erat}% of normal)</dd>
|
|
554
|
+
<dt>Voltage bands / bus overrides</dt><dd>${c.bands} / ${c.overrides}</dd><dt>Monitored buses</dt><dd>${c.minkv>0?"≥ "+c.minkv+" kV":"all"}</dd>
|
|
555
|
+
<dt>Pre-existing policy</dt><dd>${S.policy==="worsen"?`strict: may not worsen by more than ${c.tolpu} pu / ${c.tolpct}%`:"lenient: ignored"}</dd>
|
|
556
|
+
<dt>Reactive power</dt><dd>${st.reactive==="voltage"?`plant holds its pre-project bus voltage within ±${st.pf} power factor; at the limit Q is held and voltage floats`:"unity power factor"}</dd>
|
|
557
|
+
<dt>Search</dt><dd>0 to ${f0(st.pmax)} MW, tolerance ${st.tol} MW${st.headroom!=null?`; redispatch headroom ${f0(st.headroom)} MW`:""}</dd></dl>
|
|
558
|
+
<p class="note">Default criteria are common screening values, not the criteria of any ISO, RTO or utility. NERC TPL-001 leaves specific limits to each Transmission Planner and Planning Coordinator.</p></div>
|
|
559
|
+
${D.notes.length?`<div class="panel"><h2>Model import notes</h2><ul class="plain">${D.notes.map(n=>`<li>${esc(n)}</li>`).join("")}</ul></div>`:""}
|
|
560
|
+
<div class="panel"><h2>Limitations</h2><ul class="plain">
|
|
561
|
+
<li>The reactive range is applied at the point of interconnection bus; the plant's step-up transformer and collector system are not modeled.</li>
|
|
562
|
+
<li>Branch outages that island buses with load are not studied in this version. Generator pickup is a steady-state approximation of governor response.</li>
|
|
563
|
+
<li>One new plant at a time. Double outages, stability, short-circuit strength and ISO-specific deliverability methods are out of scope.</li>
|
|
564
|
+
<li>The reported value is feasible; the true limit lies less than two tolerance steps above it.</li></ul></div>`;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/* ---------- wiring ---------- */
|
|
568
|
+
function wireRows(root){root.querySelectorAll("tr.click,.bars .tr").forEach(t=>{const go=()=>select(t.dataset.bus);t.onclick=go;t.onkeydown=e=>{if(e.key==="Enter"){e.preventDefault();go();}};});}
|
|
569
|
+
function render(){
|
|
570
|
+
cards();nav();
|
|
571
|
+
$("v-overview").innerHTML=vOverview();$("v-map").innerHTML=vMap();$("v-rank").innerHTML=vRank();
|
|
572
|
+
$("v-table").innerHTML=vTable();$("v-pre").innerHTML=vPre();$("v-outages").innerHTML=vOut();$("v-method").innerHTML=vMethod();
|
|
573
|
+
document.querySelectorAll(".mapwrap").forEach(wireMap);wireCtl();wireRows(document);fillTable();
|
|
574
|
+
const qi=$("q");if(qi)qi.oninput=e=>{q=e.target.value;fillTable();};
|
|
575
|
+
document.querySelectorAll("#rt th.s").forEach(th=>th.onclick=()=>{const k=th.dataset.k;sortD=sortK===k?-sortD:(k==="mw"||k==="val"||k==="q"||k==="nx"?-1:1);sortK=k;render();});
|
|
576
|
+
}
|
|
577
|
+
function select(bus){sel=bus;const cur=(document.querySelector(".view.on")||{}).id;render();if(cur)show(cur.slice(2));}
|
|
578
|
+
function csv(){
|
|
579
|
+
const h=["bus","capability_mw","limit_type","binding_type","binding_element","binding_condition","binding_value","binding_limit","flow_from_bus","next_limit_mw","next_binding_element","next_binding_condition","next_note","plant_q_mvar","status","warnings"];
|
|
580
|
+
const cell=v=>{v=v==null?"":String(v);if(/^[=+\-@]/.test(v))v="'"+v;return /[",\n]/.test(v)?'"'+v.replace(/"/g,'""')+'"':v;};
|
|
581
|
+
const rows=S.rows.map(r=>{const b=r.b||{};return [r.bus,r.mw,TYPN[typ(r)],b.kind,b.el,b.cond,b.val,b.lim,b.ff,r.nx,r.nb?r.nb.el:"",r.nb?r.nb.cond:"",r.nn,r.q,r.status,r.warn.join(" | ")].map(cell).join(",");});
|
|
582
|
+
const blob=new Blob([h.join(",")+"\n"+rows.join("\n")+"\n"],{type:"text/csv"});
|
|
583
|
+
const a=document.createElement("a");a.href=URL.createObjectURL(blob);a.download="hostcap_results.csv";document.body.appendChild(a);a.click();setTimeout(()=>{URL.revokeObjectURL(a.href);a.remove();},0);
|
|
584
|
+
}
|
|
585
|
+
shell();
|
|
586
|
+
$("csv").onclick=csv;$("prt").onclick=()=>window.print();
|
|
587
|
+
$("setsel").onchange=e=>{S=D.sets[+e.target.value];const cur=(document.querySelector(".view.on")||{}).id;shell();render();show(cur?cur.slice(2):"overview");};
|
|
588
|
+
const lo=[...S.rows].filter(r=>r.mw!=null).sort((a,b)=>a.mw-b.mw)[0];sel=lo?lo.bus:null;
|
|
589
|
+
document.body.classList.add("intro");
|
|
590
|
+
render();
|
|
591
|
+
setTimeout(()=>document.body.classList.remove("intro"),2200);
|
|
592
|
+
const h=location.hash.slice(1);show(VIEWS.some(v=>v[0]===h)?h:"overview");
|
|
593
|
+
})();
|
|
594
|
+
</script>
|
|
595
|
+
</body></html>
|
|
596
|
+
"""
|
|
File without changes
|