In this section
- Price History UI energy-data · globalgrid2050 / uk_energy_tracking_v4/price-history-ui.css lines 1–228
- Price History UI energy-data · globalgrid2050 / uk_energy_tracking_v4/price-history-ui.js lines 1–57
- Frequency History UI render · globalgrid2050 / uk_energy_tracking_v5/frequency-history-ui.js lines 1–143
- Live App render · globalgrid2050 / uk_energy_tracking_v5/live-app.js lines 1–67
- Live Config other · globalgrid2050 / uk_energy_tracking_v5/live-config.js lines 1–7
- Live Gauges render · globalgrid2050 / uk_energy_tracking_v5/live-gauges.js lines 1–25
- Live Helpers transform · globalgrid2050 / uk_energy_tracking_v5/live-helpers.js lines 1–9
- Live Oil Chart render · globalgrid2050 / uk_energy_tracking_v5/live-oil-chart.js lines 1–97
- Live Transport energy-data · globalgrid2050 / uk_energy_tracking_v5/live-transport.js lines 1–54
Price History UI
A style sheet in GlobalGrid2050.
Set aside from the main view: Near copy of uk_energy_tracking_v5/price-history-ui.css (globalgrid2050), which stays: reachable first, then the higher version. (near-copy-of, proposed by families.py). 96% of lines shared with Price History UI; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9695 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v4/price-history-ui.css:1-228 395d7d288b8af33597551d860565fd86a6755ef8
- sha256 03444190769bcebc9caf3e709b92b10f443e20b33dae2d588d86617fdac9148d
- target sha256 7dd87d2d7679ca335436b11f71d964e810f632996f33cecd652bcf56b9696862
- group of 2 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
- re-pointed by apply.py version rule (was canonical)
energy-dataglobalgrid2050 / uk_energy_tracking_v4/price-history-ui.css · lines 1–228 of 228 · Not reached from any entry point (candidate for review)
- What it does
- Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage hv_procurement (path word 'price'): HV materials procurement, which Ventus Ltd states is within its commercial execution boundary.
- What it achieves
- Electricity-price-history-panel.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · uk_energy_tracking_v4 · style sheet
- Uses
- none found
- Used by
- none found
- 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
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v4/price-history-ui.css:1-228 · blob 395d7d288b8af33597551d860565fd86a6755ef8 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: hv_procurement · users: EPC_contractor, procurement_buyer · canonical: unreached_review
#electricity-price-history-panel,
#electricity-price-history-panel * {
box-sizing: border-box;
}
#electricity-price-history-panel {
width: 100%;
max-width: 100%;
overflow: hidden;
}
#electricity-price-history-panel .trend-panel {
width: 100%;
max-width: 100%;
overflow: hidden;
background: #070a10 !important;
border: 1px solid #252b36 !important;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.02), 0 0 22px rgba(0,255,255,.05);
}
#electricity-price-history-panel .price-history-actions {
display: flex;
flex-wrap: wrap;
gap: 10px;
align-items: center;
margin-bottom: 10px;
}
#electricity-price-history-panel .price-history-actions strong {
color: #00ffff !important;
letter-spacing: .12em;
text-transform: uppercase;
}
#electricity-price-history-panel .price-history-actions select {
background: #050505 !important;
color: #00ffff !important;
border: 1px solid #252b36 !important;
border-radius: 4px;
padding: 7px 9px;
font-family: "Courier New", monospace;
}
#electricity-price-history-panel .price-history-actions a {
border: 1px solid #252b36 !important;
border-radius: 4px;
padding: 7px 9px;
color: #7fdfff !important;
text-decoration: none !important;
background: rgba(255,255,255,.03) !important;
}
#electricity-price-history-panel #price-history-canvas {
width: 100% !important;
max-width: 100% !important;
height: clamp(230px, 34vw, 340px) !important;
display: block;
border: 1px solid #252b36 !important;
background: #05070c !important;
border-radius: 6px;
touch-action: none;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
}
#electricity-price-history-panel .price-history-grid {
display: grid;
grid-template-columns: repeat(4,minmax(0,1fr));
gap: 10px;
margin-top: 12px;
}
#electricity-price-history-panel .price-history-card {
border: 1px solid #252b36 !important;
background: #0b0f17 !important;
border-radius: 6px;
padding: 12px;
min-width: 0;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
}
#electricity-price-history-panel .price-history-label {
color: #9aa3b6 !important;
text-transform: uppercase;
letter-spacing: .12em;
font-size: 10px;
}
#electricity-price-history-panel .price-history-value {
color: #00ffff !important;
font-size: 18px;
font-weight: 800;
margin-top: 5px;
overflow-wrap: anywhere;
}
#electricity-price-history-panel .price-history-table-toggle {
margin-top: 12px;
border: 1px solid #252b36 !important;
border-radius: 6px;
background: #0b0f17 !important;
overflow: hidden;
}
#electricity-price-history-panel .price-history-table-toggle summary {
cursor: pointer;
list-style: none;
padding: 10px 12px;
color: #00ffff !important;
background: #05070c !important;
text-transform: uppercase;
letter-spacing: .1em;
font-size: 11px;
border-bottom: 1px solid #252b36 !important;
}
#electricity-price-history-panel .price-history-table-toggle summary::-webkit-details-marker {
display: none;
}
#electricity-price-history-panel .price-history-table-toggle summary::after {
content: "Open";
float: right;
color: #9aa3b6;
letter-spacing: .08em;
}
#electricity-price-history-panel .price-history-table-toggle[open] summary::after {
content: "Close";
}
#electricity-price-history-panel .price-history-table-wrap {
overflow-x: auto;
overflow-y: auto;
border: 0 !important;
border-radius: 0;
margin-top: 0;
max-height: 320px;
max-width: 100%;
background: #070a10 !important;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
}
#electricity-price-history-panel table.price-history-table {
width: 100%;
min-width: 760px;
border-collapse: collapse;
border-spacing: 0;
font-size: 12px;
color: #f5f7fb !important;
background: #070a10 !important;
font-family: "Courier New", monospace;
}
#electricity-price-history-panel table.price-history-table thead,
#electricity-price-history-panel table.price-history-table tbody,
#electricity-price-history-panel table.price-history-table tr {
background: transparent !important;
}
#electricity-price-history-panel table.price-history-table th,
#electricity-price-history-panel table.price-history-table td {
border: 0 !important;
border-bottom: 1px solid #252b36 !important;
border-right: 1px solid rgba(255,255,255,.045) !important;
padding: 9px 10px;
text-align: left;
white-space: nowrap;
background: #0b0f17 !important;
color: #f5f7fb !important;
}
#electricity-price-history-panel table.price-history-table tbody tr:nth-child(even) td {
background: #0f1520 !important;
}
#electricity-price-history-panel table.price-history-table tbody tr:hover td {
background: #111b29 !important;
}
#electricity-price-history-panel table.price-history-table th {
color: #00ffff !important;
text-transform: uppercase;
letter-spacing: .08em;
background: #05070c !important;
position: sticky;
top: 0;
z-index: 2;
}
#electricity-price-history-panel table.price-history-table td:nth-child(2) {
color: #00ffff !important;
font-weight: 800;
}
#electricity-price-history-panel table.price-history-table td:nth-child(5) {
color: #9aa3b6 !important;
}
@media (max-width: 850px) {
#electricity-price-history-panel .price-history-grid { grid-template-columns: 1fr 1fr; }
#electricity-price-history-panel #price-history-canvas { height: 250px !important; }
#electricity-price-history-panel table.price-history-table { font-size: 11px; min-width: 700px; }
}
@media (max-width: 560px) {
#electricity-price-history-panel .price-history-grid { grid-template-columns: 1fr; }
#electricity-price-history-panel .price-history-value { font-size: 22px; }
#electricity-price-history-panel #price-history-canvas { height: 245px !important; }
}
/* V4 price history fullscreen chart */
#electricity-price-history-panel .price-history-fullscreen-btn{border:1px solid #252b36!important;border-radius:4px;padding:7px 9px;color:#00ffff!important;background:rgba(0,255,255,.05)!important;font-family:"Courier New",monospace;cursor:pointer}
.price-history-fullscreen-overlay{position:fixed;inset:0;display:none;z-index:9999;background:rgba(0,0,0,.92);padding:14px;box-sizing:border-box;overflow:hidden}
.price-history-fullscreen-overlay.open{display:flex}
.price-history-fullscreen-shell{width:100%;height:100%;min-height:0;border:1px solid #00ffff;border-radius:8px;background:#05070c;box-shadow:0 0 32px rgba(0,255,255,.16);display:flex;flex-direction:column;overflow:hidden;transform:translateZ(0);will-change:transform}
.price-history-fullscreen-toolbar{flex:0 0 auto;display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:10px 12px;border-bottom:1px solid #252b36;background:#070a10;color:#f5f7fb;font-family:"Courier New",monospace}
.price-history-fullscreen-toolbar strong{color:#00ffff;text-transform:uppercase;letter-spacing:.12em;font-size:12px}.price-history-fullscreen-toolbar span{color:#9aa3b6;font-size:12px;margin-right:auto}.price-history-fullscreen-toolbar button{border:1px solid #252b36;border-radius:4px;padding:7px 9px;color:#00ffff;background:rgba(255,255,255,.03);font-family:"Courier New",monospace;cursor:pointer}
#price-history-fullscreen-canvas{width:100%;height:100%;min-height:0;flex:1 1 auto;display:block;background:#05070c;touch-action:none;transform:translateZ(0);will-change:transform}
.price-history-fullscreen-note{flex:0 0 auto;border-top:1px solid #252b36;padding:8px 12px;color:#9aa3b6;font:12px "Courier New",monospace;background:#070a10}
/* V4 price history calendar range controls */
#electricity-price-history-panel .price-history-date-label{display:flex;align-items:center;gap:6px;color:#9aa3b6;text-transform:uppercase;letter-spacing:.08em;font-size:11px}
#electricity-price-history-panel .price-history-date-label input{background:#050505!important;color:#00ffff!important;border:1px solid #252b36!important;border-radius:4px;padding:7px 9px;font-family:"Courier New",monospace}
#electricity-price-history-panel .price-history-date-apply{border:1px solid #252b36!important;border-radius:4px;padding:7px 9px;color:#00ffff!important;background:rgba(0,255,255,.05)!important;font-family:"Courier New",monospace;cursor:pointer}
#electricity-price-history-panel table.price-history-table tr.price-warning td{background:#20160b!important;color:#ffd28a!important}
#electricity-price-history-panel table.price-history-table tr.price-warning td:nth-child(2){color:#ffcc66!important}
#electricity-price-history-panel .price-history-range-status{width:100%;color:#9aa3b6;font-size:11px;line-height:1.45;border:1px solid #252b36;border-radius:4px;padding:7px 9px;background:#070a10;}Price History UI
A JavaScript file in GlobalGrid2050 that loads annual (`loadAnnual`), syncs scroller start (`syncScrollerFromStart`) and start scroller (`syncStartFromScroller`), draws on a canvas and reads inputs for price history scroll.
energy-dataglobalgrid2050 / uk_energy_tracking_v4/price-history-ui.js · lines 1–57 of 57 · Not reached from any entry point (candidate for review) · pattern syncScrollerFromStart (shared by 2 files)
- What it does
- It draws electricity price history. Defines 30 functions or classes, including $, fmt, dlab, slab, mlab. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage hv_procurement (path word 'price'): HV materials procurement, which Ventus Ltd states is within its commercial execution boundary.
- Inputs & outputs
- In: JSON file electricity_price_history.json; form fields (user input). Out: canvas drawing.
- What it achieves
- It loads JSON (`loadJson`), loads annual (`loadAnnual`) and syncs scroller start (`syncScrollerFromStart`). Defines `fmt`, `dlab`, `slab` and 26 more. It responds to click, DOMContentLoaded and change events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · uk_energy_tracking_v4 · script
- Uses
- none found
- Used by
- none found
- Produces
- $, fmt, dlab, slab, mlab, tlab, ymd, set, timeModeLabel, csvLine, loadJson, yearsBetween
- Defines here
- $, fmt, dlab, slab, mlab, tlab, ymd, set, timeModeLabel, csvLine, loadJson, yearsBetween, loadAnnual, merge, periodDays, periodLabel, totalScrollableDays, dateFromOffset, offsetFromDate, ensureYearOptions, syncScrollerFromStart, syncStartFromScroller, passesTimeMode, health, minMax, niceStep, drawDateTick, eventPoints, drawEvents, deferredLoad
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v4/price-history-ui.js:1-57 · blob 9ed87119ff8cfeceb200b05e8fec8c48d5218f4d · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, network · domain stage: hv_procurement · users: EPC_contractor, procurement_buyer · canonical: unreached_review
(function(){
var JSON_URL='/uk_energy_tracking_v4/electricity_price_history.json';
var ANNUAL_URL_BASE='/data/electricity/elexon_system_prices_';
var MAX_VISIBLE_ROWS=19000;
var FIRST_YEAR=2016;
var MIN_DATE=new Date(Date.UTC(FIRST_YEAR,0,1,0,0,0));
var TODAY=new Date();
var MAX_DATE=new Date(Date.UTC(TODAY.getUTCFullYear(),TODAY.getUTCMonth(),TODAY.getUTCDate(),23,59,59));
var ANNUAL_CACHE={};
var pendingTimer=null;
var STATE={all:[],visible:[],meta:null,loadedYears:[],sourceRows:0,timeMode:'all'};window.__v4PriceHistoryState=STATE;
function $(id){return document.getElementById(id)}
function fmt(n,d){return n==null||isNaN(n)?'—':Number(n).toLocaleString('en-GB',{minimumFractionDigits:d,maximumFractionDigits:d})}
function dlab(t){return new Date(t).toLocaleDateString('en-GB',{day:'2-digit',month:'long',year:'numeric'})}
function slab(t){return new Date(t).toLocaleDateString('en-GB',{day:'2-digit',month:'short',year:'numeric'})}
function mlab(t){return new Date(t).toLocaleDateString('en-GB',{month:'short',year:'2-digit'})}
function tlab(t){return new Date(t).toLocaleTimeString('en-GB',{hour:'2-digit',minute:'2-digit'})}
function ymd(d){return d.toISOString().slice(0,10)}
function set(id,v){var e=$(id);if(e)e.textContent=v}
function timeModeLabel(){if(STATE.timeMode==='day')return 'Daytime price points only, 06:00 to 17:59 UTC';if(STATE.timeMode==='night')return 'Nighttime price points only, 18:00 to 05:59 UTC';return 'All half hourly price points'}
function csvLine(l){var o=[],v='',q=false;for(var i=0;i<l.length;i++){var c=l[i];if(c==='"'){if(q&&l[i+1]==='"'){v+='"';i++}else q=!q}else if(c===','&&!q){o.push(v);v=''}else v+=c}o.push(v);return o}
function parseCsv(t){t=(t||'').trim();if(!t)return[];var lines=t.split(/\r?\n/),h=csvLine(lines[0]).map(function(x){return x.trim()});return lines.slice(1).map(function(line){var c=csvLine(line),r={};h.forEach(function(x,i){r[x]=(c[i]||'').trim()});var p=r.systemBuyPriceGBPperMWh||r.systemSellPriceGBPperMWh||r.priceGBPperMWh||'';return{source:r.source||'Elexon BMRS System Prices',priceTimeUTC:r.pe … [line shortened here: 878 characters; full line on GitHub]
function loadJson(){return fetch(JSON_URL+'?t='+Date.now(),{cache:'no-store'}).then(function(r){return r.ok?r.json():{rows:[]}}).then(function(d){return d.rows||[]}).catch(function(){return[]})}
function yearsBetween(a,b){var y=[],s=a.getUTCFullYear(),e=b.getUTCFullYear();for(var n=s;n<=e;n++)y.push(n);return y}
function loadAnnual(year){if(ANNUAL_CACHE[year])return ANNUAL_CACHE[year];ANNUAL_CACHE[year]=fetch(ANNUAL_URL_BASE+year+'.csv?t='+Date.now(),{cache:'no-store'}).then(function(r){return r.ok?r.text():''}).then(parseCsv).catch(function(){return[]});return ANNUAL_CACHE[year]}
function norm(rows){var seen={};return(rows||[]).filter(function(r){return r.priceTimeUTC&&r.priceGBPperMWh!==''&&!isNaN(Number(r.priceGBPperMWh))}).map(function(r){var o=Object.assign({},r);o.priceGBPperMWh=Number(o.priceGBPperMWh);return o}).sort(function(a,b){return new Date(a.priceTimeUTC)-new Date(b.priceTimeUTC)}).filter(function(r){var k=r.priceTimeUTC+'|'+r.priceGBPperMWh+'|'+(r.source||'' … [line shortened here: 450 characters; full line on GitHub]
function merge(sys,cap){var rows=[];sys.forEach(function(r){rows.push(Object.assign({},r,{source:'Elexon BMRS System Prices',priceHealth:r.priceHealth||'historical system price'}))});cap.forEach(function(r){rows.push(Object.assign({},r,{source:r.source||'V4 captured Elexon Market Index Price'}))});return norm(rows)}
function periodDays(period){return {'7d':7,'30d':30,'3m':92,'6m':183,'12m':366}[period]||7}
function periodLabel(period){return {'7d':'1 week','30d':'1 month','3m':'3 months','6m':'6 months','12m':'12 months'}[period]||'1 week'}
function totalScrollableDays(){return Math.max(1,Math.floor((MAX_DATE-MIN_DATE)/86400000))}
function dateFromOffset(v){var d=new Date(MIN_DATE.getTime()+Number(v)*86400000);d.setUTCHours(0,0,0,0);return d}
function offsetFromDate(d){return Math.max(0,Math.min(totalScrollableDays(),Math.floor((d-MIN_DATE)/86400000)))}
function ensurePeriodOptions(){var p=$('price-history-period');if(!p)return;var wanted=[['7d','1 week'],['30d','1 month'],['3m','3 months'],['6m','6 months'],['12m','12 months']];var current=p.value||'7d';p.innerHTML='';wanted.forEach(function(x){var o=document.createElement('option');o.value=x[0];o.textContent=x[1];p.appendChild(o)});p.value=current&&wanted.some(function(x){return x[0]===current} … [line shortened here: 415 characters; full line on GitHub]
function ensureModeTabs(){if($('price-history-time-tabs'))return;var actions=document.querySelector('#electricity-price-history-panel .price-history-actions');if(!actions)return;var tabs=document.createElement('div');tabs.id='price-history-time-tabs';tabs.className='price-history-time-tabs';tabs.innerHTML='<span>Hour filter inside selected date window</span><button type="button" data-mode="all" cl … [line shortened here: 955 characters; full line on GitHub]
function ensureScroller(){if($('price-history-scroll'))return;var actions=document.querySelector('#electricity-price-history-panel .price-history-actions');if(!actions)return;var wrap=document.createElement('div');wrap.className='price-history-scroller';wrap.innerHTML='<div class="price-history-scroller-head"><strong>History scroller</strong><span id="price-history-scroll-label">2016 to present. O … [line shortened here: 2,188 characters; full line on GitHub]
function ensureYearOptions(){var y=$('price-history-year');if(!y||y.options.length)return;var nowYear=MAX_DATE.getUTCFullYear();for(var n=nowYear;n>=FIRST_YEAR;n--){var o=document.createElement('option');o.value=String(n);o.textContent=String(n);y.appendChild(o)}y.value=String(nowYear)}
function ensureStartDate(){var y=$('price-history-year'),s=$('price-history-start');if(!s)return;var selectedYear=y&&y.value?Number(y.value):MAX_DATE.getUTCFullYear();if(!s.value||s.value.slice(0,4)!==String(selectedYear)){var start;if(selectedYear===MAX_DATE.getUTCFullYear()){start=new Date(MAX_DATE.getTime()-7*86400000)}else{start=new Date(Date.UTC(selectedYear,0,1,0,0,0))}s.value=ymd(start)}syn … [line shortened here: 421 characters; full line on GitHub]
function syncScrollerFromStart(){var s=$('price-history-start'),r=$('price-history-scroll');if(!s||!r||!s.value)return;r.value=String(offsetFromDate(new Date(s.value+'T00:00:00Z')))}
function syncStartFromScroller(){var r=$('price-history-scroll'),s=$('price-history-start'),y=$('price-history-year');if(!r||!s)return;var d=dateFromOffset(r.value);s.value=ymd(d);if(y)y.value=String(d.getUTCFullYear())}
function selectedWindow(){ensureStartDate();var y=$('price-history-year'),s=$('price-history-start'),p=$('price-history-period');var year=y&&y.value?Number(y.value):MAX_DATE.getUTCFullYear();var period=p&&p.value?p.value:'7d';var start=s&&s.value?new Date(s.value+'T00:00:00Z'):new Date(Date.UTC(year,0,1,0,0,0));if(isNaN(start))start=new Date(Date.UTC(year,0,1,0,0,0));if(start<MIN_DATE)start=new Da … [line shortened here: 791 characters; full line on GitHub]
function passesTimeMode(r){if(STATE.timeMode==='all')return true;var h=new Date(r.priceTimeUTC).getUTCHours();var day=h>=6&&h<18;return STATE.timeMode==='day'?day:!day}
function health(r){if(r.priceHealth&&r.priceHealth!=='ok')return 'price: '+r.priceHealth;if(r.carbonHealth&&r.carbonHealth!=='ok')return 'carbon: '+r.carbonHealth;if(r.carbonGperKWh!==''&&r.carbonGperKWh!=null)return r.carbonGperKWh+' g/kWh';if(r.carbonIndex)return String(r.carbonIndex);return '—'}
function minMax(v){var lo=0,hi=0;v.forEach(function(x){if(x<lo)lo=x;if(x>hi)hi=x});if(lo===hi)hi=lo+1;var m=(hi-lo)*0.08;return{lo:lo-m,hi:hi+m}}
function niceStep(span){var raw=span/6,p=Math.pow(10,Math.floor(Math.log10(Math.max(raw,1)))),n=raw/p;if(n<=1)return p;if(n<=2)return 2*p;if(n<=5)return 5*p;return 10*p}
function drawDateTick(g,x,y,t,q,align){g.textAlign=align||'center';g.fillStyle='#f5f7fb';g.font=12*q+'px Courier New';g.fillText(mlab(t),x,y);g.textAlign='left'}
function drawAxes(g,w,h,q,m,t0,t1,pad){var step=niceStep(m.hi-m.lo),start=Math.ceil(m.lo/step)*step;g.lineWidth=q;g.font=11*q+'px Courier New';g.textAlign='left';for(var val=start;val<=m.hi+step*.5;val+=step){var yy=pad.top+((m.hi-val)/(m.hi-m.lo))*(h-pad.top-pad.bottom);g.strokeStyle=val===0?'rgba(255,51,51,.95)':'rgba(255,255,255,.18)';g.lineWidth=val===0?2*q:q;g.beginPath();g.moveTo(pad.left,yy … [line shortened here: 868 characters; full line on GitHub]
function eventPoints(rows){if(!rows.length)return null;var hi=rows[0],lo=rows[0];rows.forEach(function(r){if(Number(r.priceGBPperMWh)>Number(hi.priceGBPperMWh))hi=r;if(Number(r.priceGBPperMWh)<Number(lo.priceGBPperMWh))lo=r});return{hi:hi,lo:lo}}
function drawMarker(g,label,r,x,y,q,above,colour){var price='£'+fmt(Number(r.priceGBPperMWh),2),time=slab(r.priceTimeUTC)+' '+tlab(r.priceTimeUTC);var shift=label==='HIGH'?18*q:-18*q;var tx=label==='HIGH'?Math.min(g.canvas.width-118*q,x+shift):Math.max(118*q,x+shift);var ty=above?Math.max(42*q,y-34*q):Math.min(g.canvas.height-44*q,y+48*q);g.strokeStyle=colour;g.fillStyle=colour;g.lineWidth=1.3*q;g … [line shortened here: 691 characters; full line on GitHub]
function drawEvents(g,rows,X,Y,q){var e=eventPoints(rows);if(!e)return;drawMarker(g,'HIGH',e.hi,X(e.hi),Y(Number(e.hi.priceGBPperMWh)),q,true,'#ff3333');drawMarker(g,'LOW',e.lo,X(e.lo),Y(Number(e.lo.priceGBPperMWh)),q,false,'#ff3333')}
function draw(rows,meta){var c=$('price-history-canvas');if(!c)return;var q=devicePixelRatio||1,r=c.getBoundingClientRect();if(r.width){c.width=Math.max(320,Math.floor(r.width*q));c.height=Math.max(260,Math.floor((r.height||300)*q))}var g=c.getContext('2d'),w=c.width,h=c.height,pad={left:68*q,right:32*q,top:42*q,bottom:64*q};g.clearRect(0,0,w,h);g.fillStyle='#05070c';g.fillRect(0,0,w,h);g.font=12* … [line shortened here: 1,485 characters; full line on GitHub]
function table(rows,meta){var b=$('price-history-table-body');if(!b)return;if(!rows.length){b.innerHTML='<tr><td colspan="5">No records available from '+dlab(meta.start)+' for the selected period and hour filter.</td></tr>';return}b.innerHTML=rows.slice().reverse().map(function(r){return '<tr class="'+((r.priceHealth&&r.priceHealth!=='ok')?'price-warning':'')+'"><td>'+dlab(r.priceTimeUTC)+' '+tlab … [line shortened here: 606 characters; full line on GitHub]
function status(meta,sourceRows,rows,years){var s=$('price-history-range-status');var lab=$('price-history-scroll-label');var note=(meta.period==='6m'||meta.period==='12m')?' | Longer window, performance depends on device capacity.':'';var text='Date window: '+dlab(meta.start)+' '+tlab(meta.start)+' to '+dlab(meta.end)+' '+tlab(meta.end)+' | Hour filter: '+timeModeLabel()+' | Annual files: '+(year … [line shortened here: 758 characters; full line on GitHub]
function load(){ensurePeriodOptions();ensureModeTabs();ensureYearOptions();ensureScroller();var meta=selectedWindow(),years=yearsBetween(meta.start,meta.end);syncScrollerFromStart();Promise.all([loadJson()].concat(years.map(loadAnnual))).then(function(parts){var cap=parts[0],sys=[];parts.slice(1).forEach(function(a){sys=sys.concat(a)});var all=merge(norm(sys),norm(cap));var rows=all.filter(functio … [line shortened here: 1,205 characters; full line on GitHub]
function deferredLoad(){clearTimeout(pendingTimer);pendingTimer=setTimeout(load,160)}
window.__v4PriceHistoryControls={load:load,deferredLoad:deferredLoad,periodDays:periodDays,totalScrollableDays:totalScrollableDays,dateFromOffset:dateFromOffset,offsetFromDate:offsetFromDate,syncStartFromScroller:syncStartFromScroller,setOffset:function(v){var r=$('price-history-scroll');if(r){r.value=v;syncStartFromScroller();load()}},setPeriod:function(v){var p=$('price-history-period');if(p){p. … [line shortened here: 463 characters; full line on GitHub]
document.addEventListener('DOMContentLoaded',function(){ensurePeriodOptions();ensureModeTabs();ensureYearOptions();ensureScroller();ensureStartDate();var y=$('price-history-year'),p=$('price-history-period'),s=$('price-history-start'),cl=$('price-history-clear-start'),r=$('price-history-scroll'),prev=$('price-history-prev'),next=$('price-history-next');if(y)y.addEventListener('change',function(){v … [line shortened here: 1,346 characters; full line on GitHub]
})();Frequency History UI
A JavaScript file in GlobalGrid2050 that draws grid frequency history and live grid frequency weekly health. It parses CSV (`parseCsv`), gets text (`getText`) and gets JSON (`getJson`).
Set aside from the main view: Near copy of uk_energy_tracking_v6/frequency_history/frequency-history-ui.js (globalgrid2050), which stays: reachable first, then the higher version. (near-copy-of, proposed by families.py). 91% of lines shared with Frequency History UI; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9194 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v5/frequency-history-ui.js:1-143 7e30db45790ec74e287fa2e41a027a81618b673d
- sha256 4e136ec56e7e4e2bc9bc3856eee9dd2b4774782aef42fdb3849bb703b0b7a39b
- target sha256 856be8e85e34747bf53ab5a223115b9001c3e3486109290b3118195d81ea993f
- group of 2 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
- re-pointed by apply.py version rule (was canonical)
renderglobalgrid2050 / uk_energy_tracking_v5/frequency-history-ui.js · lines 1–143 of 143 · Not reached from any entry point (candidate for review) · pattern canvasSetup (shared by 2 files)
- What it does
- It draws grid frequency history and live grid frequency weekly health. Defines 13 functions or classes, including $, txt, css, install, parseCsv. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage upstream_foresight (topic 'markets-data'): 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.
- Inputs & outputs
- In: CSV file grid_frequency_history.csv; JSON file live_grid_frequency.json; JSON file live_grid_frequency_weekly_health.json; CSV file grid_frequency_weekly_health.csv. Out: canvas drawing.
- Downstream impact
- Used directly by 1 file: Live App (globalgrid2050).
- What it achieves
- GlobalGrid2050 V5 frequency chart. Inserts itself below the Elexon price chart. Its code works with 50 Hz. It responds to resize events.
- Why it matters
- Imported by Live App.
- Application
- globalgrid2050 · uk_energy_tracking_v5 · script
- Uses
- none found
- Used by
- loaded by Live App (script src), mentioned in Standalone (comment link)
- Produces
- $, txt, css, install, parseCsv, timeLabel, weekLabel, getText, getJson, canvasSetup, draw, drawWeekly
- Defines here
- $, txt, css, install, parseCsv, timeLabel, weekLabel, getText, getJson, canvasSetup, draw, drawWeekly, refresh
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v5/frequency-history-ui.js:1-143 · blob 7e30db45790ec74e287fa2e41a027a81618b673d · 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: unreached_review
// GlobalGrid2050 V5 frequency chart. Inserts itself below the Elexon price chart.
(function(){
var CSV_URL = "/uk_energy_tracking_v5/grid_frequency_history.csv";
var LIVE_URL = "/uk_energy_tracking_v5/live_grid_frequency.json";
var WEEKLY_URL = "/uk_energy_tracking_v5/live_grid_frequency_weekly_health.json";
var REFRESH_MS = 120000;
var installed = false;
function $(id){ return document.getElementById(id); }
function txt(id, value){ var el=$(id); if(el) el.textContent=value; }
function css(){
if($("gg-frequency-style")) return;
var s=document.createElement("style");
s.id="gg-frequency-style";
s.textContent="\n#grid-frequency-panel .frequency-shell{background:var(--gg-panel,#0b0f17);border:1px solid var(--gg-line,#252b36);border-radius:6px;padding:14px;margin-top:18px}\n#grid-frequency-panel .frequency-actions{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin-bottom:10px}\n#grid-frequency-panel .frequency-actions strong{color:var(--gg-cyan,#00ffff);letter-spacing:.12em; … [line shortened here: 1,891 characters; full line on GitHub]
document.head.appendChild(s);
}
function install(){
if(installed || $("grid-frequency-panel")) return true;
var price=$("electricity-price-history-panel");
if(!price || !price.parentNode) return false;
css();
var section=document.createElement("section");
section.id="grid-frequency-panel";
section.innerHTML="<h2 class='section-title'>Grid Frequency 24 Hour Trace</h2>"+
"<div class='frequency-shell'>"+
"<div class='frequency-actions'><strong>UK grid frequency from Elexon</strong><a href='/uk_energy_tracking_v5/grid_frequency_history.csv' download>Download frequency CSV</a><a href='/uk_energy_tracking_v5/grid_frequency_weekly_health.csv' download>Download weekly health CSV</a></div>"+
"<div class='frequency-note'><b>Grid stability signal:</b> frequency shows the live balance between generation and demand. The 50 Hz reference line exposes stress, recovery and control behaviour over the last rolling 24 hours.</div>"+
"<canvas id='frequency-history-canvas' width='900' height='340'></canvas>"+
"<div class='frequency-mini-grid'>"+
"<div class='frequency-mini'><span>Latest</span><strong><b id='frequency-latest'>—</b> Hz</strong></div>"+
"<div class='frequency-mini'><span>Records</span><strong id='frequency-records'>—</strong></div>"+
"<div class='frequency-mini'><span>Window</span><strong id='frequency-window'>24 hours</strong></div>"+
"<div class='frequency-mini'><span>Min to max</span><strong id='frequency-minmax'>—</strong></div>"+
"</div><div class='scada-credit' id='frequency-updated' style='margin-top:10px;'>Awaiting frequency update.</div>"+
"<div class='frequency-subtitle'>Weekly grid health trend</div>"+
"<div class='frequency-note'><b>Health proxy:</b> weekly average frequency and largest deviation from 50 Hz. Historic depth depends on what the public Elexon frequency endpoint returns during backfill.</div>"+
"<canvas id='frequency-weekly-canvas' width='900' height='300'></canvas>"+
"<div class='frequency-mini-grid'>"+
"<div class='frequency-mini'><span>Weeks</span><strong id='frequency-weekly-count'>—</strong></div>"+
"<div class='frequency-mini'><span>Latest avg</span><strong id='frequency-weekly-avg'>—</strong></div>"+
"<div class='frequency-mini'><span>Largest dev</span><strong id='frequency-weekly-dev'>—</strong></div>"+
"<div class='frequency-mini'><span>Weekly health</span><strong id='frequency-weekly-health'>—</strong></div>"+
"</div></div>";
price.parentNode.insertBefore(section, price.nextSibling);
installed=true;
return true;
}
function parseCsv(text){
text=(text||"").trim();
if(!text) return [];
return text.split(/\r?\n/).slice(1).map(function(line){
var p=line.split(",");
if(p.length<2) return null;
var hz=parseFloat(p[1]);
if(!isFinite(hz)) return null;
return {t:p[0], hz:hz};
}).filter(Boolean);
}
function timeLabel(iso){
if(!iso) return "—";
var d=new Date(iso);
if(isNaN(d.getTime())) return iso;
return d.toLocaleString("en-GB",{day:"2-digit",month:"short",hour:"2-digit",minute:"2-digit",second:"2-digit"});
}
function weekLabel(iso){
if(!iso) return "—";
var d=new Date(iso);
if(isNaN(d.getTime())) return iso;
return d.toLocaleDateString("en-GB",{day:"2-digit",month:"short"});
}
function getText(url){return fetch(url+"?t="+Date.now(),{cache:"no-store"}).then(function(r){if(!r.ok) throw new Error(String(r.status)); return r.text();});}
function getJson(url){return fetch(url+"?t="+Date.now(),{cache:"no-store"}).then(function(r){if(!r.ok) throw new Error(String(r.status)); return r.json();});}
function canvasSetup(id, minH){
var c=$(id); if(!c) return null;
var ctx=c.getContext("2d"), rect=c.getBoundingClientRect(), dpr=window.devicePixelRatio||1;
var w=Math.max(340,Math.floor(rect.width*dpr)), h=Math.max(minH||260,Math.floor(rect.height*dpr));
c.width=w; c.height=h; ctx.fillStyle="#070a10"; ctx.fillRect(0,0,w,h);
return {c:c,ctx:ctx,dpr:dpr,w:w,h:h,L:58*dpr,R:18*dpr,T:24*dpr,B:44*dpr};
}
function draw(rows){
var g=canvasSetup("frequency-history-canvas",260); if(!g) return;
var ctx=g.ctx,dpr=g.dpr,L=g.L,R=g.R,T=g.T,B=g.B,w=g.w,h=g.h,pw=w-L-R,ph=h-T-B;
ctx.strokeStyle="rgba(255,255,255,.12)"; ctx.lineWidth=1*dpr; ctx.strokeRect(L,T,pw,ph);
[49.8,49.9,50.0,50.1,50.2].forEach(function(v){
var y=T+(50.2-v)/0.4*ph;
ctx.beginPath(); ctx.moveTo(L,y); ctx.lineTo(L+pw,y); ctx.stroke();
ctx.fillStyle=v===50?"#00ffff":"#9aa3b6"; ctx.font=(11*dpr)+"px Courier New"; ctx.fillText(v.toFixed(1),8*dpr,y+4*dpr);
});
if(!rows.length){ctx.fillStyle="#9aa3b6"; ctx.font=(14*dpr)+"px Courier New"; ctx.fillText("Awaiting frequency records",L+18*dpr,T+42*dpr); return;}
var vals=rows.map(function(r){return r.hz;});
var min=Math.min.apply(null,vals.concat([49.8])), max=Math.max.apply(null,vals.concat([50.2]));
var span=Math.max(0.2,max-min); min-=span*0.08; max+=span*0.08;
var y50=T+(max-50)/(max-min)*ph;
ctx.strokeStyle="rgba(0,255,255,.60)"; ctx.setLineDash([6*dpr,6*dpr]); ctx.beginPath(); ctx.moveTo(L,y50); ctx.lineTo(L+pw,y50); ctx.stroke(); ctx.setLineDash([]);
ctx.shadowColor="rgba(0,255,136,.45)"; ctx.shadowBlur=12*dpr; ctx.strokeStyle="#00ff88"; ctx.lineWidth=2*dpr; ctx.beginPath();
rows.forEach(function(r,i){var x=L+(rows.length===1?0.5:i/(rows.length-1))*pw; var y=T+(max-r.hz)/(max-min)*ph; if(i===0)ctx.moveTo(x,y); else ctx.lineTo(x,y);});
ctx.stroke(); ctx.shadowBlur=0;
ctx.fillStyle="#9aa3b6"; ctx.font=(11*dpr)+"px Courier New";
ctx.fillText(timeLabel(rows[0].t),L,T+ph+26*dpr);
ctx.fillText(timeLabel(rows[rows.length-1].t),Math.max(L,L+pw-150*dpr),T+ph+26*dpr);
}
function drawWeekly(rows){
var g=canvasSetup("frequency-weekly-canvas",240); if(!g) return;
var ctx=g.ctx,dpr=g.dpr,L=g.L,R=g.R,T=g.T,B=g.B,w=g.w,h=g.h,pw=w-L-R,ph=h-T-B;
ctx.strokeStyle="rgba(255,255,255,.12)"; ctx.lineWidth=1*dpr; ctx.strokeRect(L,T,pw,ph);
[49.95,50.0,50.05].forEach(function(v){
var y=T+(50.05-v)/0.10*ph;
ctx.beginPath(); ctx.moveTo(L,y); ctx.lineTo(L+pw,y); ctx.stroke();
ctx.fillStyle=v===50?"#00ffff":"#9aa3b6"; ctx.font=(11*dpr)+"px Courier New"; ctx.fillText(v.toFixed(2),6*dpr,y+4*dpr);
});
if(!rows.length){ctx.fillStyle="#9aa3b6"; ctx.font=(14*dpr)+"px Courier New"; ctx.fillText("Awaiting weekly health rows",L+18*dpr,T+42*dpr); return;}
var vals=rows.map(function(r){return Number(r.avg_hz);}).filter(function(v){return isFinite(v);});
var min=Math.min.apply(null,vals.concat([49.95])), max=Math.max.apply(null,vals.concat([50.05]));
var span=Math.max(0.05,max-min); min-=span*0.1; max+=span*0.1;
var y50=T+(max-50)/(max-min)*ph;
ctx.strokeStyle="rgba(0,255,255,.60)"; ctx.setLineDash([6*dpr,6*dpr]); ctx.beginPath(); ctx.moveTo(L,y50); ctx.lineTo(L+pw,y50); ctx.stroke(); ctx.setLineDash([]);
ctx.shadowColor="rgba(255,204,0,.35)"; ctx.shadowBlur=10*dpr; ctx.strokeStyle="#ffcc00"; ctx.lineWidth=2*dpr; ctx.beginPath();
rows.forEach(function(r,i){var x=L+(rows.length===1?0.5:i/(rows.length-1))*pw; var y=T+(max-Number(r.avg_hz))/(max-min)*ph; if(i===0)ctx.moveTo(x,y); else ctx.lineTo(x,y);});
ctx.stroke(); ctx.shadowBlur=0;
ctx.fillStyle="#9aa3b6"; ctx.font=(11*dpr)+"px Courier New";
ctx.fillText(weekLabel(rows[0].week_start_utc),L,T+ph+26*dpr);
ctx.fillText(weekLabel(rows[rows.length-1].week_start_utc),Math.max(L,L+pw-90*dpr),T+ph+26*dpr);
}
function refresh(){
if(!install()) return;
Promise.all([getText(CSV_URL).catch(function(){return "";}),getJson(LIVE_URL).catch(function(){return null;}),getJson(WEEKLY_URL).catch(function(){return null;})]).then(function(res){
var rows=parseCsv(res[0]), live=res[1]||{}, weekly=res[2]||{}, latest=live.latest||{}, weeklyRows=weekly.rows||[], latestWeek=weekly.latest_week||weeklyRows[weeklyRows.length-1]||{};
draw(rows); drawWeekly(weeklyRows);
txt("frequency-latest", latest.frequency_hz!=null?Number(latest.frequency_hz).toFixed(3):rows.length?Number(rows[rows.length-1].hz).toFixed(3):"—");
txt("frequency-records", String(live.record_count||rows.length||0));
txt("frequency-window", (live.window_hours||24)+" hours");
txt("frequency-minmax", live.min_hz!=null&&live.max_hz!=null?Number(live.min_hz).toFixed(3)+" to "+Number(live.max_hz).toFixed(3)+" Hz":"—");
txt("frequency-updated", live.updated_utc?"Updated: "+timeLabel(live.updated_utc):"Awaiting frequency update.");
txt("frequency-weekly-count", String(weekly.record_count||weeklyRows.length||0));
txt("frequency-weekly-avg", latestWeek.avg_hz!=null?Number(latestWeek.avg_hz).toFixed(4)+" Hz":"—");
txt("frequency-weekly-dev", latestWeek.largest_deviation_hz!=null?Number(latestWeek.largest_deviation_hz).toFixed(4)+" Hz":"—");
txt("frequency-weekly-health", latestWeek.data_health||weekly.health||"—");
});
}
window.addEventListener("resize", refresh);
refresh(); setInterval(refresh, REFRESH_MS);
})();Live App
A JavaScript file in GlobalGrid2050 that loads frequency module (`loadFrequencyModule`).
renderglobalgrid2050 / uk_energy_tracking_v5/live-app.js · lines 1–67 of 67 · Not reached from any entry point (candidate for review) · pattern ensureSummaryPanel (shared by 2 files)
- What it does
- It draws its content. Defines ensureV6Notice, ensureSummaryStyle, ensureSummaryPanel, loadFrequencyModule, refresh. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage upstream_foresight (topic 'markets-data'): 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.
- What it achieves
- It loads frequency module (`loadFrequencyModule`) and is built from the ensure v6 notice helper (`ensureV6Notice`) and the ensure summary style helper (`ensureSummaryStyle`). V5 live tracker app boot and refresh loop. It responds to change events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · uk_energy_tracking_v5 · script
- Uses
- Frequency History UI (script src)
- Used by
- none found
- Produces
- ensureV6Notice, ensureSummaryStyle, ensureSummaryPanel, loadFrequencyModule, refresh
- Defines here
- ensureV6Notice, ensureSummaryStyle, ensureSummaryPanel, loadFrequencyModule, refresh
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v5/live-app.js:1-67 · blob ef7194f4ec73ea49b4cf71960fa5a9bdb9fa3ab8 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: unreached_review
// V5 live tracker app boot and refresh loop. Load last.
function ensureV6Notice(){
if(document.getElementById('v5-v6-notice')) return;
var s=document.createElement('style');
s.id='v5-v6-notice-style';
s.textContent='\n.v5-v6-notice{border:1px solid rgba(0,255,255,.45);background:rgba(0,255,255,.055);border-radius:6px;padding:12px 14px;margin:14px 0;color:#f5f7fb;font-family:"Courier New",monospace;line-height:1.45;box-shadow:0 0 14px rgba(0,255,255,.10)}\n.v5-v6-notice strong{color:#00ffff;text-transform:uppercase;letter-spacing:.12em;display:block;margin-bottom:4px}\n.v5-v6-notice a{color:#0 … [line shortened here: 426 characters; full line on GitHub]
document.head.appendChild(s);
var grid=document.getElementById('scada-grid');
if(!grid) return;
var note=document.createElement('div');
note.id='v5-v6-notice';
note.className='v5-v6-notice';
note.innerHTML='<strong>Modular V6 now available</strong>V5 remains live for reference. The modular development build is now <a href="/uk_energy_tracking_v6/">UK Live Grid Tracker V6</a>.';
grid.insertBefore(note,grid.firstChild);
}
function ensureSummaryStyle(){
if(document.getElementById('v5-live-summary-style')) return;
var s=document.createElement('style');
s.id='v5-live-summary-style';
s.textContent='\n.scada-gauges{display:none!important;}\n.scada-live-summary{border:1px solid var(--gg-cyan,#00ffff);background:rgba(0,255,255,.04);border-radius:6px;padding:18px 16px;margin:18px 0 24px;box-shadow:0 0 18px rgba(0,255,255,.08);font-family:"Courier New",monospace;}\n.scada-summary-title{color:var(--gg-cyan,#00ffff);text-transform:uppercase;letter-spacing:.16em;font-size:13px;margi … [line shortened here: 1,302 characters; full line on GitHub]
document.head.appendChild(s);
}
function ensureSummaryPanel(){
ensureV6Notice();
ensureSummaryStyle();
var existing=document.getElementById('scada-live-summary');
if(existing) return existing;
var gauges=document.querySelector('.scada-gauges');
var panel=document.createElement('section');
panel.id='scada-live-summary';
panel.className='scada-live-summary';
panel.innerHTML='<div class="scada-summary-title">Live electricity snapshot</div>'+
'<div class="scada-summary-grid">'+
'<div><span>Demand</span><strong id="summary-demand">—</strong><em>GW</em></div>'+
'<div><span>Price</span><strong id="summary-price">—</strong><em>£/MWh</em></div>'+
'<div><span>Carbon</span><strong id="summary-carbon">—</strong><em>g/kWh</em></div>'+
'</div>'+
'<div class="scada-summary-time" id="summary-timestamps">Awaiting source timestamps.</div>';
if(gauges&&gauges.parentNode){gauges.parentNode.insertBefore(panel,gauges);}
else{document.getElementById('scada-grid').appendChild(panel);}
return panel;
}
function loadFrequencyModule(){
if(document.getElementById('frequency-history-ui-script')) return;
var script=document.createElement('script');
script.id='frequency-history-ui-script';
script.src='/uk_energy_tracking_v5/frequency-history-ui.js?v=20260528b';
document.body.appendChild(script);
}
function refresh(){
Promise.all([getJSON(ENERGY),getJSON(PRICE),getJSON(OIL),getJSON(OIL_HISTORY),getJSON(FUEL),getJSON(EV_PRICES)]).then(function(res){
var e=res[0]||{}, p=res[1]||{}, oil=res[2]||{}, hist=res[3], fuel=res[4]||{}, ev=res[5]||{};
ensureSummaryPanel();
renderGauge("demand", e.demandGW); renderGauge("price", p.priceGBPperMWh); renderGauge("carbon", carbonValue(p));
if(e.mix) renderMix(e.mix); renderCommodities(oil,fuel); renderEvPrices(ev); if(hist) drawOilTrend(hist);
var latest=latestIso(e.updated,p.updated,oil.updated);
setText("summary-demand",e.demandGW==null?"—":fmt(e.demandGW,2));
setText("summary-price",p.priceGBPperMWh==null?"—":fmt(p.priceGBPperMWh,2));
setText("summary-carbon",carbonValue(p)==null?"—":Math.round(carbonValue(p)));
setText("summary-timestamps",latest?"Updated: "+dateLabel(latest)+" · energy "+timeLabel(e.updated)+" · price "+timeLabel(p.updated)+" · commodities "+timeLabel(oil.updated):"Awaiting source timestamps.");
var s=document.getElementById("scada-status");
if(s){s.textContent="";s.style.display="none";}
});
}
var oilRange=document.getElementById("oil-range");
if(oilRange) oilRange.addEventListener("change", function(){ getJSON(OIL_HISTORY).then(drawOilTrend); });
parseMarketInputs(); ensureV6Notice(); ensureSummaryPanel(); loadFrequencyModule(); refresh(); setInterval(refresh, POLL);Live Config
A JavaScript file in GlobalGrid2050 covering live grid energy, live grid price, live oil prices and oil price history.
otherglobalgrid2050 / uk_energy_tracking_v5/live-config.js · lines 1–7 of 7 · Not reached from any entry point (candidate for review)
- Why it exists in the grid workflow
- Domain stage upstream_foresight (topic 'markets-data'): 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.
- Inputs & outputs
- In: JSON file live_grid_energy.json; JSON file live_grid_price.json; JSON file live_oil_prices.json; GeoJSON file oil_price_history.geojson; JSON file live_uk_fuel_prices.json; JSON file ev_charging_prices.json.
- What it achieves
- V5 live tracker config.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · uk_energy_tracking_v5 · script
- Uses
- none found
- Used by
- none found
- 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
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v5/live-config.js:1-7 · blob 9d5d0b8f926465de7be3b8fea82e268800452f2a · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: unknown · effects: none found · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: unreached_review
// V5 live tracker config. Load first.
var ENERGY="/uk_energy_tracking_v5/live_grid_energy.json", PRICE="/uk_energy_tracking_v5/live_grid_price.json", OIL="/uk_energy_tracking_v5/live_oil_prices.json", OIL_HISTORY="/uk_energy_tracking_v5/oil_price_history.geojson", FUEL="/uk_energy_tracking_v5/live_uk_fuel_prices.json", EV_PRICES="/uk_energy_tracking_v5/ev_charging_prices.json", POLL=5*60*1000;
var GAUGES={
demand:{min:0,max:45,unit:"Gigawatts (GW)",colour:"#00ffff"},
price:{min:-50,max:250,unit:"Pounds per Megawatt hour (£/MWh)",colour:"#ff00e6"},
carbon:{min:0,max:400,unit:"Grams per Kilowatt hour (g/kWh)",colour:"#00ff88"}
};Live Gauges
A JavaScript file in GlobalGrid2050 that renders mix (`renderMix`). It renders gauge (`renderGauge`), renders mix (`renderMix`) and gets JSON (`getJSON`).
renderglobalgrid2050 / uk_energy_tracking_v5/live-gauges.js · lines 1–25 of 25 · Not reached from any entry point (candidate for review) · pattern carbonValue (shared by 2 files)
- What it does
- It draws its content. Defines 9 functions or classes, including renderGauge, renderMix, ageMin, timeLabel, dateLabel. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage upstream_foresight (topic 'markets-data'): 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.
- What it achieves
- V5 live tracker gauges and generation mix rendering.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · uk_energy_tracking_v5 · script
- Uses
- none found
- Used by
- none found
- Produces
- renderGauge, renderMix, ageMin, timeLabel, dateLabel, latestIso, carbonValue, getJSON, setText
- Defines here
- renderGauge, renderMix, ageMin, timeLabel, dateLabel, latestIso, carbonValue, getJSON, setText
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v5/live-gauges.js:1-25 · blob ce0b0dba25cdc375f1cf33765f8db8ae6e3642e1 · 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
// V5 live tracker gauges and generation mix rendering.
function renderGauge(name,value){
var cfg=GAUGES[name], svg=document.querySelector('[data-gauge="'+name+'"]'); if(!svg) return;
var p=pct(value,cfg.min,cfg.max), end=-90+(180*p);
var display=value===null||value===undefined||isNaN(value)?"—":(name==="carbon"?Math.round(value):fmt(value, name==="price"?0:2));
svg.innerHTML='<path class="scada-gauge-bg" d="'+arcPath(30,115,80,-90,90)+'"></path>'+
'<path class="scada-gauge-fill" style="color:'+cfg.colour+';stroke:'+cfg.colour+'" d="'+arcPath(30,115,80,-90,end)+'"></path>'+
'<text class="scada-gauge-value" x="110" y="94">'+display+'</text>'+
'<text class="scada-gauge-unit" x="110" y="120">'+cfg.unit+'</text>';
}
function renderMix(mix){
var w=document.getElementById("scada-mix"); if(!Array.isArray(mix)){return;}
w.innerHTML=mix.map(function(r){
var width=Math.max(0,Math.min(100,Math.abs(r.pct)));
return '<div class="scada-mini"><div class="scada-mini-top"><div class="scada-mini-name">'+r.label+'</div><div class="scada-mini-value">'+fmt(r.gw)+' Gigawatts (GW) · '+fmt(r.pct)+'%</div></div>'+
'<div class="scada-mini-track"><div class="scada-mini-fill" style="width:'+width+'%;background:'+r.color+';box-shadow:0 0 10px '+r.color+'"></div></div></div>';
}).join("");
}
function ageMin(iso){return iso?(Date.now()-new Date(iso).getTime())/60000:Infinity;}
function timeLabel(iso){return iso?new Date(iso).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit"}):"Awaiting feed";}
function dateLabel(iso){return iso?new Date(iso).toLocaleDateString("en-GB",{weekday:"short",day:"2-digit",month:"short",year:"numeric"}):"";}
function latestIso(a,b,c){ var arr=[a,b,c].filter(Boolean).sort(function(x,y){return new Date(y)-new Date(x)}); return arr[0]||null; }
function carbonValue(p){ return p.carbonGperKWh==null ? p.carbonForecast : p.carbonGperKWh; }
function getJSON(u){return fetch(u+"?t="+Date.now(),{cache:"no-store"}).then(function(r){if(!r.ok)throw 0;return r.json();}).catch(function(){return null;});}
function setText(id,val){ var el=document.getElementById(id); if(el) el.textContent=val; }Live Helpers
A JavaScript file in GlobalGrid2050 that works with arc path (`arcPath`). It is built from the fmt step (`fmt`), the pct step (`pct`) and the arc path helper (`arcPath`).
transformglobalgrid2050 / uk_energy_tracking_v5/live-helpers.js · lines 1–9 of 9 · Not reached from any entry point (candidate for review) · pattern arcPath (shared by 2 files)
- What it does
- It calculates its inputs. Defines fmt, pct, arcPath.
- Why it exists in the grid workflow
- Domain stage upstream_foresight (topic 'markets-data'): 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.
- What it achieves
- V5 live tracker helpers. Depends on config.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · uk_energy_tracking_v5 · script
- Uses
- none found
- Used by
- none found
- Produces
- fmt, pct, arcPath
- Defines here
- fmt, pct, arcPath
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v5/live-helpers.js:1-9 · blob 89b4b663097577d4c110469634be39064cc64dda · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: duplicate_candidate
// V5 live tracker helpers. Depends on config.
function fmt(n,dp){return (n===null||n===undefined||isNaN(n))?"—":Number(n).toLocaleString("en-GB",{minimumFractionDigits:dp==null?2:dp,maximumFractionDigits:dp==null?2:dp});}
function pct(n,min,max){ if(n===null||n===undefined||isNaN(n)) return 0; return Math.max(0,Math.min(1,(Number(n)-min)/(max-min))); }
function arcPath(cx,cy,r,start,end){
var s=(start-90)*Math.PI/180, e=(end-90)*Math.PI/180;
var x1=cx+r*Math.cos(s), y1=cy+r*Math.sin(s), x2=cx+r*Math.cos(e), y2=cy+r*Math.sin(e);
var large=end-start<=180?0:1;
return "M "+x1+" "+y1+" A "+r+" "+r+" 0 "+large+" 1 "+x2+" "+y2;
}Live Oil Chart
A JavaScript file in GlobalGrid2050 that draws oil trend (`drawOilTrend`), binds oil tooltip (`bindOilTooltip`) and reads inputs for oil range. It draws oil trend (`drawOilTrend`) and binds oil tooltip (`bindOilTooltip`).
renderglobalgrid2050 / uk_energy_tracking_v5/live-oil-chart.js · lines 1–97 of 97 · Not reached from any entry point (candidate for review) · pattern bindOilTooltip (shared by 2 files)
- What it does
- It draws its content. Defines 8 functions or classes, including rangeCutoff, oilStats, drawOilTrend, x, line. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage upstream_foresight (topic 'markets-data'): 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.
- Inputs & outputs
- Out: canvas drawing.
- What it achieves
- V5 live tracker oil history chart. It responds to mousemove, touchmove and mouseleave events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · uk_energy_tracking_v5 · script
- Uses
- none found
- Used by
- none found
- Produces
- rangeCutoff, oilStats, drawOilTrend, x, line, bindOilTooltip, show, hide
- Defines here
- rangeCutoff, oilStats, drawOilTrend, x, line, bindOilTooltip, show, hide
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v5/live-oil-chart.js:1-97 · blob 984a002b5167eb170c0b91eb5ba0d530e4a4902c · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: duplicate_candidate
// V5 live tracker oil history chart.
var oilChartState = { rows: [], x: null, y: null, canvas: null, activeIndex: null, min: 0, max: 0, pad: 54 };
function rangeCutoff(range){
if(range === "all") return null;
var d = new Date();
if(range === "7d") d.setDate(d.getDate()-7);
else if(range === "1m") d.setMonth(d.getMonth()-1);
else if(range === "3m") d.setMonth(d.getMonth()-3);
else if(range === "6m") d.setMonth(d.getMonth()-6);
else if(range === "9m") d.setMonth(d.getMonth()-9);
else if(range === "1y") d.setFullYear(d.getFullYear()-1);
else if(range === "5y") d.setFullYear(d.getFullYear()-5);
else if(range === "10y") d.setFullYear(d.getFullYear()-10);
else if(range === "25y") d.setFullYear(d.getFullYear()-25);
return d;
}
function oilStats(rows){
var vals=[]; rows.forEach(function(p){ if(p.brentUSDperBarrel) vals.push(p.brentUSDperBarrel); if(p.wtiUSDperBarrel) vals.push(p.wtiUSDperBarrel); });
var el=document.getElementById("oil-stats"); if(!el) return;
if(!vals.length){ el.innerHTML=""; return; }
var high=Math.max.apply(null,vals), low=Math.min.apply(null,vals), avg=vals.reduce(function(a,b){return a+b;},0)/vals.length;
var variance=vals.reduce(function(a,b){return a+Math.pow(b-avg,2);},0)/vals.length;
var vol=avg?Math.sqrt(variance)/avg*100:0;
el.innerHTML = [
["High", "$"+fmt(high,2)], ["Low", "$"+fmt(low,2)], ["Average", "$"+fmt(avg,2)], ["Volatility", fmt(vol,1)+"%"]
].map(function(x){return '<div class="oil-stat"><div class="oil-stat-label">'+x[0]+'</div><div class="oil-stat-value">'+x[1]+'</div></div>';}).join("");
}
function drawOilTrend(geo, activeIndex){
var canvas=document.getElementById("oil-trend-canvas"); if(!canvas||!geo||!Array.isArray(geo.features)) return;
var ctx=canvas.getContext("2d"), range=document.getElementById("oil-range").value;
var rows=geo.features.map(function(f){return f.properties||{};}).filter(function(p){return p.date&&(p.brentUSDperBarrel||p.wtiUSDperBarrel);});
var cutoff=rangeCutoff(range); if(cutoff) rows=rows.filter(function(p){return new Date(p.date)>=cutoff;});
var w=canvas.width,h=canvas.height,pad=54,rightPad=28;
ctx.clearRect(0,0,w,h); ctx.fillStyle="#070a10"; ctx.fillRect(0,0,w,h);
if(rows.length<2) { ctx.fillStyle="#a6adbb"; ctx.font="14px Courier New"; ctx.fillText("Waiting for oil history data", pad, 42); oilStats([]); return; }
var vals=[]; rows.forEach(function(p){ if(p.brentUSDperBarrel) vals.push(p.brentUSDperBarrel); if(p.wtiUSDperBarrel) vals.push(p.wtiUSDperBarrel); });
var min=Math.min.apply(null,vals), max=Math.max.apply(null,vals); if(max===min){max=min+1;}
function x(i){return pad+(i/(rows.length-1))*(w-pad-rightPad);} function y(v){return h-pad-((v-min)/(max-min))*(h-pad*1.85);}
ctx.strokeStyle="#252b36"; ctx.lineWidth=1;
ctx.fillStyle="#a6adbb"; ctx.font="16px Courier New";
for(var g=0;g<5;g++){
var value=max-(g*(max-min)/4), yy=y(value);
ctx.beginPath();ctx.moveTo(pad,yy);ctx.lineTo(w-rightPad,yy);ctx.stroke();
ctx.fillText("$"+fmt(value,0), 8, yy+4);
}
ctx.save();
ctx.translate(14, h/2 + 70);
ctx.rotate(-Math.PI/2);
ctx.fillStyle="#a6adbb";
ctx.font="11px Courier New";
ctx.fillText("US dollars per barrel (USD/bbl)", 0, 0);
ctx.restore();
function line(field,colour){
ctx.strokeStyle=colour;ctx.lineWidth=2;ctx.beginPath();var started=false;
rows.forEach(function(p,i){var v=p[field];if(!v)return; if(!started){ctx.moveTo(x(i),y(v));started=true;}else{ctx.lineTo(x(i),y(v));}});
ctx.stroke();
}
line("brentUSDperBarrel","#ff9900"); line("wtiUSDperBarrel","#00ffff");
ctx.fillStyle="#a6adbb"; ctx.font="12px Courier New";
ctx.fillText("Brent",pad,18); ctx.fillStyle="#ff9900"; ctx.fillRect(pad+46,10,18,4);
ctx.fillStyle="#a6adbb"; ctx.fillText("WTI",pad+78,18); ctx.fillStyle="#00ffff"; ctx.fillRect(pad+112,10,18,4);
var idx = Number.isFinite(activeIndex) ? Math.max(0, Math.min(rows.length-1, activeIndex)) : null;
if(idx !== null){
var xx=x(idx);
ctx.strokeStyle="rgba(255,255,255,.85)";
ctx.lineWidth=1.5;
ctx.beginPath(); ctx.moveTo(xx, pad*0.72); ctx.lineTo(xx, h-pad); ctx.stroke();
var p=rows[idx];
["brentUSDperBarrel","wtiUSDperBarrel"].forEach(function(field){
var v=p[field]; if(!v) return;
ctx.fillStyle = field==="brentUSDperBarrel" ? "#ff9900" : "#00ffff";
ctx.beginPath(); ctx.arc(xx, y(v), 4, 0, Math.PI*2); ctx.fill();
});
}
oilChartState={rows:rows,x:x,y:y,canvas:canvas,activeIndex:idx,min:min,max:max,pad:pad}; oilStats(rows); bindOilTooltip();
}
function bindOilTooltip(){
var canvas=document.getElementById("oil-trend-canvas"), tip=document.getElementById("oil-tooltip"); if(!canvas||!tip||canvas.__oilTipBound) return;
canvas.__oilTipBound=true;
function show(e){
var rect=canvas.getBoundingClientRect();
var clientX=(e.touches&&e.touches[0]?e.touches[0].clientX:e.clientX);
var px=(clientX-rect.left)*(canvas.width/rect.width);
var rows=oilChartState.rows||[]; if(!rows.length) return;
var pad=oilChartState.pad||54, rightPad=28;
var idx=Math.max(0,Math.min(rows.length-1,Math.round((px-pad)/(canvas.width-pad-rightPad)*(rows.length-1))));
drawOilTrend(window.__oilGeojsonCache, idx);
var p=rows[idx];
tip.innerHTML='<strong>'+p.date+'</strong><br>Brent: '+(p.brentUSDperBarrel?'$'+fmt(p.brentUSDperBarrel,2):'—')+' USD/bbl<br>WTI: '+(p.wtiUSDperBarrel?'$'+fmt(p.wtiUSDperBarrel,2):'—')+' USD/bbl';
tip.style.display='block'; tip.style.left=Math.min(rect.width-190,Math.max(8,clientX-rect.left+12))+'px'; tip.style.top='42px';
}
function hide(){ tip.style.display='none'; drawOilTrend(window.__oilGeojsonCache, null); }
canvas.addEventListener('mousemove',show); canvas.addEventListener('touchmove',show,{passive:true}); canvas.addEventListener('mouseleave',hide); canvas.addEventListener('touchend',hide);
}Live Transport
A JavaScript file in GlobalGrid2050 that renders commodities (`renderCommodities`) and metal card (`renderMetalCard`) and renders fuel breakdown (`renderFuelBreakdown`).
energy-dataglobalgrid2050 / uk_energy_tracking_v5/live-transport.js · lines 1–54 of 54 · Not reached from any entry point (candidate for review) · pattern renderFuelBreakdown (shared by 2 files)
- What it does
- It draws its content. Defines 7 functions or classes, including moneySymbol, fmtMoney, renderCommodities, renderMetalCard, renderFuelBreakdown. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage upstream_foresight (topic 'markets-data'): 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.
- What it achieves
- It renders commodities (`renderCommodities`), renders metal card (`renderMetalCard`) and renders fuel breakdown (`renderFuelBreakdown`). V5 live tracker commodity, road fuel and EV rendering.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · uk_energy_tracking_v5 · script
- Uses
- none found
- Used by
- none found
- Produces
- moneySymbol, fmtMoney, renderCommodities, renderMetalCard, renderFuelBreakdown, parseMarketInputs, renderEvPrices
- Defines here
- moneySymbol, fmtMoney, renderCommodities, renderMetalCard, renderFuelBreakdown, parseMarketInputs, renderEvPrices
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 uk_energy_tracking_v5/live-transport.js:1-54 · blob 20ba40cf0c9a14909ac49c2d729c1ec6a8e169f1 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: unreached_review
// V5 live tracker commodity, road fuel and EV rendering.
function moneySymbol(currency){
return currency==='GBP'?'£':(currency==='EUR'?'€':'$');
}
function fmtMoney(value,currency){
if(value==null || isNaN(value)) return '—';
return moneySymbol(currency)+Number(value).toLocaleString('en-GB',{maximumFractionDigits:0});
}
function renderCommodities(oil,fuel){
oil=oil||{}; fuel=fuel||{};
setText("brent-price", oil.brentUSDperBarrel==null?"—":"$"+fmt(oil.brentUSDperBarrel,2));
setText("wti-price", oil.wtiUSDperBarrel==null?"—":"$"+fmt(oil.wtiUSDperBarrel,2));
renderMetalCard("copper-price", "copper", oil);
renderMetalCard("aluminium-price", "aluminium", oil);
var latest=fuel.latest||{};
setText("petrol-price", latest.petrolPencePerLitre==null?"—":fmt(latest.petrolPencePerLitre,2)+"p");
setText("diesel-price", latest.dieselPencePerLitre==null?"—":fmt(latest.dieselPencePerLitre,2)+"p");
renderFuelBreakdown(oil, latest);
}
function renderMetalCard(id, metal, data){
var el=document.getElementById(id); if(!el) return;
var usd=data[metal+"USDperTonne"], eur=data[metal+"EURperTonne"], gbp=data[metal+"GBPperTonne"];
if(usd==null && eur==null && gbp==null){ el.textContent="—"; return; }
el.innerHTML='<span style="display:block">'+fmtMoney(usd,'USD')+' <span style="font-size:12px;color:#9aa3b6">USD/t</span></span>'+
'<span style="display:block;font-size:16px;margin-top:4px;color:#00ffff">'+fmtMoney(eur,'EUR')+' <span style="font-size:11px;color:#9aa3b6">EUR/t</span></span>'+
'<span style="display:block;font-size:16px;margin-top:2px;color:#f5f7fb">'+fmtMoney(gbp,'GBP')+' <span style="font-size:11px;color:#9aa3b6">GBP/t</span></span>';
}
function renderFuelBreakdown(oil, latest){
var el=document.getElementById("fuel-breakdown"); if(!el) return;
var brent=oil&&oil.brentUSDperBarrel, petrol=latest&&latest.petrolPencePerLitre;
var stamp=oil&&oil.updatedDisplayUTC ? " Commodity sync: "+oil.updatedDisplayUTC+"." : "";
if(brent==null || petrol==null){ el.textContent="Awaiting Brent crude and DESNZ fuel price feed."+stamp; return; }
var gbpUsd=(oil.fx&&oil.fx.gbpUSD)||1.27, litresPerBarrel=158.987, duty=52.95, vatRate=0.20;
var crudePpl=(Number(brent)/gbpUsd/litresPerBarrel)*100;
var preVat=Number(petrol)/(1+vatRate);
var vat=Number(petrol)-preVat;
var spread=preVat-duty-crudePpl;
el.innerHTML="Brent proxy: $"+fmt(brent,2)+"/bbl divided by FX "+fmt(gbpUsd,4)+" and 159 litres equals about "+fmt(crudePpl,1)+"p/l crude input. Petrol pump: "+fmt(petrol,2)+"p/l. VAT at 20%: "+fmt(vat,1)+"p/l. Fuel duty assumption: "+fmt(duty,2)+"p/l. Implied refining, logistics, wholesale and retail spread: "+fmt(spread,1)+"p/l. Week: "+(latest.week||"not stated")+"."+stamp;
}
function parseMarketInputs(){
getJSON(OIL).then(function(data){
data=data||{};
renderMetalCard("copper-price", "copper", data);
renderMetalCard("aluminium-price", "aluminium", data);
}).catch(function(){ setText("copper-price","—"); setText("aluminium-price","—"); });
}
function renderEvPrices(ev){
var ops=(ev&&ev.operators)||[];
var rapid=[], ultra=[];
ops.forEach(function(o){ if(o.rapidPencePerKWh!=null) rapid.push(Number(o.rapidPencePerKWh)); if(o.ultraRapidPencePerKWh!=null) ultra.push(Number(o.ultraRapidPencePerKWh)); });
if(rapid.length){ setText("ev-rapid-price", fmt(rapid.reduce(function(a,b){return a+b;},0)/rapid.length,1)+"p"); }
if(ultra.length){ setText("ev-ultra-price", fmt(ultra.reduce(function(a,b){return a+b;},0)/ultra.length,1)+"p"); }
}