In this section
- Electrical Distance geodesy · ventus-grid-engine / sources/v9-extracts/electrical-distance.mjs lines 1–313
- Rating Envelope electrical · ventus-grid-engine / sources/v9-extracts/rating-envelope.mjs lines 1–173
Electrical Distance
A JavaScript module in the sources folder of Ventus Grid Engine that starts nodes (`startNodes`) (units: kV, MVA), covering transformers.
Set aside from the main view: 93% of its lines are the same as engine/electrical-distance.js (ventus-grid-engine), which stays. (near-copy-of, proposed by families.py). 93% of lines shared with Electrical Distance; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9346 to ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 engine/electrical-distance.js:1-315 85060a0846aa07b9877ecb10d8fccf79a04d76d3
- sha256 fe1ebddf254851aee280cf1b60f9c61ca465e57ee4460e262d998c16b8b511bf
- target sha256 b6b55e2207e29a7078f0ab9a1ee0575125a0252386907e93434b78aeead2c4a3
- group of 2 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
geodesyventus-grid-engine / sources/v9-extracts/electrical-distance.mjs · lines 1–313 of 313 · Not reached from any entry point (candidate for review) · pattern startNodes (shared by 10 files)
- What it does
- It lists and searches transformers. Defines 6 functions or classes, including crossing, describe, legality, startNodes, between. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain terms in the code: transformers.
- What it achieves
- It starts nodes (`startNodes`) and is built from the crossing step (`crossing`) and the describe step (`describe`). Extracted verbatim from `gridatlas/atlas/modules/202609012245-electrical-distance.js`. Its code works with 100 MVA.
- Why it matters
- No other file in the estate was found to import it.
- Application
- ventus-grid-engine · sources/v9-extracts · JavaScript module
- Uses
- none found
- Used by
- none found
- Produces
- NOT_A_DISTANCE, NOT_A_CAPACITY, IMPEDANCE_CARRIED, UNDECLARED, between, within, schema, requires
- Defines here
- crossing, describe, legality, startNodes, between, within
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 sources/v9-extracts/electrical-distance.mjs:1-313 · blob ed2eec2efc855800480ed9cc3136582a755d3f71 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: unknown · users: none · canonical: duplicate_candidate
/**
* Module: electrical-distance
*
* Extracted verbatim from
* gridatlas/atlas/modules/202609012245-electrical-distance.js.
*
* How far away a substation is, measured in the network operator's own
* published circuits rather than in kilometres. Breadth-first shortest
* path (in hop count, not km) over the graph produced by
* network-topology.mjs's index(product).graph(). No impedance summation:
* R, X, B are carried per-hop exactly as published and never combined.
*
* Depends on: a `network-topology` index exposing `.graph()` with schema
* 'gridatlas.module.network-topology.graph.v1', and `.site(key)`.
*
* CHANGED: source is an IIFE registering itself on
* `window.__GRIDATLAS_MODULES__.electricalDistance`. That wiring is
* removed; `between()` and `within()` are otherwise unchanged.
*/
const SCHEMA = 'gridatlas.module.electrical-distance.v1';
const REQUIRES = 'gridatlas.module.network-topology.graph.v1';
export const NOT_A_DISTANCE =
'Hops are published circuits between two sites, not a distance. A site '
+ 'one hop away may be a hundred kilometres away, and a site ten '
+ 'kilometres away may be on no shared circuit at all.';
export const NOT_A_CAPACITY =
'A path existing on the published network says nothing about whether '
+ 'anything can flow along it for a new project. Ratings are the '
+ 'circuit\'s, not a spare allowance, and queue position, committed '
+ 'connections, consent and commercial terms appear in no appendix.';
export const IMPEDANCE_CARRIED =
'R, X and B are reproduced on each hop exactly as published, on a '
+ '100 MVA base. They are not added, scaled or combined anywhere in '
+ 'this module. A sum of them would be the beginning of a load flow, '
+ 'which needs a declared model this data does not contain.';
export const UNDECLARED = 'undeclared';
/* A traversal must not invent a voltage, so the two ends of an edge are
compared only when BOTH are declared. */
function crossing(graph, nearNode, farNode) {
const near = graph.nodeVoltageKv(nearNode);
const far = graph.nodeVoltageKv(farNode);
return {
near_kv: near,
far_kv: far,
both_declared: near != null && far != null,
changes: near != null && far != null && near !== far
};
}
function describe(graph, entry, nearNode) {
const farNode = entry.row[entry.far];
const cross = crossing(graph, nearNode, farNode);
return {
kind: entry.kind,
from_node: nearNode,
to_node: farNode,
from_site_code: graph.nodeSiteCode(nearNode) || null,
to_site_code: graph.nodeSiteCode(farNode) || null,
from_voltage_kv: cross.near_kv,
to_voltage_kv: cross.far_kv,
voltage_changed: cross.changes,
voltage_ratio_kv: entry.kind === 'transformer'
&& typeof entry.row.voltage_ratio_kv === 'string'
? entry.row.voltage_ratio_kv : null,
ratings_mva: graph.ratingsOf(entry.row),
transformer_rating_mva: entry.kind === 'transformer'
&& Number.isFinite(entry.row.rating_mva) ? entry.row.rating_mva : null,
parameters_pct_100mva: graph.parametersOf(entry.row)
};
}
/**
* Is this edge legal to walk? A transformer is the only thing that may
* change voltage. A circuit that appears to change voltage is refused
* and reported rather than traversed.
*/
function legality(kind, cross) {
if (!cross.changes) return { legal: true, refusal: null };
if (kind === 'transformer') return { legal: true, refusal: null };
return {
legal: false,
refusal: 'a ' + kind + ' whose two ends carry different declared '
+ 'voltages (' + cross.near_kv + ' kV and ' + cross.far_kv + ' kV); '
+ 'only a transformer may change voltage, so this edge is not walked'
};
}
function startNodes(graph, site, voltageKv) {
const nodes = graph.nodesOfSite(site.code);
if (voltageKv == null) return nodes;
return nodes.filter((name) => graph.nodeVoltageKv(name) === voltageKv);
}
/**
* The shortest published path between two sites, in circuits.
* Breadth-first, so the first arrival is a fewest-hop path.
*
* @param index a network-topology index (must expose graph())
* @param fromKey site code or exact site name
* @param toKey site code or exact site name
* @param options { voltageKv, maxHops }
* @returns a result object, or null if either site is unknown
*/
export function between(index, fromKey, toKey, options) {
if (!index || typeof index.graph !== 'function') return null;
const graph = index.graph();
if (!graph || graph.schema !== REQUIRES) return null;
const from = index.site(fromKey);
const to = index.site(toKey);
if (!from || !to) return null;
const opts = options || {};
const voltageKv = Number.isFinite(opts.voltageKv) ? opts.voltageKv : null;
const maxHops = Number.isFinite(opts.maxHops) ? opts.maxHops : 6;
const targets = new Set(graph.nodesOfSite(to.code));
const origins = startNodes(graph, from, voltageKv);
const base = {
schema: SCHEMA,
from: { code: from.code, name: from.name },
to: { code: to.code, name: to.name },
requested_voltage_kv: voltageKv,
max_hops: maxHops,
not_a_distance: NOT_A_DISTANCE,
not_a_capacity: NOT_A_CAPACITY,
impedance_basis: IMPEDANCE_CARRIED
};
if (!origins.length) {
return Object.assign({}, base, {
reached: false,
reason: voltageKv == null
? 'the origin site publishes no nodes in this product'
: 'the origin site publishes no node at ' + voltageKv + ' kV',
hops: null, path: [], refusals: [], ties: 0, explored_nodes: 0
});
}
if (from.code === to.code) {
return Object.assign({}, base, {
reached: true, hops: 0, path: [], refusals: [], ties: 0,
explored_nodes: origins.length,
reason: 'the same site'
});
}
const seen = new Map();
const refusals = [];
let frontier = [];
for (const name of origins.slice().sort()) {
if (targets.has(name)) {
return Object.assign({}, base, {
reached: true, hops: 0, path: [], refusals: [], ties: 0,
explored_nodes: 1,
reason: 'both site codes resolve to the same node'
});
}
seen.set(name, null);
frontier.push(name);
}
for (let depth = 1; depth <= maxHops; depth += 1) {
const next = [];
const arrivals = [];
for (const nearNode of frontier) {
for (const entry of graph.edgesAt(nearNode)) {
const farNode = entry.row[entry.far];
if (!farNode || !graph.has(farNode)) continue;
const cross = crossing(graph, nearNode, farNode);
const verdict = legality(entry.kind, cross);
if (!verdict.legal) {
refusals.push({
at_node: nearNode, to_node: farNode,
kind: entry.kind, reason: verdict.refusal
});
continue;
}
if (seen.has(farNode)) continue;
seen.set(farNode, { via: entry, from: nearNode });
if (targets.has(farNode)) arrivals.push(farNode);
else next.push(farNode);
}
}
if (arrivals.length) {
arrivals.sort();
const path = [];
let cursor = arrivals[0];
while (cursor) {
const step = seen.get(cursor);
if (!step) break;
path.unshift(describe(graph, step.via, step.from));
cursor = step.from;
}
return Object.assign({}, base, {
reached: true,
hops: path.length,
path,
transformers_crossed: path.filter((h) => h.kind === 'transformer').length,
voltage_changes: path.filter((h) => h.voltage_changed).length,
ties: arrivals.length - 1,
refusals,
explored_nodes: seen.size,
arrival_node: arrivals[0]
});
}
if (!next.length) break;
frontier = next.sort();
}
return Object.assign({}, base, {
reached: false,
reason: 'no published path within ' + maxHops + ' hops'
+ (voltageKv == null ? '' : ' from a ' + voltageKv + ' kV node')
+ '; this is a statement about the published network, not about '
+ 'whether the two sites are connected in reality',
hops: null, path: [], refusals, ties: 0, explored_nodes: seen.size
});
}
/**
* Every site reachable within N hops, with the hop count at which it was
* first reached.
*
* @param index a network-topology index
* @param key site code or exact site name
* @param options { hops, voltageKv }
*/
export function within(index, key, options) {
if (!index || typeof index.graph !== 'function') return null;
const graph = index.graph();
if (!graph || graph.schema !== REQUIRES) return null;
const site = index.site(key);
if (!site) return null;
const opts = options || {};
const voltageKv = Number.isFinite(opts.voltageKv) ? opts.voltageKv : null;
const limit = Number.isFinite(opts.hops) ? opts.hops : 2;
const origins = startNodes(graph, site, voltageKv);
const seen = new Set(origins);
const bySite = new Map();
const refusals = [];
let frontier = origins.slice().sort();
for (let depth = 1; depth <= limit; depth += 1) {
const next = [];
for (const nearNode of frontier) {
for (const entry of graph.edgesAt(nearNode)) {
const farNode = entry.row[entry.far];
if (!farNode || !graph.has(farNode) || seen.has(farNode)) continue;
const cross = crossing(graph, nearNode, farNode);
const verdict = legality(entry.kind, cross);
if (!verdict.legal) {
refusals.push({ at_node: nearNode, to_node: farNode,
kind: entry.kind, reason: verdict.refusal });
continue;
}
seen.add(farNode);
next.push(farNode);
const code = graph.nodeSiteCode(farNode);
if (!code || String(code).toUpperCase() === String(site.code).toUpperCase()) continue;
if (bySite.has(code)) continue;
const far = graph.siteByCode(code);
bySite.set(code, {
code,
name: far ? far.name : null,
hops: depth,
first_node: farNode,
voltage_kv: cross.far_kv,
via: entry.kind
});
}
}
if (!next.length) break;
frontier = next.sort();
}
const sites = [...bySite.values()].sort((a, b) =>
a.hops - b.hops || String(a.code).localeCompare(String(b.code)));
return {
schema: SCHEMA,
site: { code: site.code, name: site.name },
requested_voltage_kv: voltageKv,
hop_limit: limit,
origin_nodes: origins.length,
sites,
counts: {
sites: sites.length,
by_hop: sites.reduce((acc, s) => {
acc[s.hops] = (acc[s.hops] || 0) + 1;
return acc;
}, {})
},
refusals,
not_a_distance: NOT_A_DISTANCE,
not_a_capacity: NOT_A_CAPACITY
};
}
export const schema = SCHEMA;
export const requires = REQUIRES;Rating Envelope
A JavaScript module in the sources folder of Ventus Grid Engine. It is built from the seasons of helper (`seasonsOf`) and the flags for helper (`flagsFor`).
electricalventus-grid-engine / sources/v9-extracts/rating-envelope.mjs · lines 1–173 of 173 · Not reached from any entry point (candidate for review) · pattern seasonsOf (shared by 10 files)
- What it does
- It lists and searches its content. Defines seasonsOf, flagsFor, at. Side effects: changes the web page (DOM).
- What it achieves
- Extracted verbatim from `gridatlas/atlas/modules/202609012250-rating-envelope.js`.
- Why it matters
- No other file in the estate was found to import it.
- Application
- ventus-grid-engine · sources/v9-extracts · JavaScript module
- Uses
- none found
- Used by
- none found
- Produces
- SEASONS, NEVER_SUMMED, NOT_A_CAPACITY, IMPLAUSIBLE_MVA, at, schema, requires
- Defines here
- seasonsOf, flagsFor, at
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 sources/v9-extracts/rating-envelope.mjs:1-173 · blob 10f26ce1962d54821efa9e6ed534ab7383fcdd6e · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: unknown · users: none · canonical: duplicate_candidate
/**
* Module: rating-envelope
*
* Extracted verbatim from
* gridatlas/atlas/modules/202609012250-rating-envelope.js.
*
* What the operator publishes a circuit can carry, season by season - and
* a structural refusal to add those numbers up. Per-circuit thermal
* ratings, never summed across a site, never averaged into a mean that no
* circuit is rated at; only the published lowest/highest across the
* circuits that qualify.
*
* Depends on: a `network-topology` index exposing `.graph()` with schema
* 'gridatlas.module.network-topology.graph.v1', and `.site(key)`.
*
* CHANGED: source is an IIFE registering itself on
* `window.__GRIDATLAS_MODULES__.ratingEnvelope`. That wiring is removed;
* `at()` and its helpers are otherwise unchanged.
*/
const SCHEMA = 'gridatlas.module.rating-envelope.v1';
const REQUIRES = 'gridatlas.module.network-topology.graph.v1';
export const SEASONS = Object.freeze(['winter', 'spring', 'summer', 'autumn']);
const FIELD = Object.freeze({
winter: 'winter_mva', spring: 'spring_mva',
summer: 'summer_mva', autumn: 'autumn_mva'
});
export const NEVER_SUMMED =
'These are per-circuit thermal ratings under stated seasonal '
+ 'conditions. They are not additive and they are not simultaneous: '
+ 'the sum of the circuits at a site is not a quantity that exists in '
+ 'the network, and this module contains no code that produces one.';
export const NOT_A_CAPACITY =
'A rating is what a circuit is rated to carry, not what is free on '
+ 'it. Existing flows, committed connections, queue position, outage '
+ 'conditions and commercial terms decide what a project could use, '
+ 'and no published appendix contains any of them.';
/* A rating that is obviously not a rating. 9999 on a one-kilometre span
with zero impedance is a placeholder, not a thermal limit; so is
69,275 on a hundred-metre cable. The test is deliberately narrow: a
value at or above this threshold is flagged and excluded from the
range, nothing else is second-guessed. */
export const IMPLAUSIBLE_MVA = 9999;
function seasonsOf(row) {
const published = {};
const absent = [];
for (const season of SEASONS) {
const value = row[FIELD[season]];
if (Number.isFinite(value)) published[season] = value;
else absent.push(season);
}
return { published, absent };
}
function flagsFor(published) {
const flags = [];
for (const [season, value] of Object.entries(published)) {
if (value >= IMPLAUSIBLE_MVA) {
flags.push({
season,
value,
reason: 'at or above ' + IMPLAUSIBLE_MVA + ' MVA, which has the '
+ 'shape of a placeholder rather than a thermal rating; it is '
+ 'reported and excluded from the range below'
});
}
}
return flags;
}
/**
* Every circuit landing at a site, at one voltage, with its own seasonal
* ratings. No total anywhere.
*
* @param index a network-topology index exposing graph()
* @param key site code or exact site name
* @param options { voltageKv }
*/
export function at(index, key, options) {
if (!index || typeof index.graph !== 'function') return null;
const graph = index.graph();
if (!graph || graph.schema !== REQUIRES) return null;
const site = index.site(key);
if (!site) return null;
const opts = options || {};
const voltageKv = Number.isFinite(opts.voltageKv) ? opts.voltageKv : null;
const nodes = graph.nodesOfSite(site.code)
.filter((name) => voltageKv == null || graph.nodeVoltageKv(name) === voltageKv);
const circuits = [];
const seen = new Set();
for (const nodeName of nodes) {
for (const entry of graph.edgesAt(nodeName)) {
if (entry.kind !== 'circuit') continue;
const far = entry.row[entry.far];
const id = [nodeName, far].sort().join('|');
if (seen.has(id)) continue;
seen.add(id);
const { published, absent } = seasonsOf(entry.row);
if (!Object.keys(published).length) continue;
circuits.push({
from_node: nodeName,
to_node: far,
to_site_code: graph.nodeSiteCode(far) || null,
voltage_kv: graph.nodeVoltageKv(nodeName),
circuit_type: typeof entry.row.circuit_type === 'string' ? entry.row.circuit_type : null,
ohl_km: Number.isFinite(entry.row.ohl_km) ? entry.row.ohl_km : null,
cable_km: Number.isFinite(entry.row.cable_km) ? entry.row.cable_km : null,
ratings_mva: published,
seasons_not_published: absent,
flags: flagsFor(published),
parameters_pct_100mva: graph.parametersOf(entry.row)
});
}
}
circuits.sort((a, b) => String(a.to_node).localeCompare(String(b.to_node)));
/* The per-season RANGE across circuits - a lowest and a highest rating,
which are two real published values - never a sum, and never a
mean, which would be a number no circuit is rated at. */
const by_season = {};
for (const season of SEASONS) {
const values = circuits
.filter((c) => Number.isFinite(c.ratings_mva[season])
&& c.ratings_mva[season] < IMPLAUSIBLE_MVA)
.map((c) => c.ratings_mva[season]);
const excluded = circuits
.filter((c) => Number.isFinite(c.ratings_mva[season])
&& c.ratings_mva[season] >= IMPLAUSIBLE_MVA).length;
by_season[season] = values.length
? {
lowest_circuit_mva: Math.min.apply(null, values),
highest_circuit_mva: Math.max.apply(null, values),
circuits: values.length,
excluded_as_implausible: excluded
}
: { circuits: 0, excluded_as_implausible: excluded, published: false };
}
const flagged = circuits.filter((c) => c.flags.length);
const missingSeasons = circuits.filter((c) => c.seasons_not_published.length);
return {
schema: SCHEMA,
site: { code: site.code, name: site.name },
requested_voltage_kv: voltageKv,
scope: voltageKv == null
? 'every voltage at this site; a range across two busbar voltages '
+ 'is a number about neither of them'
: voltageKv + ' kV nodes at this site only',
circuits,
by_season,
counts: {
circuits: circuits.length,
with_a_flagged_value: flagged.length,
with_a_season_not_published: missingSeasons.length
},
never_summed: NEVER_SUMMED,
not_a_capacity: NOT_A_CAPACITY
};
}
export const schema = SCHEMA;
export const requires = REQUIRES;