In this section
- Substation Intelligence V9 63 geodesy · code-generator / apps/substation-finder/Si/202609062358-substation-intelligence-v9-63.js lines 2801–3500
Substation Intelligence V9 63
A JavaScript file in the substation finder folder of Code Generator that maps elizabeth line and uses data from the ventus-grid-engine repository. Served with the page at https://ventusltd.github.io/code-generator/apps/substation-finder/Si/.
Set aside from the main view: 100% of its lines are the same as atlas/cartridges/202611180026-substation-intelligence-v9-63.js (gridatlas), which stays. (near-copy-of, proposed by families.py). 99% of lines shared with Substation Intelligence V9 63; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9974 to gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/cartridges/202611180026-substation-intelligence-v9-63.js:1-8609 c6f9632fdb6e803baae03a54a542fe508431d153
- sha256 d94b0de50deddac77643325b10fbe490ce44b8c406dbc6c67e6e7cadbdaa8ec6
- target sha256 88c538b97bf426776cda436151741f17500a2136867d28362407550d72f9038f
- group of 4 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
geodesycode-generator / apps/substation-finder/Si/202609062358-substation-intelligence-v9-63.js · lines 2801–3500 of 8590 · version 2026-09-06 23:58 (continued from section 283) · Not reached from any entry point (candidate for review) · pattern switchOn (shared by 4 files)
- What it does
- It maps elizabeth line, london underground, UK metros trams and hs2. Defines 238 functions or classes, including deepFreeze, escapeHTML, normalizeStatus, fmt, haversine. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage upstream_foresight (path word 'substation'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: 750kV, 400kV, 275kV, 132kV, 66kV, 33kV.
- Inputs & outputs
- In: data source: ventus-grid-engine data; data source: data-federation-map-for-globalgrid2050-all-repos data; data source: spiders data; data source: npm data; GeoJSON file elizabeth_line.geojson; GeoJSON file london_underground.geojson; GeoJSON file uk_metros_trams.geojson; GeoJSON file hs2.geojson. Out: downloaded file gridatlas-; downloaded file globalgrid2050-grid-atlas-; interactive map; canvas drawing; SVG drawing. Voltage levels named: 750kV, 400kV, 275kV, 132kV, 66kV, 33kV, 11kV.
- What it achieves
- It normalizes status (`normalizeStatus`), toggles zone draw mode (`toggleZoneDrawMode`) and opens popup (`openPopup`). ASSEMBLED by `tools/build-cartridge.mjs` from the parts below. Its code works with 400 kV, 100 MVA and 132 kV. It responds to fullscreenchange, webkitfullscreenchange and click events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- code-generator · apps/substation-finder/Si · script
- VEDIC
- SNAP LINE ENDS TO SUBSTATIONS (GG2050-VEDIC-000106): GridAtlas / Substations · Geospatial data processing. line_features, substation_point_features → Line features whose first and last vertices are moved onto the nearest substation point within tolerance; other geometry unchanged.
- VEDIC
- MEASURE (GG2050-VEDIC-000001): GridAtlas / Geodesy · Mathematics / Spherical geometry. coordinate_pair, coordinate_pair → distance_km
- VEDIC
- REPRESENT (GG2050-VEDIC-000002): GridAtlas / Geodesy · Computer science / Geometry processing. geojson_geometry → coordinate_pair_or_null
- Uses
- Spider Full Po Test (estate URL), Data — Grid Studies Public Page (estate URL)
- Used by
- none found
- Produces
- deepFreeze, escapeHTML, normalizeStatus, fmt, haversine, _zoneDrawGetRadius, _zoneDrawCirclePoints, _zoneDrawCalcArea, _zoneDrawUpdateLayers, _zoneDrawShowPopup, _zoneDrawShowPopupDebounced, _zoneDrawClear
- Defines here
- makeUnionFind, find, assemble, busOf, componentOf, multiply, solve, sinkFor, respond, modelFor, asString, asNumber, statusRank, yearRank, publishedToday, index, describe
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- code-generator@3897d83efcd0259d21dce87704b0c33118fe2c2e apps/substation-finder/Si/202609062358-substation-intelligence-v9-63.js:2801-3500 · blob 2c8121b277e1b152a96688f6a2e0d7ef83471376 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: duplicate_candidate
* transfer has two ends and quoting only one is meaningless.
* Taps Not published, therefore not modelled. Transformers are
* represented by their series reactance alone.
* Shunts b_pct_100mva is carried by the product and is NOT used:
* line charging does not appear in a DC model.
* Contingency None. This is the intact network.
*
* ─────────────────────────────────────────────────────────────────────
* WHAT THE ANSWER IS NOT
* ─────────────────────────────────────────────────────────────────────
*
* It is not a loading, and it is not headroom. It says what fraction of a
* NEW injection would appear on each circuit. What is already flowing on
* that circuit is not published anywhere in this product, so the sum of
* the two - which is what determines whether the circuit is full - cannot
* be computed here by anyone, including this module. A circuit carrying
* 38% of a 500 MW injection is carrying 190 MW of it; whether that
* circuit can accept 190 MW more depends on facts no appendix contains.
*
* ─────────────────────────────────────────────────────────────────────
* ZERO-REACTANCE BRANCHES
* ─────────────────────────────────────────────────────────────────────
*
* The product publishes circuits with x_pct_100mva of exactly 0 - zero
* length spans, busbar couplers, some series devices. 1/x is undefined for
* these, and substituting a small number would silently invent a
* reactance. They are instead treated as what they physically are: a
* short, meaning the two nodes are electrically the same bus. The nodes
* are merged before the matrix is built, the merge is counted, and the
* count is reported in the answer.
*
* ─────────────────────────────────────────────────────────────────────
* WHAT THE FIRST VERSION GOT WRONG
* ─────────────────────────────────────────────────────────────────────
*
* Codex reviewed this adversarially on request and found two defects that
* the proof could not see, both of them the same shape: the proof tested a
* case the production caller never takes.
*
* 1. NO ARBITRARY SLACK. The caller chose the first bus that was not the
* injection bus. The 400 kV induced graph is not connected - 573 buses,
* 437 modelled edges, 238 components - so that bus is usually in a
* different component from the injection, and a transfer between two
* components does not exist. West Burton was paired with ABHA41, which
* is disconnected from 572 of the 573 buses; the solve ran 2,292
* iterations to a residual of about 1.7e13.
*
* Worse, acceptance checked Kirchhoff at the INJECTION BUS ONLY, which
* a disconnected pair can satisfy while the solve has not converged at
* all. A page gated on that check could print an impossible transfer.
*
* Now: the withdrawal bus must be in the same component as the
* injection, the component is computed and named, and where no sink is
* declared the rule that picks one is stated in the answer rather than
* left implicit. Acceptance requires convergence AND a global residual
* AND Kirchhoff at EVERY bus. Anything else is an explicit refusal.
*
* 2. PARALLEL CIRCUITS ARE NOT ONE CIRCUIT. Edges were de-duplicated by
* endpoints, kind and reactance, so two genuine parallel circuits that
* publish the same reactance collapsed into one - 22 groups covering 45
* published rows at 400 kV. Two parallel circuits carry twice what one
* carries at the same angle, so the collapse understated the network.
* Every landing is still visited twice, once from each end; the row
* ITSELF is now the identity, which distinguishes "seen twice" from
* "two rows that look alike".
*
* node tools/proofs/modules/202609020015-injection-response.proof.mjs
*/
(() => {
const NS = window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {};
if (NS.injectionResponse) return;
const SCHEMA = 'gridatlas.module.injection-response.v2';
const REQUIRES = 'gridatlas.module.network-topology.graph.v1';
const BASE_MVA = 100;
const DECLARED_MODEL = Object.freeze({
method: 'linear DC power flow (injection response / power transfer distribution factor)',
equations: 'P = B′ · θ ; branch flow f_ij = (θ_i − θ_j) / x_ij',
base_mva: BASE_MVA,
reactance: 'x = x_pct_100mva / 100, per unit, as published',
resistance: 'not used; the DC approximation neglects series resistance',
shunt_susceptance: 'not used; line charging does not appear in a DC model',
voltages: 'assumed flat at 1.0 per unit; not published and not solved',
angles: 'assumed small, so sin θ ≈ θ',
losses: 'zero by construction; real losses are of order 1-2% and are not represented',
transformer_taps: 'not published, therefore not modelled; transformers are their series reactance only',
contingencies: 'none; this is the intact network',
slack: 'declared explicitly on every answer, never inferred silently'
});
const NOT_A_LOADING =
'This is the response to a NEW injection, not a loading. What is '
+ 'already flowing on these circuits is published nowhere in this '
+ 'product, so the total flow - which is what decides whether a '
+ 'circuit is full - cannot be computed here by anyone.';
const NOT_A_CONNECTION_OFFER =
'A fraction of an injection appearing on a circuit is not permission '
+ 'to use that circuit. Queue position, committed connections, outage '
+ 'conditions, consent and commercial terms decide what a project may '
+ 'connect, and no published appendix contains any of them.';
/* ── union-find, for shorting zero-reactance branches ──────────────── */
function makeUnionFind() {
const parent = new Map();
function find(x) {
if (!parent.has(x)) { parent.set(x, x); return x; }
let root = x;
while (parent.get(root) !== root) root = parent.get(root);
let cursor = x;
while (parent.get(cursor) !== cursor) {
const next = parent.get(cursor);
parent.set(cursor, root);
cursor = next;
}
return root;
}
return {
find,
union(a, b) {
const ra = find(a);
const rb = find(b);
if (ra === rb) return false;
parent.set(ra, rb);
return true;
}
};
}
/* The matrix assembly, taking an explicit node list so the caller
decides the scope - one site, one voltage, or the whole product -
without a second copy of this code existing for each case. */
function assemble(graph, nodeNames, { voltageKv, includeTransformers }) {
const inScope = new Set(nodeNames);
const uf = makeUnionFind();
for (const n of nodeNames) uf.find(n);
const branches = [];
const seen = new Set();
let shorted = 0;
let skippedNoReactance = 0;
for (const name of nodeNames) {
for (const entry of graph.edgesAt(name)) {
if (entry.kind === 'transformer' && !includeTransformers) continue;
const far = entry.row[entry.far];
if (!inScope.has(far)) continue;
/* The published ROW is the identity, not its values.
----------------------------------------------------------
Keying on endpoints + kind + reactance collapsed genuine
parallel circuits that happen to publish the same reactance:
22 groups covering 45 rows at 400 kV. Two parallel circuits
carry twice what one carries at the same angle, so collapsing
them understates the network - and it understates it silently,
which is worse. Every landing is visited twice, once from each
end, and the row object distinguishes that from two rows that
merely look alike. (Codex 202609020030, finding 2.) */
if (seen.has(entry.row)) continue;
seen.add(entry.row);
const xPct = entry.row.x_pct_100mva;
if (!Number.isFinite(xPct)) { skippedNoReactance += 1; continue; }
if (xPct === 0) {
/* physically a short: the two nodes are the same bus */
if (uf.union(name, far)) shorted += 1;
continue;
}
branches.push({
from: name, to: far, kind: entry.kind,
x_pu: xPct / 100,
row: entry.row
});
}
}
/* After shorting, work in terms of bus representatives. */
const busOf = (name) => uf.find(name);
const buses = [...new Set(nodeNames.map(busOf))].sort();
const busIndex = new Map(buses.map((b, i) => [b, i]));
const edges = [];
for (const b of branches) {
const i = busIndex.get(busOf(b.from));
const j = busIndex.get(busOf(b.to));
if (i === undefined || j === undefined || i === j) continue;
edges.push({ i, j, b: 1 / b.x_pu, meta: b });
}
/* Which buses can actually reach each other.
--------------------------------------------------------------------
A DC transfer between two components is not a transfer; it is a
singular system, and asking a solver for it produces a large number
rather than an error. So the components are computed here, once,
and every answer names the one it was solved in. */
const comp = makeUnionFind();
for (const b of buses) comp.find(b);
for (const e of edges) comp.union(buses[e.i], buses[e.j]);
const componentOf = (bus) => comp.find(bus);
const componentSizes = new Map();
for (const b of buses) {
const root = componentOf(b);
componentSizes.set(root, (componentSizes.get(root) || 0) + 1);
}
/* the degree of each bus, for the declared sink rule below */
const degree = new Map();
for (const e of edges) {
degree.set(buses[e.i], (degree.get(buses[e.i]) || 0) + 1);
degree.set(buses[e.j], (degree.get(buses[e.j]) || 0) + 1);
}
return {
schema: SCHEMA,
declared_model: DECLARED_MODEL,
componentOf,
componentSize: (bus) => componentSizes.get(componentOf(bus)) || 0,
degreeOf: (bus) => degree.get(bus) || 0,
voltage_kv: voltageKv,
includes_transformers: includeTransformers,
buses, busIndex, busOf, edges,
counts: {
nodes: nodeNames.length,
buses: buses.length,
branches: edges.length,
shorted_zero_reactance: shorted,
skipped_no_published_reactance: skippedNoReactance,
components: componentSizes.size,
largest_component: Math.max(0, ...componentSizes.values())
}
};
}
/* ── sparse conjugate gradient on the reduced B' matrix ────────────── */
function multiply(model, x, slackIndex) {
const y = new Float64Array(x.length);
for (const e of model.edges) {
if (e.i === slackIndex || e.j === slackIndex) {
/* the slack angle is pinned at zero, so its column contributes
nothing and its row is not solved */
if (e.i !== slackIndex) y[e.i] += e.b * x[e.i];
if (e.j !== slackIndex) y[e.j] += e.b * x[e.j];
continue;
}
const d = x[e.i] - x[e.j];
y[e.i] += e.b * d;
y[e.j] -= e.b * d;
}
return y;
}
function solve(model, injection, slackIndex, tolerance, maxIterations) {
const n = model.buses.length;
const x = new Float64Array(n);
let r = new Float64Array(injection);
r[slackIndex] = 0;
let p = new Float64Array(r);
let rr = 0;
for (let k = 0; k < n; k += 1) rr += r[k] * r[k];
const target = tolerance * tolerance * Math.max(rr, 1e-30);
let iterations = 0;
for (; iterations < maxIterations && rr > target; iterations += 1) {
const ap = multiply(model, p, slackIndex);
let pap = 0;
for (let k = 0; k < n; k += 1) pap += p[k] * ap[k];
if (!(Math.abs(pap) > 1e-30)) break;
const alpha = rr / pap;
let rrNext = 0;
for (let k = 0; k < n; k += 1) {
x[k] += alpha * p[k];
r[k] -= alpha * ap[k];
rrNext += r[k] * r[k];
}
const beta = rrNext / rr;
for (let k = 0; k < n; k += 1) p[k] = r[k] + beta * p[k];
rr = rrNext;
}
x[slackIndex] = 0;
return { theta: x, iterations, residual: Math.sqrt(rr) };
}
const SINK_RULE =
'Where no withdrawal bus is declared, the sink is the most connected '
+ 'bus in the SAME component as the injection - the bus with the most '
+ 'published branches landing on it. It is a stated rule, not a '
+ 'convenience: a transfer has two ends and the answer is meaningless '
+ 'without naming both. Declare a sink to override it.';
/**
* The withdrawal bus this model would choose, and why.
*
* Returns null when the injection bus has no one to transfer to, which
* is a real answer about an isolated bus and not a failure.
*/
function sinkFor(model, atNode) {
if (!model || typeof model.componentOf !== 'function') return null;
const atBus = model.busOf(atNode);
const component = model.componentOf(atBus);
let best = null;
let bestDegree = -1;
for (const bus of model.buses) {
if (bus === atBus) continue;
if (model.componentOf(bus) !== component) continue;
const d = model.degreeOf(bus);
if (d > bestDegree || (d === bestDegree && best !== null && bus < best)) {
best = bus;
bestDegree = d;
}
}
return best;
}
/**
* Inject `mw` at one node and withdraw it at the declared slack; report
* the flow this puts on every branch that carries a meaningful share.
*
* @param model from modelFor()
* @param options { atNode, slackNode, mw, minimumShare }
*/
function respond(model, options) {
const opts = options || {};
const mw = Number.isFinite(opts.mw) ? opts.mw : 100;
const atBus = model.busOf(opts.atNode);
const slackBus = model.busOf(opts.slackNode);
const i = model.busIndex.get(atBus);
const s = model.busIndex.get(slackBus);
if (i === undefined || s === undefined) return null;
if (i === s) {
return {
schema: SCHEMA,
declared_model: DECLARED_MODEL,
injected_mw: mw,
at_node: opts.atNode,
slack_node: opts.slackNode,
same_bus: true,
reason: 'the injection point and the slack are the same electrical '
+ 'bus once zero-reactance branches are shorted, so there is no '
+ 'transfer to distribute',
branches: [],
not_a_loading: NOT_A_LOADING,
not_a_connection_offer: NOT_A_CONNECTION_OFFER
};
}
/* A transfer between two components does not exist. The solver would
answer anyway - with a large number - so the refusal is here, before
it is asked. (Codex 202609020030, finding 1.) */
if (typeof model.componentOf === 'function'
&& model.componentOf(atBus) !== model.componentOf(slackBus)) {
return {
schema: SCHEMA,
declared_model: DECLARED_MODEL,
injected_mw: mw,
at_node: opts.atNode,
slack_node: opts.slackNode,
same_bus: false,
publishable: false,
reason: 'the injection bus and the withdrawal bus are in different '
+ 'connected components of the published network at this voltage, '
+ 'so there is no transfer between them to distribute. The model '
+ 'has ' + (model.counts ? model.counts.components : 'several')
+ ' components at this voltage; a transfer must be solved within one.',
branches: [],
component: {
injection: model.componentOf(atBus),
slack: model.componentOf(slackBus),
injection_component_buses: model.componentSize(atBus)
},
sink_rule: SINK_RULE,
not_a_loading: NOT_A_LOADING,
not_a_connection_offer: NOT_A_CONNECTION_OFFER
};
}
const n = model.buses.length;
const p = new Float64Array(n);
p[i] = mw / BASE_MVA; /* per unit on the declared base */
p[s] = -mw / BASE_MVA;
const solved = solve(model, p, s, 1e-10, Math.min(4 * n, 20000));
const minimumShare = Number.isFinite(opts.minimumShare) ? opts.minimumShare : 0.01;
const flows = [];
for (const e of model.edges) {
const flowPu = (solved.theta[e.i] - solved.theta[e.j]) * e.b;
const flowMw = flowPu * BASE_MVA;
const share = mw === 0 ? 0 : flowMw / mw;
if (Math.abs(share) < minimumShare) continue;
const row = e.meta.row;
const ratings = {};
for (const [season, field] of [['winter', 'winter_mva'], ['spring', 'spring_mva'],
['summer', 'summer_mva'], ['autumn', 'autumn_mva']]) {
if (Number.isFinite(row[field])) ratings[season] = row[field];
}
flows.push({
from_node: e.meta.from,
to_node: e.meta.to,
kind: e.meta.kind,
x_pct_100mva: e.meta.x_pu * 100,
flow_mw: flowMw,
share_of_injection: share,
published_ratings_mva: Object.keys(ratings).length ? ratings : null,
transformer_rating_mva: e.meta.kind === 'transformer'
&& Number.isFinite(row.rating_mva) ? row.rating_mva : null
});
}
flows.sort((a, b) => Math.abs(b.share_of_injection) - Math.abs(a.share_of_injection));
/* Validation carried in the answer, and GLOBAL.
--------------------------------------------------------------------
This checked Kirchhoff at the injection bus alone, which a
disconnected pair can satisfy while the solve has not converged at
all: a minimal A-B / C-D fixture injecting at A and withdrawing at D
returned validation.passes true with converged false. A page gated on
that could print an impossible transfer.
Now every bus is checked. Net flow must be the injection at the
injection bus, minus it at the slack, and zero everywhere else. */
const net = new Float64Array(model.buses.length);
for (const e of model.edges) {
const flowPu = (solved.theta[e.i] - solved.theta[e.j]) * e.b;
net[e.i] += flowPu;
net[e.j] -= flowPu;
}
const kirchhoff = net[i] * BASE_MVA / (mw || 1);
let worstBusError = 0;
let worstBus = null;
for (let k = 0; k < net.length; k += 1) {
const expected = k === i ? mw / BASE_MVA : (k === s ? -mw / BASE_MVA : 0);
const error = Math.abs(net[k] - expected);
if (error > worstBusError) { worstBusError = error; worstBus = model.buses[k]; }
}
const worstBusMw = worstBusError * BASE_MVA;
return {
schema: SCHEMA,
declared_model: DECLARED_MODEL,
injected_mw: mw,
at_node: opts.atNode,
slack_node: opts.slackNode,
same_bus: false,
branches: flows,
counts: {
branches_in_model: model.edges.length,
branches_carrying_at_least: minimumShare,
branches_reported: flows.length
},
convergence: {
iterations: solved.iterations,
residual: solved.residual,
converged: solved.residual < 1e-6
},
publishable: solved.residual < 1e-6 && worstBusMw < 1e-6 * Math.max(1, mw)
&& Math.abs(kirchhoff - 1) < 1e-6,
sink_rule: SINK_RULE,
component: {
solved_in: typeof model.componentOf === 'function' ? model.componentOf(atBus) : null,
buses_in_component: typeof model.componentSize === 'function' ? model.componentSize(atBus) : null
},
validation: {
kirchhoff_at_injection: kirchhoff,
kirchhoff_error: Math.abs(kirchhoff - 1),
worst_bus_error_mw: worstBusMw,
worst_bus: worstBus,
/* ALL THREE, not one. Convergence alone is not conservation, and
conservation at one bus is not conservation. */
passes: Math.abs(kirchhoff - 1) < 1e-6
&& worstBusMw < 1e-6 * Math.max(1, mw)
&& solved.residual < 1e-6,
/* Exact by Kirchhoff's current law under the DC model: everything
injected at a bus must leave it along the branches. It is
checked at runtime and carried in the answer rather than
asserted in a comment, because a solve that has not converged
produces a plausible-looking set of flows that are wrong. */
what_it_checks: 'the shares leaving the injection bus must sum to 1.0, '
+ 'AND net flow must be zero at every other bus, AND the solve '
+ 'must have converged. Any one of the three alone can hold while '
+ 'the answer is wrong.'
},
not_a_loading: NOT_A_LOADING,
not_a_connection_offer: NOT_A_CONNECTION_OFFER
};
}
/**
* Convenience: build a model over every node at one voltage.
*/
function modelFor(index, options) {
if (!index || typeof index.graph !== 'function') return null;
const graph = index.graph();
if (!graph || graph.schema !== REQUIRES) return null;
const opts = options || {};
const voltageKv = Number.isFinite(opts.voltageKv) ? opts.voltageKv : null;
const includeTransformers = opts.includeTransformers === true;
const names = [];
for (const name of (opts.nodeNames || [])) {
if (voltageKv == null || graph.nodeVoltageKv(name) === voltageKv) names.push(name);
}
if (!names.length) return null;
return assemble(graph, names, { voltageKv, includeTransformers });
}
NS.injectionResponse = Object.freeze({
schema: SCHEMA,
requires: REQUIRES,
base_mva: BASE_MVA,
declared_model: DECLARED_MODEL,
not_a_loading: NOT_A_LOADING,
not_a_connection_offer: NOT_A_CONNECTION_OFFER,
sink_rule: SINK_RULE,
modelFor,
assemble,
sinkFor,
respond
});
})();
/**
* Module: planned-change
*
* What the network operator has PUBLISHED as planned for the circuits and
* transformers that touch one site: additions, changes and removals, by
* the year they are published against.
*
* WHY THIS EXISTS
* ---------------
* Appendix B carries 2,230 rows that are not the network. They are the
* operator's statement of what the network is planned to look like in
* 2026, 2028, 2030 and 2033: a circuit to be added, a circuit whose
* parameters are to change, a transformer to be removed. The topology
* module carries them and the graph it hands out deliberately refuses to
* walk them, which is right - a circuit published for 2030 is not a path
* a current can take today. But refusing to walk them is not the same as
* reporting them, and a reader looking at a site with four published
* additions in 2028 is entitled to be told so, with the year and the
* status and the published parameters, in the operator's own words.
*
* So this module reports the planned rows that land at a site, grouped by
* year and then by status, with real counts. It reads the same product the
* topology module reads and resolves sites, nodes and voltages through the
* topology index rather than through a second opinion of its own.
*
* WHAT IT IS NOT
* --------------
* A published plan is not infrastructure. Every entry this module returns
* is marked as a publication about a future year, it is never mixed into
* a list of circuits that exist, and nothing here can be traversed: the
* module contains no path, no hop and no neighbour, and the graph it
* borrows excludes these rows from its edges by construction.
*
* A published plan is not a commitment either. The operator publishes
* planned changes as its current view of network development; the view
* moves between editions, an addition can be deferred or dropped, and a
* year against a row is the year the row is published for, not a
* consent, not a delivery date and not a date on which anything could
* connect. A "Removed" row says a circuit is planned to be taken out; it
* does not say why, and it does not say what replaces it.
*
* And, as everywhere in this estate: nothing here states whether a project
* can connect. R, X and B on a planned row are carried as published on a
* 100 MVA base and never computed with; ratings on a planned row are the
* planned circuit's, not a spare allowance; voltages are trusted only where
* the product says the site declares them and are never decoded from a
* node code.
*
* ONE PUBLISHED FACT THAT IS WORTH CARRYING
* -----------------------------------------
* 552 of the 2,230 planned rows sit on a node pair that already has a
* circuit or transformer published for today, and 16 of those are marked
* "Addition" - a second circuit on an existing pair, on the face of it.
* Whether a pair is published today is a fact from the same product, so
* each entry carries it. It is a cross-reference, not a judgement about
* what the addition means.
*
* node tools/proofs/modules/202609012345-planned-change.proof.mjs
*/
(() => {
'use strict';
const NS = window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {};
if (NS.plannedChange) return;
const SCHEMA = 'gridatlas.module.planned-change.v1';
const ACCEPTS = 'data-grid-gb.transmission-network.v1';
const REQUIRES = 'gridatlas.module.network-topology.graph.v1';
const NOT_EXISTING =
'Every entry here is a change the network operator has published for '
+ 'a future year. None of it is a circuit or a transformer that exists '
+ 'today, none of it is a path, and none of it is counted among the '
+ 'site\'s circuits anywhere in this estate.';
const NOT_A_COMMITMENT =
'A published plan is the operator\'s current view of network '
+ 'development, and the view moves between editions. It is not a '
+ 'commitment to build, not a consent, and the year on a row is the '
+ 'year it is published for - not a delivery date and not a date on '
+ 'which anything could connect.';
const NOT_AN_ASSESSMENT =
'Nothing here states whether any project can connect at this site, '
+ 'before or after a planned change. That depends on queue position, '
+ 'committed connections, consent and commercial terms which no '
+ 'published appendix contains. A rating on a planned row is the '
+ 'planned asset\'s rating, not a spare allowance.';
const IMPEDANCE_BASIS =
'R, X and B on a planned row are percentages on a 100 MVA base, as '
+ 'published for the planned asset. They are carried and not computed '
+ 'with.';
/* The order the statuses are presented in. Anything the product
publishes that is not one of these three is kept and sorted after
them by name, never dropped. */
const STATUS_ORDER = Object.freeze(['Addition', 'Change', 'Removed']);
const ASSETS = Object.freeze(['circuit', 'transformer']);
const asString = (v) => (typeof v === 'string' && v.length ? v : null);
const asNumber = (v) => (Number.isFinite(v) ? v : null);
function statusRank(status) {
const i = STATUS_ORDER.indexOf(status);
return i === -1 ? STATUS_ORDER.length : i;
}
/* Years are published as strings ("2026"). They are sorted numerically
where they parse and left in their published form on the entry. */
function yearRank(year) {
const n = Number(year);
return Number.isFinite(n) ? n : Number.POSITIVE_INFINITY;
}
/**
* Is there a circuit or a transformer published for TODAY between
* these two nodes? Read off the graph's edges, which are circuits and
* transformers only, so a planned row can never vouch for itself.
*/
function publishedToday(graph, nearNode, farNode) {
const today = { circuit: false, transformer: false };
for (const entry of graph.edgesAt(nearNode)) {
if (entry.row[entry.far] !== farNode) continue;
if (entry.kind === 'circuit') today.circuit = true;
if (entry.kind === 'transformer') today.transformer = true;
}
return today;
}
/**
* @param product the parsed data-grid-gb transmission-network payload
* @returns an index, or null if the schema is not the one this reads
*/
function index(product) {
if (!product || product.schema !== ACCEPTS) return null;
const topology = NS.networkTopology;
if (!topology || typeof topology.index !== 'function') return null;
const base = topology.index(product);
if (!base || typeof base.graph !== 'function') return null;
const graph = base.graph();
if (!graph || graph.schema !== REQUIRES) return null;
const rows = Array.isArray(product.planned_changes) ? product.planned_changes : [];
/* Planned rows land on their two nodes exactly as branches do in the
topology module, so that a site query is a lookup and not a scan. */
const byNode = new Map();
for (const row of rows) {
if (!row) continue;
for (const [near, far] of [['node_1', 'node_2'], ['node_2', 'node_1']]) {
const name = row[near];
if (!name) continue;
if (!byNode.has(name)) byNode.set(name, []);
byNode.get(name).push({ row, near, far });
}
}
/* Product-wide tallies. These are counts of published rows, each
counted once, and they are the only place in this module where a
row is counted without reference to a site. */
const tally = { by_year: {}, by_status: {}, by_asset: {} };
for (const row of rows) {
if (!row) continue;
const y = asString(row.year) || 'unstated';
const s = asString(row.status) || 'unstated';
const a = asString(row.asset) || 'unstated';
tally.by_year[y] = (tally.by_year[y] || 0) + 1;
tally.by_status[s] = (tally.by_status[s] || 0) + 1;
tally.by_asset[a] = (tally.by_asset[a] || 0) + 1;
}
function describe(landing, nearNode) {
const row = landing.row;
const farNode = row[landing.far];
const farSiteCode = graph.nodeSiteCode(farNode) || null;
const farSite = farSiteCode ? graph.siteByCode(farSiteCode) : null;
const nearSiteCode = graph.nodeSiteCode(nearNode) || null;
const asset = asString(row.asset);
const entry = {
publication: 'planned',
year: asString(row.year),