GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Solar and storage design / solar-electrical-topology-analysis-engine-text-based / v8-leapfrog

Model and 2 more files

A JavaScript module in Solar Electrical Topology Analysis Engine Text Based that parses bands (`parseBands`), builds strings (`buildStrings`) and sums strings (`sumStrings`). Served with the page at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/.

700 lines of JavaScript and HTML from solar-electrical-topology-analysis-engine-text-based, in 3 files. Topic: Solar and storage design. Section 252 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog Page render · solar-electrical-topology-analysis-engine-text-based / v8-leapfrog/index.html lines 701–722
  2. Inverter24 render · solar-electrical-topology-analysis-engine-text-based / v8-leapfrog/inverter24.html lines 1–191
  3. Model electrical · solar-electrical-topology-analysis-engine-text-based / v8-leapfrog/model.js lines 1–487

Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog Page

A web page that draws SVG graphics and reads inputs for modules per, module width and along row gap (units: mm², Ω). Published at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/.

rendersolar-electrical-topology-analysis-engine-text-based / v8-leapfrog/index.html · lines 701–722 of 722 (continued from section 251) · Entry point

What it does
It draws cables. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage sub33kv_design (repository name word 'solar'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables.
Inputs & outputs
In: form fields (user input). Out: web page; SVG drawing.
Downstream impact
Used directly by 42 files: Geometry Workbench (solar-electrical-topology-analysis-engine-text-based, https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v10-development/geometry-workbench.html); Inverter24 (solar-electrical-topology-analysis-engine-text-based, https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/inverter24.html); Tests (solar-electrical-topology-analysis-engine-text-based, https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/tests.html); GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); and 38 more. Reached from 85 other entry points, including GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); Homepage V037 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v037.html); Homepage V038 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v038.html). It is itself an entry point, published at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/.
What it achieves
V8 field-installed external-cable comparison with Build 025 total-conductor reconciliation.
Why it matters
Loaded by the Geometry Workbench page at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v10-development/geometry-workbench.html and 40 other pages. Checked by Tests.
Application
solar-electrical-topology-analysis-engine-text-based · v8-leapfrog · page
Uses
Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog Style Sheet (stylesheet), Solar Electrical Topology Analysis Engine Text Based — Index Page (link), V7 Development — Feed I Page (link), Tests (link), Model (script src), Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog (script src), Authority Reconciliation (script src)
Used by
linked from Geometry Workbench (link), linked from Inverter24 (link), linked from Tests (link), named by URL in GlobalGrid2050 Historical Builds (estate URL), named by URL in Homepage Versions — GlobalGrid2050 Page (estate URL), named by URL in Homepage V002 (estate URL), named by URL in Homepage V003 (estate URL), named by URL in Homepage V004 (estate URL), and 34 more
Produces
none declared
Defines here
none
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 v8-leapfrog/index.html:701-722 · blob 95a7fff4463e5a376852c3f64b5524d2d4817f1e · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
              style="width:100%;margin-top:12px;background:#03070b;
              color:#d7ecff;border:1px solid #263747;padding:10px;
              font:12px/1.55 ui-monospace,monospace"
            ></textarea>
          </div>
        </section>
      </div>
    </section>
  </main>

  <footer class="footer">
    V8.2 is a historical/reference field-installed external-cable model.
    It remains reproducible but is not the canonical total-conductor or
    electromagnetic authority. Build 025/V10 provides the current complete
    routing and receipt reconciliation.
  </footer>

  <script src="./model.js"></script>
  <script src="./app.js"></script>
  <script src="./authority-reconciliation.js"></script>
</body>
</html>

Inverter24

A web page in Solar Electrical Topology Analysis Engine Text Based that adds path (`addPath`), updates readout (`updateReadout`), applies view (`applyView`) and draws SVG graphics, covering cables. Published at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/inverter24.html.

rendersolar-electrical-topology-analysis-engine-text-based / v8-leapfrog/inverter24.html · lines 1–191 of 191 · Entry point · pattern applyView (shared by 2 files)

What it does
It draws cables. Defines 12 functions or classes, including el, sequence, moduleX, terminal, addPath. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage sub33kv_design (repository name word 'solar'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables.
Inputs & outputs
Out: web page; SVG drawing.
Downstream impact
It is itself an entry point, published at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/inverter24.html.
What it achieves
It adds path (`addPath`), updates readout (`updateReadout`) and applies view (`applyView`). V8 geometry-faithful 24-string inverter topology drawing with deterministic terminal coordinates and no invented cable routes. It responds to click, pointerdown and pointermove events.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
solar-electrical-topology-analysis-engine-text-based · v8-leapfrog · page
Uses
Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog Style Sheet (stylesheet), Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog Page (link), Solar Electrical Topology Analysis Engine Text Based — V10 Development Page (link), Progress Dashboard (link)
Used by
none found
Produces
el, sequence, moduleX, terminal, addPath, stringFace, inputLabel, rowColour, draw, updateReadout, applyView, fit
Defines here
el, sequence, moduleX, terminal, addPath, stringFace, inputLabel, rowColour, draw, updateReadout, applyView, fit
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 v8-leapfrog/inverter24.html:1-191 · blob b44bd75732a0b4169b450d9a25b23d170ebae82b · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>V8 Leapfrog · 24-String Inverter Cartridge</title>
  <meta name="description" content="V8 geometry-faithful 24-string inverter topology drawing with deterministic terminal coordinates and no invented cable routes.">
  <link rel="stylesheet" href="./styles.css">
  <style>
    body{overflow:auto}.layout{grid-template-columns:minmax(0,1fr)}.workbench{min-width:0}.toolbar{display:flex;gap:10px;flex-wrap:wrap;padding:14px 0}.toolbar button,.toolbar a{width:auto}.toolbar button.active{background:#0ca6c8;color:#031018;border-color:#58dcff}.diagram-shell{position:relative;overflow:hidden;border:1px solid #29445a;background:#03070b;min-height:72vh}.diagram-shell svg{displa  … [line shortened here: 1,109 characters; full line on GitHub]
  </style>
</head>
<body>
<header class="topbar">
  <div>
    <div class="kicker">GLOBALGRID2050 · OPEN ELECTRICAL ENGINEERING · V8 CARTRIDGE</div>
    <h1>24-String Inverter Geometry</h1>
    <p>Exactly the V8 visual language, extended to twenty-four complete strings. Every module, terminal, series link and inverter home-run is generated from deterministic coordinates. No decorative or invented cable routing.</p>
    <div class="navlinks">
      <a href="./">V8 comparison</a>
      <a href="../v10-development/">V10 workbench</a>
      <a href="../progress-dashboard.html">Progress dashboard</a>
    </div>
  </div>
  <div class="status-stack">
    <div class="status-badge">24 STRINGS · 12 MPPT · 2 INPUTS</div>
    <div class="status-badge testing">GEOMETRY-DERIVED DRAWING</div>
    <div class="status-badge error">SCREENING · NOT AS-BUILT</div>
  </div>
</header>
<div class="reliance"><strong>DRAWING AUTHORITY</strong>Physical module positions remain fixed. Sequential and leapfrog change electrical connection order only. External conductors run only between declared string free terminals and declared inverter input terminals.</div>
<main class="layout">
  <section class="workbench">
    <section class="section">
      <h2>Complete inverter cartridge</h2>
      <div class="section-body">
        <div class="toolbar">
          <button id="leapfrogBtn" class="active">Leapfrog</button>
          <button id="sequentialBtn">Sequential</button>
          <button id="eastBtn" class="active">East face</button>
          <button id="westBtn" class="active">West face</button>
          <a class="button" href="./">Return to V8</a>
        </div>
        <div class="legend24">
          <span style="--swatch:#ffb84d">inverter / selected string</span>
          <span style="--swatch:#5fdcff">east strings</span>
          <span style="--swatch:#b88cff">west strings</span>
          <span style="--swatch:#d8e3ea">series connections</span>
        </div>
      </div>
      <div class="diagram-shell" id="shell">
        <div class="floating-tools">
          <button id="zoomOut">−</button><button id="fit">FIT</button><button id="zoomIn">+</button><span id="zoomLabel" style="padding:7px 6px;font-family:ui-monospace,monospace;color:#5fdcff">100%</span>
        </div>
        <svg id="diagram" role="img" aria-label="Twenty-four PV strings connected to twelve MPPT inputs"></svg>
      </div>
      <div id="readout" class="string-readout">Select a string to inspect its deterministic electrical order and inverter input.</div>
    </section>
  </section>
</main>
<script>
(() => {
  'use strict';
  const NS='http://www.w3.org/2000/svg';
  const svg=document.getElementById('diagram');
  const shell=document.getElementById('shell');
  const readout=document.getElementById('readout');
  let topology='leapfrog';
  let showEast=true,showWest=true;
  let selected=1;
  let view={x:0,y:0,k:1};
  let drag=null;

  const config={strings:24,modules:30,moduleW:22,moduleH:28,moduleGap:3,rowGap:44,inverterX:42,rowX:270,top:92};
  const totalRowW=config.modules*(config.moduleW+config.moduleGap)-config.moduleGap;
  const worldW=config.rowX+totalRowW+90;
  const worldH=config.top+(config.strings-1)*config.rowGap+120;

  function el(name,attrs={},text=''){
    const node=document.createElementNS(NS,name);
    Object.entries(attrs).forEach(([k,v])=>node.setAttribute(k,String(v)));
    if(text)node.textContent=text;
    return node;
  }
  function sequence(n,mode){
    if(mode==='sequential')return Array.from({length:n},(_,i)=>i+1);
    const out=[];
    for(let i=1;i<=n;i+=2)out.push(i);
    for(let i=n%2===0?n:n-1;i>=2;i-=2)out.push(i);
    return out;
  }
  function moduleX(number){return config.rowX+(number-1)*(config.moduleW+config.moduleGap)}
  function terminal(number,polarity,y){
    const x=moduleX(number);
    return {x:x+(polarity==='-'?7:config.moduleW-7),y:y+10};
  }
  function addPath(group,d,stroke,width=1.6,extra={}){
    group.appendChild(el('path',{d,fill:'none',stroke:'#03070b','stroke-width':width+3,'stroke-linecap':'round','stroke-linejoin':'round',...extra}));
    group.appendChild(el('path',{d,fill:'none',stroke,'stroke-width':width,'stroke-linecap':'round','stroke-linejoin':'round',...extra}));
  }
  function stringFace(index){return index<=12?'east':'west'}
  function inputLabel(index){return `MPPT ${Math.ceil(index/2)} · input ${index%2?1:2}`}
  function rowColour(index){return stringFace(index)==='east'?'#5fdcff':'#b88cff'}

  function draw(){
    svg.innerHTML='';
    svg.setAttribute('viewBox',`0 0 ${worldW} ${worldH}`);
    svg.setAttribute('width',worldW);
    svg.setAttribute('height',worldH);
    svg.style.width=worldW+'px';
    svg.style.height=worldH+'px';
    svg.style.transformOrigin='0 0';

    const root=el('g');svg.appendChild(root);
    root.appendChild(el('text',{x:34,y:38,fill:'#dce8f1','font-size':22,'font-family':'ui-monospace,monospace'},'INVERTER INPUTS'));
    root.appendChild(el('rect',{x:38,y:62,width:92,height:worldH-112,rx:5,fill:'#ffb84d',stroke:'#ffe0a8','stroke-width':2}));

    for(let s=1;s<=config.strings;s++){
      const face=stringFace(s);
      if((face==='east'&&!showEast)||(face==='west'&&!showWest))continue;
      const y=config.top+(s-1)*config.rowGap;
      const colour=rowColour(s);
      const highlight=s===selected;
      const g=el('g',{'data-string':s,style:'cursor:pointer'});
      root.appendChild(g);

      const negY=y+7,posY=y+25;
      g.appendChild(el('line',{x1:128,y1:negY,x2:config.rowX-8,y2:negY,stroke:'#d8e3ea','stroke-width':highlight?3:1.3}));
      g.appendChild(el('line',{x1:128,y1:posY,x2:config.rowX-8,y2:posY,stroke:'#d8e3ea','stroke-width':highlight?3:1.3}));
      g.appendChild(el('line',{x1:112,y1:negY,x2:128,y2:negY,stroke:'#192632','stroke-width':3}));
      g.appendChild(el('line',{x1:112,y1:posY,x2:128,y2:posY,stroke:'#192632','stroke-width':3}));
      g.appendChild(el('text',{x:142,y:y+13,fill:highlight?'#ffcf7b':colour,'font-size':11,'font-family':'ui-monospace,monospace'},`${s}−`));
      g.appendChild(el('text',{x:142,y:y+31,fill:highlight?'#ffcf7b':colour,'font-size':11,'font-family':'ui-monospace,monospace'},`${s}+`));

      for(let m=1;m<=config.modules;m++){
        const x=moduleX(m);
        g.appendChild(el('rect',{x,y,width:config.moduleW,height:config.moduleH,fill:highlight?'#61451d':face==='east'?'#123d4d':'#34254d',stroke:highlight?'#ffb84d':colour,'stroke-width':highlight?2:1}));
      }

      const seq=sequence(config.modules,topology);
      for(let i=0;i<seq.length-1;i++){
        const from=terminal(seq[i],'+',y),to=terminal(seq[i+1],'-',y);
        const outward=topology==='sequential'||(seq[i]%2===1&&seq[i+1]%2===1);
        const lane=y+(outward?-10:38);
        const d=`M ${from.x} ${from.y} C ${from.x} ${lane}, ${to.x} ${lane}, ${to.x} ${to.y}`;
        addPath(g,d,highlight?'#ffb84d':'#d8e3ea',highlight?2.6:1.35);
      }

      const freeNeg=terminal(seq[0],'-',y);
      const freePos=terminal(seq[seq.length-1],'+',y);
      const negPath=`M ${freeNeg.x} ${freeNeg.y} L ${config.rowX-18} ${negY} L 128 ${negY}`;
      const posLane=topology==='sequential'?y+34:posY;
      const posPath=`M ${freePos.x} ${freePos.y} L ${freePos.x} ${posLane} L ${config.rowX-18} ${posLane} L ${config.rowX-18} ${posY} L 128 ${posY}`;
      addPath(g,negPath,highlight?'#ffb84d':'#d8e3ea',highlight?2.8:1.5);
      addPath(g,posPath,highlight?'#ffb84d':'#d8e3ea',highlight?2.8:1.5);
      g.addEventListener('click',()=>{selected=s;draw();updateReadout();});
    }

    root.appendChild(el('text',{x:42,y:worldH-20,fill:'#9db2c3','font-size':14,'font-family':'ui-monospace,monospace'},`${topology.toUpperCase()} · 24 strings · 12 MPPT · deterministic terminal coordinates`));
    applyView();
  }

  function updateReadout(){
    const seq=sequence(config.modules,topology);
    readout.innerHTML=`<strong>String ${selected}</strong> · ${stringFace(selected).toUpperCase()} · ${inputLabel(selected)} · ${topology.toUpperCase()}<br>Electrical order: ${seq.map(n=>'M'+n).join(' → ')}<br>Free terminals: M${seq[0]}− and M${seq[seq.length-1]}+. External conductors terminate only at the declared inverter input pair.`;
  }
  function applyView(){
    svg.style.transform=`translate(${view.x}px,${view.y}px) scale(${view.k})`;
    document.getElementById('zoomLabel').textContent=Math.round(view.k*100)+'%';
  }
  function fit(){
    const sx=shell.clientWidth/worldW,sy=shell.clientHeight/worldH;
    view.k=Math.min(sx,sy)*.96;view.x=(shell.clientWidth-worldW*view.k)/2;view.y=8;applyView();
  }
  document.getElementById('zoomIn').onclick=()=>{view.k=Math.min(3,view.k*1.2);applyView()};
  document.getElementById('zoomOut').onclick=()=>{view.k=Math.max(.25,view.k/1.2);applyView()};
  document.getElementById('fit').onclick=fit;
  document.getElementById('leapfrogBtn').onclick=()=>{topology='leapfrog';document.getElementById('leapfrogBtn').classList.add('active');document.getElementById('sequentialBtn').classList.remove('active');draw();updateReadout()};
  document.getElementById('sequentialBtn').onclick=()=>{topology='sequential';document.getElementById('sequentialBtn').classList.add('active');document.getElementById('leapfrogBtn').classList.remove('active');draw();updateReadout()};
  document.getElementById('eastBtn').onclick=()=>{showEast=!showEast;document.getElementById('eastBtn').classList.toggle('active',showEast);draw()};
  document.getElementById('westBtn').onclick=()=>{showWest=!showWest;document.getElementById('westBtn').classList.toggle('active',showWest);draw()};
  shell.addEventListener('pointerdown',e=>{drag={x:e.clientX,y:e.clientY,vx:view.x,vy:view.y};shell.setPointerCapture(e.pointerId)});
  shell.addEventListener('pointermove',e=>{if(!drag)return;view.x=drag.vx+e.clientX-drag.x;view.y=drag.vy+e.clientY-drag.y;applyView()});
  shell.addEventListener('pointerup',()=>drag=null);
  shell.addEventListener('wheel',e=>{e.preventDefault();view.k=Math.max(.25,Math.min(3,view.k*(e.deltaY<0?1.1:.9)));applyView()},{passive:false});
  window.addEventListener('resize',fit);
  draw();updateReadout();requestAnimationFrame(fit);
})();
</script>
</body>
</html>

Model

A JavaScript module in Solar Electrical Topology Analysis Engine Text Based that parses bands (`parseBands`), builds strings (`buildStrings`) and sums strings (`sumStrings`). Served with the page at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/.

electricalsolar-electrical-topology-analysis-engine-text-based / v8-leapfrog/model.js · lines 1–487 of 749 · Entry point · pattern runGoldenTests (shared by 2 files)

What it does
It calculates its inputs. Defines 18 functions or classes, including buildModel, asNumber, atLeast, parseNumberList, parseBands.
Why it exists in the grid workflow
Domain stage sub33kv_design (repository name word 'solar'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
Downstream impact
Used directly by 4 files: V8 Model Test (solar-electrical-topology-analysis-engine-text-based); Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog Page (solar-electrical-topology-analysis-engine-text-based, https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/); Tests (solar-electrical-topology-analysis-engine-text-based, https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/tests.html); V8 Tests Workflow (solar-electrical-topology-analysis-engine-text-based). Reached from 135 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); Homepage V002 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v002.html). It is itself an entry point, published at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/.
What it achieves
It parses number list (`parseNumberList`), parses bands (`parseBands`) and builds strings (`buildStrings`). Defines `buildModel`, `asNumber`, `atLeast` and 15 more.
Why it matters
Loaded by the V8 Leapfrog page at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/. Checked by 3 tests, including V8 Model Test.
Application
solar-electrical-topology-analysis-engine-text-based · v8-leapfrog · JavaScript module
Uses
none found
Used by
required by V8 Model Test (require), loaded by Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog Page (script src), loaded by Tests (script src), run by V8 Tests Workflow (workflow run)
Produces
buildModel, asNumber, atLeast, parseNumberList, parseBands, normalise, modulePitchM, rowSpanM, cableResistancePerM, sequentialPolarities, leadFeasibility, buildStrings
Defines here
buildModel, asNumber, atLeast, parseNumberList, parseBands, normalise, modulePitchM, rowSpanM, cableResistancePerM, sequentialPolarities, leadFeasibility, buildStrings, sumStrings, calculate
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 v8-leapfrog/model.js:1-487 · blob 93b9745e2be06d90f3a285e19173ee280f3c1390 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
(function attachModel(root, factory) {
  'use strict';

  const api = factory();

  if (typeof module === 'object' && module.exports) {
    module.exports = api;
  }

  if (root) {
    root.V8LeapfrogModel = api;
  }
})(
  typeof window !== 'undefined' ? window : globalThis,
  function buildModel() {
    'use strict';

    const VERSION = '8.2.0';
    const COPPER_ALPHA_20 = 0.00393;

    const DEFAULTS = Object.freeze({
      modulesPerString: 30,
      moduleWidthM: 1.303,
      alongRowGapM: 0.020,
      bandGapM: 0.500,
      eastBands: [5, 5, 2],
      westBands: [5, 5, 2],
      inverterDistanceM: 10,
      scenarioDistancesM: [10, 20, 30],
      polarityConvention: 'mirrored',
      cableR20MilliOhmPerM: 3.39,
      cableTemperatureC: 70,
      stringCurrentA: 17.35,
      moduleVmpV: 38.1,
      inverterCount: 795,
      totalSiteStringCount: 18_918,
      installedCableRatePerM: 0,
      positiveFactoryLeadM: 0.350,
      negativeFactoryLeadM: 0.280,
      measuredLeapfrogSpanM: 0,
      leadEvidence: 'MANUFACTURER_STANDARD_NOT_AS_BUILT'
    });

    function asNumber(value, fallback) {
      const parsed = Number(value);
      return Number.isFinite(parsed) ? parsed : fallback;
    }

    function atLeast(value, minimum, fallback) {
      return Math.max(minimum, asNumber(value, fallback));
    }

    function parseNumberList(value, fallback) {
      const source = Array.isArray(value)
        ? value
        : String(value ?? '').split(',');

      const values = source
        .map((item) => Number(String(item).trim()))
        .filter((item) => Number.isFinite(item) && item >= 0);

      return values.length ? values : fallback.slice();
    }

    function parseBands(value, fallback) {
      return parseNumberList(value, fallback)
        .map((item) => Math.max(0, Math.round(item)))
        .filter((item) => item > 0);
    }

    function normalise(raw = {}) {
      return {
        modulesPerString: Math.max(
          1,
          Math.round(
            asNumber(
              raw.modulesPerString,
              DEFAULTS.modulesPerString
            )
          )
        ),
        moduleWidthM: atLeast(
          raw.moduleWidthM,
          0.001,
          DEFAULTS.moduleWidthM
        ),
        alongRowGapM: atLeast(
          raw.alongRowGapM,
          0,
          DEFAULTS.alongRowGapM
        ),
        bandGapM: atLeast(
          raw.bandGapM,
          0,
          DEFAULTS.bandGapM
        ),
        eastBands: parseBands(
          raw.eastBands,
          DEFAULTS.eastBands
        ),
        westBands: parseBands(
          raw.westBands,
          DEFAULTS.westBands
        ),
        inverterDistanceM: atLeast(
          raw.inverterDistanceM,
          0,
          DEFAULTS.inverterDistanceM
        ),
        scenarioDistancesM: parseNumberList(
          raw.scenarioDistancesM,
          DEFAULTS.scenarioDistancesM
        ),
        polarityConvention:
          raw.polarityConvention === 'positive_near_both'
            ? 'positive_near_both'
            : 'mirrored',
        cableR20MilliOhmPerM: atLeast(
          raw.cableR20MilliOhmPerM,
          0,
          DEFAULTS.cableR20MilliOhmPerM
        ),
        cableTemperatureC: asNumber(
          raw.cableTemperatureC,
          DEFAULTS.cableTemperatureC
        ),
        stringCurrentA: atLeast(
          raw.stringCurrentA,
          0,
          DEFAULTS.stringCurrentA
        ),
        moduleVmpV: atLeast(
          raw.moduleVmpV,
          0.001,
          DEFAULTS.moduleVmpV
        ),
        inverterCount: Math.max(
          1,
          Math.round(
            asNumber(raw.inverterCount, DEFAULTS.inverterCount)
          )
        ),
        totalSiteStringCount: Math.max(
          1,
          Math.round(
            asNumber(
              raw.totalSiteStringCount,
              DEFAULTS.totalSiteStringCount
            )
          )
        ),
        installedCableRatePerM: atLeast(
          raw.installedCableRatePerM,
          0,
          DEFAULTS.installedCableRatePerM
        ),
        positiveFactoryLeadM: atLeast(
          raw.positiveFactoryLeadM,
          0,
          DEFAULTS.positiveFactoryLeadM
        ),
        negativeFactoryLeadM: atLeast(
          raw.negativeFactoryLeadM,
          0,
          DEFAULTS.negativeFactoryLeadM
        ),
        measuredLeapfrogSpanM: atLeast(
          raw.measuredLeapfrogSpanM,
          0,
          DEFAULTS.measuredLeapfrogSpanM
        ),
        leadEvidence: String(
          raw.leadEvidence || DEFAULTS.leadEvidence
        )
      };
    }

    function modulePitchM(input) {
      return input.moduleWidthM + input.alongRowGapM;
    }

    function rowSpanM(input) {
      return (
        input.modulesPerString * input.moduleWidthM +
        Math.max(0, input.modulesPerString - 1) *
          input.alongRowGapM
      );
    }

    function cableResistancePerM(input) {
      const r20 = input.cableR20MilliOhmPerM / 1000;
      const temperatureFactor =
        1 + COPPER_ALPHA_20 * (input.cableTemperatureC - 20);

      return r20 * temperatureFactor;
    }

    function sequentialPolarities(
      face,
      nearRouteM,
      farRouteM,
      convention
    ) {
      if (convention === 'mirrored' && face === 'W') {
        return {
          positiveM: farRouteM,
          negativeM: nearRouteM
        };
      }

      return {
        positiveM: nearRouteM,
        negativeM: farRouteM
      };
    }

    function leadFeasibility(raw = {}) {
      const input = normalise(raw);
      const geometricReachM = 2 * modulePitchM(input);
      const measuredOverride = input.measuredLeapfrogSpanM > 0;
      const requiredReachM = measuredOverride
        ? input.measuredLeapfrogSpanM
        : geometricReachM;
      const availableLeadReachM =
        input.positiveFactoryLeadM +
        input.negativeFactoryLeadM;
      const marginM = availableLeadReachM - requiredReachM;
      const feasible = marginM >= 0;
      const extensionRequiredM = Math.max(0, -marginM);

      return {
        status: feasible
          ? 'FEASIBLE_LENGTH_SCREEN'
          : 'INFEASIBLE_LENGTH_SCREEN',
        feasible,
        basis: measuredOverride
          ? 'MEASURED_ROUTED_SPAN'
          : 'TWO_MODULE_PITCH_SCREEN',
        geometricReachM,
        requiredReachM,
        availableLeadReachM,
        marginM,
        extensionRequiredM,
        evidence: input.leadEvidence,
        message: feasible
          ? (
              'Factory leads pass the length screen. ' +
              'Bend radius, connector orientation, support and slack ' +
              'still require verification.'
            )
          : (
              'Factory leads fail the length screen. ' +
              `Shortfall: ${extensionRequiredM.toFixed(3)} m. ` +
              'Any extension would add connector interfaces and must ' +
              'be engineered separately.'
            )
      };
    }

    function buildStrings(raw = {}, distanceOverrideM) {
      const input = normalise(raw);
      const rowM = rowSpanM(input);
      const bandPitchM = rowM + input.bandGapM;
      const distanceM = distanceOverrideM == null
        ? input.inverterDistanceM
        : Math.max(
            0,
            asNumber(
              distanceOverrideM,
              input.inverterDistanceM
            )
          );
      const rPerM = cableResistancePerM(input);
      const lead = leadFeasibility(input);
      const strings = [];
      const faces = [
        {
          face: 'E',
          bands: input.eastBands
        },
        {
          face: 'W',
          bands: input.westBands
        }
      ];
      let number = 1;

      for (const definition of faces) {
        definition.bands.forEach((count, bandIndex) => {
          const bandOffsetM = bandIndex * bandPitchM;
          const nearRouteM = distanceM + bandOffsetM;
          const farRouteM = nearRouteM + rowM;
          const sequential = sequentialPolarities(
            definition.face,
            nearRouteM,
            farRouteM,
            input.polarityConvention
          );

          for (let rank = 1; rank <= count; rank += 1) {
            const resistanceSavingOhm = rowM * rPerM;
            const voltageDropSavingV =
              input.stringCurrentA * resistanceSavingOhm;
            const stringVmpV =
              input.modulesPerString * input.moduleVmpV;
            const powerLossSavingW =
              input.stringCurrentA *
              input.stringCurrentA *
              resistanceSavingOhm;

            strings.push({
              number,
              stringId:
                `${definition.face}${bandIndex + 1}-` +
                String(rank).padStart(2, '0'),
              positiveId: `${number}+`,
              negativeId: `${number}−`,
              face: definition.face,
              band: bandIndex + 1,
              rank,
              bandOffsetM,
              inverterDistanceM: distanceM,
              nearRouteM,
              farRouteM,
              rowSpanM: rowM,
              basePairM: 2 * nearRouteM,
              sequential: {
                positiveM: sequential.positiveM,
                negativeM: sequential.negativeM,
                totalExternalM:
                  sequential.positiveM +
                  sequential.negativeM,
                additionalRowReturnM: rowM
              },
              leapfrog: {
                positiveM: nearRouteM,
                negativeM: nearRouteM,
                totalExternalM: 2 * nearRouteM,
                additionalRowReturnM: 0,
                feasible: lead.feasible
              },
              saving: {
                theoreticalExternalCableM: rowM,
                availableExternalCableM:
                  lead.feasible ? rowM : null,
                theoreticalResistanceOhmPerString:
                  resistanceSavingOhm,
                availableResistanceOhmPerString:
                  lead.feasible ? resistanceSavingOhm : null,
                theoreticalVoltageDropVPerString:
                  voltageDropSavingV,
                availableVoltageDropVPerString:
                  lead.feasible ? voltageDropSavingV : null,
                voltageDropPercentOfStringVmp:
                  stringVmpV > 0
                    ? 100 * voltageDropSavingV / stringVmpV
                    : 0,
                theoreticalPowerLossWPerString:
                  powerLossSavingW,
                availablePowerLossWPerString:
                  lead.feasible ? powerLossSavingW : null,
                theoreticalInstalledCostPerString:
                  rowM * input.installedCableRatePerM,
                availableInstalledCostPerString:
                  lead.feasible
                    ? rowM * input.installedCableRatePerM
                    : null
              }
            });

            number += 1;
          }
        });
      }

      return strings;
    }

    function sumStrings(strings) {
      return strings.reduce(
        (totals, string) => {
          totals.sequentialExternalM +=
            string.sequential.totalExternalM;
          totals.leapfrogExternalM +=
            string.leapfrog.totalExternalM;
          totals.theoreticalSavingM +=
            string.saving.theoreticalExternalCableM;
          totals.theoreticalPowerLossSavingW +=
            string.saving.theoreticalPowerLossWPerString;
          totals.theoreticalInstalledCostSaving +=
            string.saving.theoreticalInstalledCostPerString;

          return totals;
        },
        {
          sequentialExternalM: 0,
          leapfrogExternalM: 0,
          theoreticalSavingM: 0,
          theoreticalPowerLossSavingW: 0,
          theoreticalInstalledCostSaving: 0
        }
      );
    }

    function calculate(raw = {}, distanceOverrideM) {
      const input = normalise(raw);
      const lead = leadFeasibility(input);
      const strings = buildStrings(input, distanceOverrideM);
      const rowM = rowSpanM(input);
      const rPerM = cableResistancePerM(input);
      const archetype = sumStrings(strings);
      const firstString = strings[0] || null;
      const siteSavingM =
        rowM * input.totalSiteStringCount;
      const sitePowerLossSavingW =
        (firstString
          ? firstString.saving.theoreticalPowerLossWPerString
          : 0) * input.totalSiteStringCount;
      const siteInstalledCostSaving =
        rowM *
        input.totalSiteStringCount *
        input.installedCableRatePerM;

      return {
        modelVersion: VERSION,
        formulaId:
          'v8-2-sequential-versus-leapfrog-external-cable',
        input,
        feasibility: lead,
        geometry: {
          modulePitchM: modulePitchM(input),
          rowSpanM: rowM,
          bandPitchM: rowM + input.bandGapM,
          requiredLeapfrogReachM: lead.requiredReachM
        },
        electrical: {
          cableResistance20OhmPerM:
            input.cableR20MilliOhmPerM / 1000,
          cableResistanceOperatingOhmPerM: rPerM,
          stringVmpV:
            input.modulesPerString * input.moduleVmpV,
          theoreticalResistanceSavingOhmPerString:
            firstString
              ? firstString.saving
                  .theoreticalResistanceOhmPerString
              : 0,
          availableResistanceSavingOhmPerString:
            lead.feasible && firstString
              ? firstString.saving
                  .theoreticalResistanceOhmPerString
              : null,
          theoreticalVoltageDropSavingVPerString:
            firstString
              ? firstString.saving
                  .theoreticalVoltageDropVPerString
              : 0,
          availableVoltageDropSavingVPerString:
            lead.feasible && firstString
              ? firstString.saving
                  .theoreticalVoltageDropVPerString
              : null,
          voltageDropSavingPercentOfStringVmp:
            firstString
              ? firstString.saving
                  .voltageDropPercentOfStringVmp
              : 0,
          theoreticalPowerLossSavingWPerString:
            firstString
              ? firstString.saving
                  .theoreticalPowerLossWPerString
              : 0,
          availablePowerLossSavingWPerString:
            lead.feasible && firstString
              ? firstString.saving
                  .theoreticalPowerLossWPerString
              : null
        },
        totals: {
          stringsPerArchetypeInverter: strings.length,
          totalSiteStringCount: input.totalSiteStringCount,
          averageSiteStringsPerInverter:
            input.totalSiteStringCount / input.inverterCount,
          sequentialExternalMPerArchetypeInverter:
            archetype.sequentialExternalM,
          leapfrogExternalMPerArchetypeInverter:
            archetype.leapfrogExternalM,
          theoreticalSavingMPerArchetypeInverter: