In this section
- Price History Data energy-data · globalgrid2050 / uk_energy_tracking_v5/price-history-data.js lines 1–29
- Price History Fullscreen energy-data · globalgrid2050 / uk_energy_tracking_v5/price-history-fullscreen.js lines 1–38
- Price History Render energy-data · globalgrid2050 / uk_energy_tracking_v5/price-history-render.js lines 1–22
- Price History UI energy-data · globalgrid2050 / uk_energy_tracking_v5/price-history-ui.css lines 1–228
- Price History UI energy-data · globalgrid2050 / uk_energy_tracking_v5/price-history-ui.js lines 1–78
- Start V6 App interaction · globalgrid2050 / uk_energy_tracking_v6/app_bootstrap/start_v6_app/start_v6_app.js lines 1–14
- Build from Data Repo storage · globalgrid2050 / uk_energy_tracking_v6/derived/build_from_data_repo.py lines 1–186
Price History Data
A JavaScript file in GlobalGrid2050 that fetches electricity price history 4bucket decade. It loads captured (`loadCaptured`), loads annual (`loadAnnual`) and loads four bucket (`loadFourBucket`).
energy-dataglobalgrid2050 / uk_energy_tracking_v5/price-history-data.js · lines 1–29 of 29 · Not reached from any entry point (candidate for review) · pattern yearsBetween (shared by 3 files)
- What it does
- It fetches electricity price history 4bucket decade. Defines 11 functions or classes, including csvLine, loadCaptured, loadAnnual, loadFourBucket, yearsBetween. 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; JSON file electricity_price_history_4bucket_decade.json.
- What it achieves
- Defines `csvLine`, `loadCaptured`, `loadAnnual` and 8 more.
- 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
- csvLine, loadCaptured, loadAnnual, loadFourBucket, yearsBetween, periodDays, periodLabel, modeForDays, filterTimeMode, merge, loadFourBucketRange
- Defines here
- csvLine, loadCaptured, loadAnnual, loadFourBucket, yearsBetween, periodDays, periodLabel, modeForDays, filterTimeMode, merge, loadFourBucketRange
- 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/price-history-data.js:1-29 · blob 180eb3105af5d8fc7d1859bd5a4c205a74f7f251 · 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
window.V5PriceHistoryData = (function(){
var JSON_URL='/uk_energy_tracking_v5/electricity_price_history.json';
var FOUR_BUCKET_URL='/uk_energy_tracking_v5/electricity_price_history_4bucket_decade.json';
var ANNUAL_URL_BASE='/data/electricity/elexon_system_prices_';
var FIRST_YEAR=2016;
var ANNUAL_CACHE={};
var CAPTURE_CACHE=null;
var FOUR_BUCKET_CACHE=null;
var TODAY=new Date();
var MAX_DATE=new Date(Date.UTC(TODAY.getUTCFullYear(),TODAY.getUTCMonth(),TODAY.getUTCDate(),23,59,59));
var MIN_DATE=new Date(Date.UTC(FIRST_YEAR,0,1,0,0,0));
var MODES={HALFHOURLY:'halfhourly',FOUR_BUCKET:'4bucket'};
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. … [line shortened here: 880 characters; full line on GitHub]
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: 452 characters; full line on GitHub]
function loadCaptured(){if(CAPTURE_CACHE)return CAPTURE_CACHE;CAPTURE_CACHE=fetch(JSON_URL+'?t='+Date.now(),{cache:'no-store'}).then(function(r){return r.ok?r.json():{rows:[]}}).then(function(d){return norm(d.rows||[])}).catch(function(){return[]});return CAPTURE_CACHE}
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).then(norm).catch(function(){return[]});return ANNUAL_CACHE[year]}
function loadFourBucket(){if(FOUR_BUCKET_CACHE)return FOUR_BUCKET_CACHE;FOUR_BUCKET_CACHE=fetch(FOUR_BUCKET_URL+'?t='+Date.now(),{cache:'no-store'}).then(function(r){return r.ok?r.json():{rows:[]}}).then(function(d){return{rows:(d.rows||[]).map(function(r){return Object.assign({},r,{date:r.date})}),meta:d}}).catch(function(){return{rows:[],meta:{}}});return FOUR_BUCKET_CACHE}
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 periodDays(period){return {'7d':7,'30d':30,'3m':92,'6m':183,'1y':366,'5y':1827,'10y':3653}[period]||7}
function periodLabel(period){return {'7d':'1 week','30d':'1 month','3m':'3 months','6m':'6 months','1y':'1 year','5y':'5 years','10y':'10 years'}[period]||'1 week'}
function modeForDays(days){return days<=183?MODES.HALFHOURLY:MODES.FOUR_BUCKET}
function filterTimeMode(rows,timeMode){if(!timeMode||timeMode==='all')return rows;return rows.filter(function(r){var h=new Date(r.priceTimeUTC).getUTCHours(),day=h>=6&&h<18;return timeMode==='day'?day:!day})}
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||'V5 captured Elexon Market Index Price'}))});return norm(rows)}
function loadHalfHourly(start,end,timeMode){var years=yearsBetween(start,end);return Promise.all([loadCaptured()].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(sys,cap);var rows=all.filter(function(r){var t=new Date(r.priceTimeUTC);return t>=start&&t<=end});rows=filterTimeMode(rows,timeMode);return … [line shortened here: 535 characters; full line on GitHub]
function loadFourBucketRange(start,end){return loadFourBucket().then(function(d){var rows=d.rows.filter(function(r){var t=new Date(r.date+'T12:00:00Z');return t>=start&&t<=end});return{rows:rows,mode:MODES.FOUR_BUCKET,source:'V5 4 bucket daily aggregate',sourceRows:d.rows.length,loadedYears:[],meta:d.meta||{}}})}
function loadForWindow(win){var start=win.start,end=win.end,days=Math.max(1,Math.ceil((end-start)/86400000)),mode=modeForDays(days);if(mode===MODES.FOUR_BUCKET)return loadFourBucketRange(start,end).then(function(r){r.window=win;r.days=days;r.label=periodLabel(win.period);return r});return loadHalfHourly(start,end,win.timeMode).then(function(r){r.window=win;r.days=days;r.label=periodLabel(win.per … [line shortened here: 416 characters; full line on GitHub]
return {loadForWindow:loadForWindow,periodDays:periodDays,periodLabel:periodLabel,modeForDays:modeForDays,modes:MODES,FIRST_YEAR:FIRST_YEAR,MIN_DATE:MIN_DATE,MAX_DATE:MAX_DATE};
})();Price History Fullscreen
A JavaScript file in GlobalGrid2050 that refreshes after load (`refreshAfterLoad`) and draws on a canvas. It copies state (`copyState`) and refreshes after load (`refreshAfterLoad`).
energy-dataglobalgrid2050 / uk_energy_tracking_v5/price-history-fullscreen.js · lines 1–38 of 38 · Entry point · pattern fullMonth (shared by 2 files)
- What it does
- It draws its content. Defines 21 functions or classes, including $, fmt, fullDate, fullMonth, timeLabel. Side effects: changes the web page (DOM); reads or writes files.
- 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
- Out: canvas drawing.
- Downstream impact
- Used directly by 3 files: GlobalGrid2050 Patch V5 Chart Dynamic Annotations Workflow (globalgrid2050); GlobalGrid2050 Patch V5 Chart Overlap Controls Workflow (globalgrid2050); GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (globalgrid2050).
- What it achieves
- Defines `fmt`, `fullDate`, `fullMonth` and 17 more. It responds to DOMContentLoaded, keydown and resize events.
- Why it matters
- Run by GlobalGrid2050 Patch V5 Chart Dynamic Annotations Workflow, GlobalGrid2050 Patch V5 Chart Overlap Controls Workflow and GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow.
- Application
- globalgrid2050 · uk_energy_tracking_v5 · script
- Uses
- none found
- Used by
- run by GlobalGrid2050 Patch V5 Chart Dynamic Annotations Workflow (workflow run), run by GlobalGrid2050 Patch V5 Chart Overlap Controls Workflow (workflow run), run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (workflow run)
- Produces
- $, fmt, fullDate, fullMonth, timeLabel, axisLabel, modeText, minMax, niceStep, clamp, selectedPeriod, selectedStart
- Defines here
- $, fmt, fullDate, fullMonth, timeLabel, axisLabel, modeText, minMax, niceStep, clamp, selectedPeriod, selectedStart, stateMatchesControls, copyState, reloadIfNeeded, refreshAfterLoad, seasonName, seasonColor, extrema, open, close
- 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/price-history-fullscreen.js:1-38 · blob 5a5f8ca61b91a2c6d41b39b14ea6c3e5e1f45d37 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem · domain stage: hv_procurement · users: EPC_contractor, procurement_buyer · canonical: production_core
(function(){
var S={rows:[],meta:null};
var MINIMAL=false;
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 fullDate(t){return new Date(t).toLocaleDateString('en-GB',{day:'2-digit',month:'long',year:'numeric'})}
function fullMonth(t){return new Date(t).toLocaleDateString('en-GB',{month:'long',year:'numeric'})}
function timeLabel(t){return new Date(t).toLocaleTimeString('en-GB',{hour:'2-digit',minute:'2-digit'})}
function axisLabel(t,span){return span<=45*86400000?fullDate(t):fullMonth(t)}
function modeText(){var st=window.__v5PriceHistoryState||{},m=st.timeMode||'all';if((st.meta||{}).mode==='daily')return 'Daily high low average';if(m==='day')return 'Day 06 to 18 UTC';if(m==='night')return 'Night 18 to 06 UTC';return 'All hours'}
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.06;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 clamp(v,a,b){return Math.max(a,Math.min(b,v))}
function decimate(rows,limit){if(window.decimateRows)return window.decimateRows(rows,limit);if(!rows||rows.length<=limit)return rows||[];var out=[],bucket=Math.ceil(rows.length/limit);for(var i=0;i<rows.length;i+=bucket){var s=rows.slice(i,i+bucket),hi=s[0],lo=s[0];s.forEach(function(r){if(Number(r.priceGBPperMWh)>Number(hi.priceGBPperMWh))hi=r;if(Number(r.priceGBPperMWh)<Number(lo.priceGBPperMWh) … [line shortened here: 633 characters; full line on GitHub]
function selectedPeriod(){var p=$('price-history-period');return p&&p.value?p.value:((S.meta&&S.meta.period)||((window.__v5PriceHistoryState&&window.__v5PriceHistoryState.meta&&window.__v5PriceHistoryState.meta.period)||'7d'))}
function selectedStart(){var s=$('price-history-start');return s&&s.value?s.value:null}
function stateMatchesControls(){var st=window.__v5PriceHistoryState||{},m=st.meta||{},p=selectedPeriod(),start=selectedStart();if(!m.period||m.period!==p)return false;if(start&&m.start){try{return m.start.toISOString().slice(0,10)===start}catch(e){return false}}return !!(st.visible&&st.visible.length)}
function copyState(){var st=window.__v5PriceHistoryState||{};if(st.visible&&st.visible.length)S.rows=st.visible;if(st.meta)S.meta=st.meta;if(S.meta&&!S.meta.period)S.meta.period=selectedPeriod();return st}
function reloadIfNeeded(){var c=window.__v5PriceHistoryControls;if(c&&!stateMatchesControls())c.load();copyState()}
function refreshAfterLoad(){[80,350,900,1800,3000].forEach(function(ms){setTimeout(function(){copyState();draw()},ms)})}
function seasonName(t){var m=new Date(t).getUTCMonth()+1;if(m===12||m<=2)return'Winter';if(m>=3&&m<=5)return'Spring';if(m>=6&&m<=8)return'Summer';return'Autumn'}
function seasonColor(t){var s=seasonName(t);if(s==='Winter')return'#00ffff';if(s==='Spring')return'#00ff88';if(s==='Summer')return'#ffcc00';return'#c79245'}
function drawSeasonKey(g,q,pad,isLandscape){if(MINIMAL)return;var items=[['Winter','#00ffff'],['Spring','#00ff88'],['Summer','#ffcc00'],['Autumn','#c79245']],x=pad.left,y=(isLandscape?62:104)*q;g.save();g.font=(isLandscape?8.5:9.5)*q+'px Courier New';items.forEach(function(it){g.fillStyle=it[1];g.shadowColor=it[1];g.shadowBlur=5*q;g.fillRect(x,y-7*q,8*q,8*q);g.shadowBlur=0;g.fillStyle='#9aa3b6';g. … [line shortened here: 464 characters; full line on GitHub]
function drawDailyKey(g,q,pad,isLandscape){if(MINIMAL)return;var items=[['Average','#00ffff'],['High','#ffcc00'],['Low','#ff3333']],x=pad.left,y=(isLandscape?62:104)*q;g.save();g.font=(isLandscape?8.5:9.5)*q+'px Courier New';items.forEach(function(it){g.fillStyle=it[1];g.shadowColor=it[1];g.shadowBlur=5*q;g.fillRect(x,y-7*q,8*q,8*q);g.shadowBlur=0;g.fillStyle='#9aa3b6';g.fillText(it[0],x+12*q,y);x … [line shortened here: 438 characters; full line on GitHub]
function drawSeasonLine(g,lineRows,X,Y,q,isLandscape){g.save();g.lineWidth=(isLandscape?1.9:2.2)*q;g.lineCap='round';g.lineJoin='round';for(var i=1;i<lineRows.length;i++){var a=lineRows[i-1],b=lineRows[i],col=seasonColor(b.priceTimeUTC);g.strokeStyle=col;g.shadowColor=col;g.shadowBlur=4*q;g.beginPath();g.moveTo(X(a),Y(Number(a.priceGBPperMWh)));g.lineTo(X(b),Y(Number(b.priceGBPperMWh)));g.stroke() … [line shortened here: 413 characters; full line on GitHub]
function drawDailyLines(g,rows,X,Y,q){var series=[['average','#00ffff',2.2],['high','#ffcc00',1.5],['low','#ff3333',1.5]];series.forEach(function(item){var k=item[0],col=item[1],lw=item[2];g.save();g.strokeStyle=col;g.shadowColor=col;g.shadowBlur=4*q;g.lineWidth=lw*q;g.lineCap='round';g.lineJoin='round';var started=false;rows.forEach(function(r){if(r[k]==null||isNaN(Number(r[k])))return;var x=X(r) … [line shortened here: 763 characters; full line on GitHub]
function injectStyle(){if($('v5-fullscreen-repair-controls'))return;var s=document.createElement('style');s.id='v5-fullscreen-repair-controls';s.textContent='.price-history-fullscreen-overlay.open{display:block!important}.price-history-fullscreen-overlay{position:fixed!important;inset:0!important;z-index:99999!important;background:#000!important;padding:0!important;overflow:hidden!important}.price … [line shortened here: 1,888 characters; full line on GitHub]
function ensureControls(){injectStyle();var o=$('price-history-fullscreen-overlay');if(!o)return;['fs-bottom-stack','fs-mini','fs-period','fs-close2'].forEach(function(id){var el=$(id);if(el)el.remove()});if(!$('fs-prev')){var left=document.createElement('button');left.id='fs-prev';left.className='fs-nav left';left.type='button';left.textContent='‹';o.appendChild(left)}if(!$('fs-next')){var right= … [line shortened here: 816 characters; full line on GitHub]
function bindControls(){var c=window.__v5PriceHistoryControls;if(!c)return;var prev=$('fs-prev'),next=$('fs-next'),closeBtn=$('fs-close-lite'),trendBtn=$('fs-trend-lite');if(closeBtn)closeBtn.onclick=close;if(trendBtn)trendBtn.onclick=function(){MINIMAL=!MINIMAL;trendBtn.textContent=MINIMAL?'Events':'Trend';draw()};if(prev)prev.onclick=function(){copyState();var days=Math.max(1,c.periodDays(select … [line shortened here: 745 characters; full line on GitHub]
function drawAxes(g,w,h,q,m,t0,t1,pad){var st=niceStep(m.hi-m.lo),start=Math.ceil(m.lo/st)*st,span=t1-t0;g.lineWidth=q;g.font=11*q+'px Courier New';g.textAlign='left';for(var val=start;val<=m.hi+st*.5;val+=st){var y=pad.top+((m.hi-val)/(m.hi-m.lo))*(h-pad.top-pad.bottom);g.strokeStyle=val===0?'rgba(255,51,51,.98)':'rgba(255,255,255,.16)';g.lineWidth=val===0?2*q:q;g.beginPath();g.moveTo(pad.left,y) … [line shortened here: 860 characters; full line on GitHub]
function extrema(rows){if(!rows.length)return null;var daily=(S.meta||{}).mode==='daily';var hi=rows[0],lo=rows[0];rows.forEach(function(r){if(Number(daily?r.high:r.priceGBPperMWh)>Number(daily?hi.high:hi.priceGBPperMWh))hi=r;if(Number(daily?r.low:r.priceGBPperMWh)<Number(daily?lo.low:lo.priceGBPperMWh))lo=r});return{hi:hi,lo:lo,daily:daily}}
function eventText(g,label,r,q,x,y,align,daily){g.save();var val=daily?(label==='HIGH'?r.high:r.low):r.priceGBPperMWh;var date=daily?(r.date+' '+(label==='HIGH'?(r.highAt||''):(r.lowAt||''))):(fullDate(r.priceTimeUTC)+' '+timeLabel(r.priceTimeUTC));g.fillStyle='#ff3333';g.shadowColor='rgba(0,255,255,.75)';g.shadowBlur=8*q;g.textAlign=align;g.font='bold '+10.5*q+'px Courier New';g.fillText(label+' … [line shortened here: 508 characters; full line on GitHub]
function drawEvents(g,rows,X,Y,q,w,h,pad){if(MINIMAL)return;var e=extrema(rows);if(!e)return;var daily=e.daily;var hx=X(e.hi),hy=Y(Number(daily?e.hi.high:e.hi.priceGBPperMWh)),lx=X(e.lo),ly=Y(Number(daily?e.lo.low:e.lo.priceGBPperMWh));g.save();g.fillStyle='#ff3333';g.shadowColor='rgba(0,255,255,.9)';g.shadowBlur=9*q;g.beginPath();g.arc(hx,hy,4.6*q,0,Math.PI*2);g.fill();g.beginPath();g.arc(lx,ly,4 … [line shortened here: 982 characters; full line on GitHub]
function draw(){var c=$('price-history-fullscreen-canvas');if(!c)return;var q=devicePixelRatio||1,cssW=window.innerWidth,cssH=window.innerHeight;c.width=Math.max(320,Math.floor(cssW*q));c.height=Math.max(320,Math.floor(cssH*q));var g=c.getContext('2d'),w=c.width,h=c.height,isLandscape=w>h;var pad=MINIMAL?{left:72*q,right:62*q,top:96*q,bottom:76*q}:{left:(isLandscape?92:86)*q,right:(isLandscape?72: … [line shortened here: 2,019 characters; full line on GitHub]
function open(){ensureControls();var o=$('price-history-fullscreen-overlay');if(!o)return;document.documentElement.classList.add('v5-chart-open');document.body.classList.add('v5-chart-open');o.classList.add('open');reloadIfNeeded();draw();refreshAfterLoad()}
function close(){var o=$('price-history-fullscreen-overlay');if(o)o.classList.remove('open');document.documentElement.classList.remove('v5-chart-open');document.body.classList.remove('v5-chart-open')}
document.addEventListener('DOMContentLoaded',function(){injectStyle();var b=$('price-history-fullscreen-btn'),c=$('price-history-fullscreen-close');if(b)b.onclick=open;if(c)c.onclick=close;document.addEventListener('keydown',function(e){if(e.key==='Escape')close()});window.addEventListener('resize',function(){if($('price-history-fullscreen-overlay')&&$('price-history-fullscreen-overlay').classList … [line shortened here: 443 characters; full line on GitHub]
})();Price History Render
A JavaScript file in GlobalGrid2050 that draws season (`drawSeasonKey`) and bucket legend (`drawBucketLegend`). It draws season key (`drawSeasonKey`) and draws bucket legend (`drawBucketLegend`).
energy-dataglobalgrid2050 / uk_energy_tracking_v5/price-history-render.js · lines 1–22 of 22 · Not reached from any entry point (candidate for review) · pattern fullMonth (shared by 2 files)
- What it does
- It draws its content. Defines 13 functions or classes, including fmt, fullDate, fullMonth, timeLabel, axisLabel. 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.
- Inputs & outputs
- Out: canvas drawing.
- What it achieves
- Defines `fmt`, `fullDate`, `fullMonth` and 10 more.
- 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, fullDate, fullMonth, timeLabel, axisLabel, minMax, niceStep, seasonName, seasonColor, extrema, drawSeasonKey, bucketSeries
- Defines here
- fmt, fullDate, fullMonth, timeLabel, axisLabel, minMax, niceStep, seasonName, seasonColor, extrema, drawSeasonKey, bucketSeries, drawBucketLegend
- 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/price-history-render.js:1-22 · blob 4004a85028a5aaaaedb64fcc1b8286b565a71239 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom · domain stage: hv_procurement · users: EPC_contractor, procurement_buyer · canonical: unreached_review
window.V5PriceHistoryRender = (function(){
function fmt(n,d){return n==null||isNaN(n)?'—':Number(n).toLocaleString('en-GB',{minimumFractionDigits:d,maximumFractionDigits:d})}
function fullDate(t){return new Date(t).toLocaleDateString('en-GB',{day:'2-digit',month:'long',year:'numeric'})}
function fullMonth(t){return new Date(t).toLocaleDateString('en-GB',{month:'long',year:'numeric'})}
function timeLabel(t){return new Date(t).toLocaleTimeString('en-GB',{hour:'2-digit',minute:'2-digit'})}
function axisLabel(t,span){return span<=45*86400000?fullDate(t):fullMonth(t)}
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.06;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 decimateRows(rows,limit){if(!rows||rows.length<=limit)return rows||[];var out=[],bucket=Math.ceil(rows.length/limit);for(var i=0;i<rows.length;i+=bucket){var slice=rows.slice(i,i+bucket),hi=slice[0],lo=slice[0];slice.forEach(function(r){if(Number(r.priceGBPperMWh)>Number(hi.priceGBPperMWh))hi=r;if(Number(r.priceGBPperMWh)<Number(lo.priceGBPperMWh))lo=r});if(new Date(lo.priceTimeUTC)<new … [line shortened here: 593 characters; full line on GitHub]
function seasonName(t){var m=new Date(t).getUTCMonth()+1;if(m===12||m<=2)return'Winter';if(m>=3&&m<=5)return'Spring';if(m>=6&&m<=8)return'Summer';return'Autumn'}
function seasonColor(t){var s=seasonName(t);if(s==='Winter')return'#00ffff';if(s==='Spring')return'#00ff88';if(s==='Summer')return'#ffcc00';return'#c79245'}
function extrema(rows){if(!rows||!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 drawAxes(g,w,h,q,m,t0,t1,pad){var step=niceStep(m.hi-m.lo),start=Math.ceil(m.lo/step)*step,span=t1-t0;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.moveT … [line shortened here: 878 characters; full line on GitHub]
function drawSeasonKey(g,q,w,pad){var items=[['Winter','#00ffff'],['Spring','#00ff88'],['Summer','#ffcc00'],['Autumn','#c79245']],x=pad.left,y=pad.top-24*q;g.save();g.font=9*q+'px Courier New';items.forEach(function(it){g.fillStyle=it[1];g.shadowColor=it[1];g.shadowBlur=4*q;g.fillRect(x,y-7*q,8*q,8*q);g.shadowBlur=0;g.fillStyle='#9aa3b6';g.fillText(it[0],x+12*q,y);x+=58*q});g.restore()}
function drawHalfHourlyLine(g,rows,X,Y,q,w){var lineRows=decimateRows(rows,Math.max(900,Math.floor((w/q)*1.8)));g.save();g.lineWidth=2.1*q;g.lineCap='round';g.lineJoin='round';for(var i=1;i<lineRows.length;i++){var a=lineRows[i-1],b=lineRows[i],col=seasonColor(b.priceTimeUTC);g.strokeStyle=col;g.shadowColor=col;g.shadowBlur=5*q;g.beginPath();g.moveTo(X(a),Y(Number(a.priceGBPperMWh)));g.lineTo(X( … [line shortened here: 455 characters; full line on GitHub]
function drawEvents(g,rows,X,Y,q,w,h,pad){var e=extrema(rows);if(!e)return;var hx=X(e.hi),hy=Y(Number(e.hi.priceGBPperMWh)),lx=X(e.lo),ly=Y(Number(e.lo.priceGBPperMWh));g.save();g.fillStyle='#ff3333';g.shadowColor='rgba(0,255,255,.85)';g.shadowBlur=8*q;g.beginPath();g.arc(hx,hy,4.5*q,0,Math.PI*2);g.fill();g.beginPath();g.arc(lx,ly,4.5*q,0,Math.PI*2);g.fill();g.restore();g.save();g.fillStyle='#ff … [line shortened here: 800 characters; full line on GitHub]
function bucketSeries(rows){var out=[];(rows||[]).forEach(function(r){['night','morning','midday','evening'].forEach(function(k){if(r[k]!=null&&!isNaN(Number(r[k])))out.push(Number(r[k]))})});return out}
function drawFourBucket(g,rows,X,Y,q){var keys=[['night','#00ffff','Night'],['morning','#00ff88','Morning'],['midday','#ffcc00','Midday'],['evening','#ff00e6','Evening']];keys.forEach(function(item){var k=item[0],col=item[1];g.save();g.strokeStyle=col;g.shadowColor=col;g.shadowBlur=4*q;g.lineWidth=1.8*q;g.lineCap='round';g.lineJoin='round';var open=false;rows.forEach(function(r){if(r[k]==null||i … [line shortened here: 570 characters; full line on GitHub]
function drawBucketLegend(g,q,pad){var keys=[['Night','#00ffff'],['Morning','#00ff88'],['Midday','#ffcc00'],['Evening','#ff00e6']],x=pad.left,y=pad.top-24*q;g.save();g.font=9*q+'px Courier New';keys.forEach(function(it){g.fillStyle=it[1];g.fillRect(x,y-7*q,8*q,8*q);g.fillStyle='#9aa3b6';g.fillText(it[0],x+12*q,y);x+=70*q});g.restore()}
function draw(canvas,rows,meta,options){options=options||{};if(!canvas)return;var q=Math.min(window.devicePixelRatio||1,2),r=canvas.getBoundingClientRect(),cssW=options.fullscreen?window.innerWidth:(r.width||900),cssH=options.fullscreen?window.innerHeight:(r.height||360);canvas.width=Math.max(320,Math.floor(cssW*q));canvas.height=Math.max(320,Math.floor(cssH*q));var g=canvas.getContext('2d'),w=c … [line shortened here: 1,827 characters; full line on GitHub]
return {fmt:fmt,fullDate:fullDate,timeLabel:timeLabel,minMax:minMax,niceStep:niceStep,decimateRows:decimateRows,extrema:extrema,draw:draw};
})();Price History UI
A style sheet in GlobalGrid2050.
energy-dataglobalgrid2050 / uk_energy_tracking_v5/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_v5 · 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_v5/price-history-ui.css:1-228 · blob dd6a867b593b4b58ba5fd44d14a29f827e25f202 · 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; }
}
/* V5 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}
/* V5 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_v5/price-history-ui.js · lines 1–78 of 78 · Entry point · pattern syncScrollerFromStart (shared by 2 files)
- What it does
- It draws electricity price history daily decade and electricity price history 4bucket decade. Defines 38 functions or classes, including $, fmt, pence, dlab, slab. 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; JSON file electricity_price_history_daily_decade.json; JSON file electricity_price_history_4bucket_decade.json; form fields (user input). Out: canvas drawing.
- Downstream impact
- Used directly by 3 files: GlobalGrid2050 Patch V5 Chart Dynamic Annotations Workflow (globalgrid2050); GlobalGrid2050 Patch V5 Chart Overlap Controls Workflow (globalgrid2050); GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (globalgrid2050).
- What it achieves
- It loads JSON (`loadJson`), loads annual (`loadAnnual`) and syncs scroller start (`syncScrollerFromStart`). Defines `fmt`, `pence`, `dlab` and 34 more. It responds to click, DOMContentLoaded and change events.
- Why it matters
- Run by GlobalGrid2050 Patch V5 Chart Dynamic Annotations Workflow, GlobalGrid2050 Patch V5 Chart Overlap Controls Workflow and GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow.
- Application
- globalgrid2050 · uk_energy_tracking_v5 · script
- Uses
- none found
- Used by
- run by GlobalGrid2050 Patch V5 Chart Dynamic Annotations Workflow (workflow run), run by GlobalGrid2050 Patch V5 Chart Overlap Controls Workflow (workflow run), run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (workflow run)
- Produces
- $, fmt, pence, dlab, slab, tlab, axisLabel, ymd, set, timeModeLabel, csvLine, loadJson
- Defines here
- $, fmt, pence, dlab, slab, tlab, axisLabel, ymd, set, timeModeLabel, csvLine, loadJson, loadAnnual, yearsBetween, merge, periodDays, periodLabel, isDailyPeriod, isDayNightPeriod, totalScrollableDays, dateFromOffset, offsetFromDate, ensureYearOptions, syncScrollerFromStart, syncStartFromScroller, passesTimeMode, minMax, niceStep, seasonName, seasonColor
- 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/price-history-ui.js:1-78 · blob 67416d75b9deea333dfeaec25271d332517315ee · 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: production_core
(function(){
var JSON_URL='/uk_energy_tracking_v5/electricity_price_history.json';
var DAILY_URL='/uk_energy_tracking_v5/electricity_price_history_daily_decade.json';
var DAILY_FALLBACK_URL='/uk_energy_tracking_v5/electricity_price_history_4bucket_decade.json';
var ANNUAL_URL_BASE='/data/electricity/elexon_system_prices_';
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={}, DAILY_CACHE=null, CAPTURE_CACHE=null;
var pendingTimer=null;
var STATE={all:[],visible:[],meta:null,loadedYears:[],sourceRows:0,timeMode:'all',mode:'halfhourly'};
window.__v5PriceHistoryState=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 pence(n){return n==null||isNaN(n)?'—':fmt(Number(n)/10,2)}
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:'long',year:'numeric'})}
function tlab(t){return new Date(t).toLocaleTimeString('en-GB',{hour:'2-digit',minute:'2-digit'})}
function axisLabel(t,span){return span<=45*86400000?slab(t):new Date(t).toLocaleDateString('en-GB',{month:'long',year:'numeric'})}
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 'Day 06 to 18 UTC';if(STATE.timeMode==='night')return 'Night 18 to 06 UTC';return 'All hours'}
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(){if(CAPTURE_CACHE)return CAPTURE_CACHE;CAPTURE_CACHE=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[]});return CAPTURE_CACHE}
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 convert4Bucket(d){return (d.rows||[]).map(function(r){var vals=[r.night,r.morning,r.midday,r.evening].filter(function(v){return v!=null&&!isNaN(Number(v))}).map(Number);return{date:r.date,average:vals.length?Number((vals.reduce(function(a,b){return a+b},0)/vals.length).toFixed(2)):null,high:r.peakPrice!=null?Number(r.peakPrice):(vals.length?Math.max.apply(null,vals):null),highAt:r.peakAt| … [line shortened here: 494 characters; full line on GitHub]
function loadDaily(){if(DAILY_CACHE)return DAILY_CACHE;DAILY_CACHE=fetch(DAILY_URL+'?t='+Date.now(),{cache:'no-store'}).then(function(r){if(!r.ok)throw new Error('daily missing');return r.json()}).then(function(d){return d.rows||[]}).catch(function(){return fetch(DAILY_FALLBACK_URL+'?t='+Date.now(),{cache:'no-store'}).then(function(r){return r.ok?r.json():{rows:[]}}).then(convert4Bucket).catch(fun … [line shortened here: 440 characters; full line on GitHub]
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 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||'V5 captured Elexon Market Index Price'}))});return norm(rows)}
function periodDays(period){return {'12hday':0.5,'12hnight':0.5,'1d':1,'7d':7,'30d':30,'3m':92,'6m':183,'12m':366,'5y':1827,'10y':3653}[period]||7}
function periodLabel(period){return {'12hday':'12 hours day','12hnight':'12 hours night','1d':'1 day','7d':'1 week','30d':'1 month','3m':'3 months','6m':'6 months','12m':'12 months','5y':'5 years','10y':'10 years'}[period]||'1 week'}
function isDailyPeriod(p){return ['6m','12m','5y','10y'].indexOf(p)>=0}
function isDayNightPeriod(p){return p==='12hday'||p==='12hnight'}
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=[['12hday','12 hours day'],['12hnight','12 hours night'],['1d','1 day'],['7d','1 week'],['30d','1 month'],['3m','3 months'],['6m','6 months'],['12m','12 months'],['5y','5 years'],['10y','10 years']];var current=p.value||'7d';p.innerHTML='';wanted.forEach(function(x){var o=document.createElement('option');o.value … [line shortened here: 522 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</span><button type="button" data-mode="all" class="active">All</button><bu … [line shortened here: 769 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">1 day, 1 week, 1 m … [line shortened here: 2,550 characters; full line on GitHub]
function ensureDiscoveryPanel(){if($('price-history-discovery'))return;var canvas=$('price-history-canvas');if(!canvas||!canvas.parentNode)return;var d=document.createElement('details');d.id='price-history-discovery';d.className='price-history-discovery';d.innerHTML='<summary>What does this Elexon price mean?</summary><p><strong>Interpretation:</strong> this is an Elexon System Price / imbalance p … [line shortened here: 1,081 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(isDayNightPeriod(period)){s … [line shortened here: 916 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 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.06;return{lo:lo-m,hi:hi+m}}
function niceStep(span){var raw=span/10,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 seasonName(t){var m=new Date(t).getUTCMonth()+1;if(m===12||m<=2)return'Winter';if(m>=3&&m<=5)return'Spring';if(m>=6&&m<=8)return'Summer';return'Autumn'}
function seasonColor(t){var s=seasonName(t);if(s==='Winter')return'#00ffff';if(s==='Spring')return'#00ff88';if(s==='Summer')return'#ffcc00';return'#c79245'}
function drawSeasonKey(g,q,w,h,pad){var items=[['Winter','#00ffff'],['Spring','#00ff88'],['Summer','#ffcc00'],['Autumn','#c79245']],x=pad.left,y=pad.top-24*q;g.save();g.font=9*q+'px Courier New';items.forEach(function(it){g.fillStyle=it[1];g.shadowColor=it[1];g.shadowBlur=4*q;g.fillRect(x,y-7*q,8*q,8*q);g.shadowBlur=0;g.fillStyle='#9aa3b6';g.fillText(it[0],x+12*q,y);x+=58*q});g.restore()}
function drawDailyKey(g,q,pad){drawSeasonKey(g,q,0,0,pad);g.save();g.fillStyle='#9aa3b6';g.font=9*q+'px Courier New';g.fillText('Daily high low average shown in seasonal colours',pad.left,pad.top-8*q);g.restore()}
function drawDateTick(g,x,y,t,q,align,span){g.textAlign=align||'center';g.fillStyle='#f5f7fb';g.font=11*q+'px Courier New';g.fillText(axisLabel(t,span||0),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,span=t1-t0;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='rgba(255,255,255,.18)';g.lineWidth=q;g.beginPath();g.moveTo(pad.left,yy);g.lineTo(w-pad.right,yy);g.st … [line shortened here: 715 characters; full line on GitHub]
function decimateRows(rows,limit){if(!rows||rows.length<=limit)return rows||[];var out=[],bucket=Math.ceil(rows.length/limit);for(var i=0;i<rows.length;i+=bucket){var slice=rows.slice(i,i+bucket),hi=slice[0],lo=slice[0];slice.forEach(function(r){if(Number(r.priceGBPperMWh)>Number(hi.priceGBPperMWh))hi=r;if(Number(r.priceGBPperMWh)<Number(lo.priceGBPperMWh))lo=r});if(new Date(lo.priceTimeUTC)<new D … [line shortened here: 591 characters; full line on GitHub]
window.decimateRows=decimateRows;
function statsHalf(rows){if(!rows.length)return null;var hi=rows[0],lo=rows[0],sum=0;rows.forEach(function(r){var v=Number(r.priceGBPperMWh);sum+=v;if(v>Number(hi.priceGBPperMWh))hi=r;if(v<Number(lo.priceGBPperMWh))lo=r});return{hi:hi,lo:lo,avg:sum/rows.length,hiValue:Number(hi.priceGBPperMWh),loValue:Number(lo.priceGBPperMWh),hiDate:slab(hi.priceTimeUTC)+' '+tlab(hi.priceTimeUTC),loDate:slab(lo.p … [line shortened here: 440 characters; full line on GitHub]
function statsDaily(rows){if(!rows.length)return null;var hi=rows[0],lo=rows[0],sum=0,c=0;rows.forEach(function(r){if(r.average!=null){sum+=Number(r.average);c++}if(Number(r.high)>Number(hi.high))hi=r;if(Number(r.low)<Number(lo.low))lo=r});return{hi:hi,lo:lo,avg:c?sum/c:null,hiValue:Number(hi.high),loValue:Number(lo.low),hiDate:hi.date+' '+(hi.highAt||''),loDate:lo.date+' '+(lo.lowAt||'')}}
function eventBox(g,lines,q,x,y,align){var pad=8*q,lh=18*q,w=0;g.save();g.font='900 '+14*q+'px Courier New';lines.forEach(function(t){w=Math.max(w,g.measureText(t).width)});var h=lines.length*lh+pad*2,xx=align==='right'?x-w-pad*2:x;g.fillStyle='rgba(5,7,12,.78)';g.strokeStyle='rgba(0,255,255,.35)';g.lineWidth=1*q;g.shadowColor='rgba(0,255,255,.24)';g.shadowBlur=8*q;g.beginPath();g.roundRect(xx,y-h … [line shortened here: 577 characters; full line on GitHub]
function drawPointer(g,point,q,x,y){g.save();g.strokeStyle='#ff3333';g.shadowColor='rgba(0,255,255,.55)';g.shadowBlur=7*q;g.lineWidth=1.5*q;g.beginPath();g.moveTo(point.x,point.y);g.lineTo(x,y-24*q);g.stroke();g.restore()}
function drawEvents(g,rows,X,Y,q,w,h,pad){var s=statsHalf(rows);if(!s)return;var hx=X(s.hi),hy=Y(s.hiValue),lx=X(s.lo),ly=Y(s.loValue);g.save();g.fillStyle='#ff3333';g.shadowColor='rgba(0,255,255,.85)';g.shadowBlur=8*q;g.beginPath();g.arc(hx,hy,5*q,0,Math.PI*2);g.fill();g.beginPath();g.arc(lx,ly,5*q,0,Math.PI*2);g.fill();g.restore();var hr=hx<w/2,lr=lx<w/2;var hxText=hr?Math.min(w-pad.right-150*q, … [line shortened here: 883 characters; full line on GitHub]
function drawSeasonLine(g,lineRows,X,Y,q){g.save();g.lineWidth=2.1*q;g.lineCap='round';g.lineJoin='round';for(var i=1;i<lineRows.length;i++){var a=lineRows[i-1],b=lineRows[i],col=seasonColor(b.priceTimeUTC);g.strokeStyle=col;g.shadowColor=col;g.shadowBlur=5*q;g.beginPath();g.moveTo(X(a),Y(Number(a.priceGBPperMWh)));g.lineTo(X(b),Y(Number(b.priceGBPperMWh)));g.stroke()}g.restore()}
function drawDailyLines(g,rows,X,Y,q){['average','high','low'].forEach(function(k){g.save();g.lineWidth=(k==='average'?2.4:1.6)*q;g.setLineDash(k==='average'?[]:(k==='high'?[5*q,4*q]:[2*q,5*q]));g.lineCap='round';g.lineJoin='round';for(var i=1;i<rows.length;i++){var a=rows[i-1],b=rows[i];if(a[k]==null||b[k]==null||isNaN(Number(a[k]))||isNaN(Number(b[k])))continue;var col=seasonColor(b.date+'T12:00 … [line shortened here: 794 characters; full line on GitHub]
function drawDailyEvents(g,rows,X,Y,q,w,h,pad){var s=statsDaily(rows);if(!s)return;var hx=X(s.hi),hy=Y(s.hiValue),lx=X(s.lo),ly=Y(s.loValue);g.save();g.fillStyle='#ff3333';g.shadowColor='rgba(0,255,255,.85)';g.shadowBlur=8*q;g.beginPath();g.arc(hx,hy,5*q,0,Math.PI*2);g.fill();g.beginPath();g.arc(lx,ly,5*q,0,Math.PI*2);g.fill();g.restore();var hr=hx<w/2,lr=lx<w/2;var hxText=hr?Math.min(w-pad.right- … [line shortened here: 889 characters; full line on GitHub]
function drawSummary(g,stats,q,w,h,pad){if(!stats)return;var y=h-44*q;g.save();g.fillStyle='rgba(5,7,12,.72)';g.strokeStyle='rgba(0,255,255,.26)';g.lineWidth=1*q;g.beginPath();g.roundRect(pad.left,y-22*q,w-pad.left-pad.right,34*q,6*q);g.fill();g.stroke();g.fillStyle='#f5f7fb';g.font='900 '+10*q+'px Courier New';g.textAlign='center';var mid=w/2;g.fillText('HIGH '+pence(stats.hiValue)+'p/kWh (£'+fmt … [line shortened here: 745 characters; full line on GitHub]
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(320,Math.floor((r.height||360)*q))}var g=c.getContext('2d'),w=c.width,h=c.height,pad={left:74*q,right:24*q,top:96*q,bottom:154*q};g.clearRect(0,0,w,h);g.fillStyle='#05070c';g.fillRect(0,0,w,h);var t0=me … [line shortened here: 1,462 characters; full line on GitHub]
function status(meta,sourceRows,rows,years){var s=$('price-history-range-status');var lab=$('price-history-scroll-label');var mode=meta.mode==='daily'?'daily high low average':'full settlement';var text=dlab(meta.start)+' to '+dlab(meta.end)+' | '+(meta.mode==='daily'?'All hours':timeModeLabel())+' | '+rows.length.toLocaleString('en-GB')+' '+mode+' points';if(s){s.textContent=text;s.className='pri … [line shortened here: 579 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.</td></tr>';return}if(meta&&meta.mode==='daily'){b.innerHTML=rows.slice().reverse().slice(0,500).map(function(r){return '<tr><td>'+r.date+'</td><td>Avg £'+fmt(r.average,2)+' | High £'+fmt(r.high,2)+' | Low £'+fmt(r.low,2)+'</td><td>'+(r.highAt||'—')+'</t … [line shortened here: 851 characters; full line on GitHub]
function loadHalfHourly(meta){var years=yearsBetween(meta.start,meta.end);return 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(function(r){var t=new Date(r.priceTimeUTC);return t>=meta.start&&t<=meta.end&&passesTimeMode(r)});STATE.all= … [line shortened here: 470 characters; full line on GitHub]
function loadDailyRows(meta){return loadDaily().then(function(all){var rows=all.filter(function(r){var t=new Date(r.date+'T12:00:00Z');return t>=meta.start&&t<=meta.end});STATE.all=all;STATE.sourceRows=all.length;STATE.loadedYears=[];return rows})}
function load(){ensurePeriodOptions();ensureModeTabs();ensureYearOptions();ensureScroller();ensureDiscoveryPanel();var meta=selectedWindow();syncScrollerFromStart();var promise=meta.mode==='daily'?loadDailyRows(meta):loadHalfHourly(meta);promise.then(function(rows){STATE.visible=rows;STATE.meta=meta;STATE.mode=meta.mode;var latest=rows.length?rows[rows.length-1]:null;set('ph-latest-price',latest?( … [line shortened here: 1,027 characters; full line on GitHub]
function deferredLoad(){clearTimeout(pendingTimer);pendingTimer=setTimeout(load,160)}
window.__v5PriceHistoryControls={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();ensureDiscoveryPanel();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(cl)cl.remove();if(y … [line shortened here: 1,323 characters; full line on GitHub]
})();Start V6 App
A JavaScript file in the app bootstrap folder of GlobalGrid2050 that refreshes live (`refreshLive`). It refreshes live (`refreshLive`).
interactionglobalgrid2050 / uk_energy_tracking_v6/app_bootstrap/start_v6_app/start_v6_app.js · lines 1–14 of 14 · Not reached from any entry point (candidate for review)
- What it does
- Defines refreshLive, start. 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
- Defines `refreshLive` and `start`. It responds to DOMContentLoaded events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · uk_energy_tracking_v6/app_bootstrap/start_v6_app · script
- Uses
- none found
- Used by
- none found
- Produces
- refreshLive, start
- Defines here
- refreshLive, start
- 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_v6/app_bootstrap/start_v6_app/start_v6_app.js:1-14 · blob 0af813bd998c800050a7735b521075ad8c1bf900 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: unreached_review
window.V6StartApp=(function(){
function refreshLive(){
var cfg=window.V6LiveConfig,load=window.V6LoadJson.loadJson;
Promise.all([load(cfg.energy),load(cfg.price),load(cfg.commodities),load(cfg.fuel),load(cfg.evPrices),load(cfg.oilHistory)]).then(function(r){
var energy=r[0]||{},price=r[1]||{},commodities=r[2]||{},fuel=r[3]||{},ev=r[4]||{},oilHistory=r[5]||null;
window.V6RenderLiveSnapshot.render(energy,price);
window.V6RenderGenerationMix.render(energy);
window.V6RenderCommodities.render(commodities,fuel,ev,oilHistory);
})
}
function start(){refreshLive();setInterval(refreshLive,5*60*1000);if(window.V6ControlPriceHistory)window.V6ControlPriceHistory.start();if(window.V6FullscreenPeriodMenu)window.V6FullscreenPeriodMenu.start()}
document.addEventListener('DOMContentLoaded',start);
return{start:start,refreshLive:refreshLive};
})();Build from Data Repo
A Python command-line tool in the derived folder of GlobalGrid2050 that reads decade summary and pvlive solar daily browser. It is built from the mean step (`mean`).
storageglobalgrid2050 / uk_energy_tracking_v6/derived/build_from_data_repo.py · lines 1–186 of 186 · Entry point
- What it does
- It loads decade summary and pvlive solar daily browser. Defines mean, main. Uses libraries argparse, io, json, os, collections. Side effects: uses storage (browser storage, DuckDB or Parquet).
- 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 decade-summary.json; Parquet file data_0.parquet; JSON file pvlive_solar_daily_browser.json; DuckDB queries; command-line arguments.
- Downstream impact
- It is itself an entry point (Python CLI); no other file was found loading it.
- What it achieves
- Rebuild the decade summary from Ventusltd/data-GB-electricity. It accepts `--data` and `--out`.
- Why it matters
- No other file in the estate was found to import it; it is an entry point.
- Application
- globalgrid2050 · uk_energy_tracking_v6/derived · Python CLI
- Uses
- argparse, io, json, os, collections, duckdb
- Used by
- none found
- Produces
- mean, main
- Defines here
- mean, main
- 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_v6/derived/build_from_data_repo.py:1-186 · blob e29974985ab1c84dd3f8ba26684e72a11a428630 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: ingest · effects: storage · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
"""Rebuild the decade summary from Ventusltd/data-gb-electricity.
WHY THIS, AND WHY ONLY THIS
---------------------------
globalgrid2050 carries 240 workflows, and they were all frozen to manual
dispatch because that had become unmanageable. Unfreezing them would recreate
exactly the problem that was solved by freezing them.
The data problem was solved elsewhere: data-gb-electricity holds GB half-hourly
prices as partitioned Parquet and refreshes itself monthly on a schedule that
is still running. What broke was not collection. What broke is that nothing
consumes it any more, so the tracker's published figures stopped moving.
So this is one script behind one scheduled workflow. It reads the Parquet the
data repo already maintains and rewrites the small summary the Atlas reads. The
chain becomes: Elexon to data-gb-electricity, monthly; data-gb-electricity to
this summary, monthly; this summary to the map, on demand.
CROSS-CHECKED, NOT ASSUMED
--------------------------
The tracker also holds its own daily JSON series, derived separately and
earlier. Run against both on 2026-08-31 the extremes agree exactly -- lowest
half hour -185.33 GBP/MWh, highest 4037.80 -- which is a real check on two
independent paths from the same upstream.
Their coverage does not agree, and that is worth stating rather than hiding.
The Parquet spans 2016-01-01 to 2026-06-17 with 3,339 complete days; the JSON
series spans 2016-06-03 to 2026-06-02 with 3,652. Different windows and
different gap handling give different means, 78.18 against 80.17. Neither is
wrong. The summary records which source produced it and over what span, so the
figure is always attributable.
python build_from_data_repo.py --data ../../data-gb-electricity
"""
import argparse
import io
import json
import os
from collections import defaultdict
HERE = os.path.dirname(os.path.abspath(__file__))
# A day needs half its half hours before it means anything as a daily mean.
MIN_OBSERVATIONS = 24
DAILY = """
SELECT settlementDate AS day,
avg(systemSellPriceGBPperMWh) AS mean,
min(systemSellPriceGBPperMWh) AS lo,
max(systemSellPriceGBPperMWh) AS hi,
count(*) AS obs
FROM read_parquet(?)
WHERE systemSellPriceGBPperMWh IS NOT NULL
GROUP BY 1
HAVING count(*) >= {min}
ORDER BY 1
""".format(min=MIN_OBSERVATIONS)
def mean(values):
return sum(values) / len(values) if values else None
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--data", default=os.path.join(HERE, "..", "..", "..",
"data-gb-electricity"))
ap.add_argument("--out", default=os.path.join(HERE, "decade-summary.json"))
a = ap.parse_args()
import duckdb
glob = os.path.join(os.path.abspath(a.data), "prices", "year=*", "month=*",
"data_0.parquet").replace("\\", "/")
con = duckdb.connect()
rows = con.execute(DAILY, [glob]).fetchall()
if not rows:
raise SystemExit("no price rows matched %s" % glob)
by_year = defaultdict(list)
negative = defaultdict(int)
lowest = None
highest = None
for day, day_mean, lo, hi, _obs in rows:
year = str(day)[:4]
by_year[year].append(float(day_mean))
# Counted separately from the daily mean, because a mean hides them
# completely and they are the export limitation question.
if lo is not None and float(lo) < 0:
negative[year] += 1
if lo is not None and (lowest is None or float(lo) < lowest["value"]):
lowest = {"value": round(float(lo), 2), "date": str(day)}
if hi is not None and (highest is None or float(hi) > highest["value"]):
highest = {"value": round(float(hi), 2), "date": str(day)}
price_years = [{
"year": year,
"days": len(values),
"mean_gbp_per_mwh": round(mean(values), 2),
"min_daily_mean": round(min(values), 2),
"max_daily_mean": round(max(values), 2),
"days_with_a_negative_half_hour": negative.get(year, 0),
} for year, values in sorted(by_year.items())]
all_days = [v for values in by_year.values() for v in values]
# The solar series has no Parquet equivalent in the data repo yet, so it is
# carried forward from the existing summary rather than dropped. Losing a
# decade of PVLive because a different source was rewired would be a poor
# trade.
solar = None
if os.path.exists(a.out):
try:
solar = json.loads(io.open(a.out, encoding="utf-8").read()).get("solar")
except Exception:
solar = None
summary = {
"schema": "globalgrid2050.decade-summary.v1",
"what_this_is": (
"Yearly aggregates of GB half-hourly system prices, derived from "
"Ventusltd/data-gb-electricity, so that a map can carry the decade "
"without carrying the series. No resampling, smoothing, modelling "
"or forecasting: every figure is an arithmetic aggregate of "
"settlement periods, a day needs at least %d of them to count, and "
"the day count behind each year is stated so a partial year reads "
"as one." % MIN_OBSERVATIONS),
"not_a_forecast": (
"Historic system conditions. Nothing here is a projection, a price "
"expectation, or a statement about the economics of any project."),
"derived_from": {
"price": {
"repository": "Ventusltd/data-gb-electricity",
"path": "prices/year=*/month=*/data_0.parquet",
"field": "systemSellPriceGBPperMWh",
"upstream": "Elexon",
"settlement_periods": con.execute(
"SELECT count(*) FROM read_parquet(?) "
"WHERE systemSellPriceGBPperMWh IS NOT NULL", [glob]).fetchone()[0],
"complete_days": len(all_days),
"minimum_observations_per_day": MIN_OBSERVATIONS,
},
"solar": (solar or {}).get("carried_from") or {
"repository": "globalgrid2050",
"path": "uk_energy_tracking_v6/generation_history/pvlive_solar_daily_browser.json",
"upstream": "Sheffield Solar PVLive",
"note": ("carried forward: the data repository has no PVLive "
"Parquet yet, and dropping a decade of solar because "
"the price source was rewired would be a poor trade"),
},
},
"cross_check": (
"The tracker's own daily JSON series, derived independently and "
"earlier, agrees exactly on the extremes -- lowest -185.33, highest "
"4037.80 -- and differs on coverage: Parquet 2016-01-01 to "
"2026-06-17, JSON 2016-06-03 to 2026-06-02. Different windows give "
"different means. Neither is wrong; the source is recorded so the "
"figure is attributable."),
"price": {
"unit": "GBP per MWh, GB system sell price, daily mean of settlement periods",
"span": [price_years[0]["year"], price_years[-1]["year"]],
"decade_mean": round(mean(all_days), 2),
"lowest_half_hour": lowest,
"highest_half_hour": highest,
"by_year": price_years,
},
}
if solar:
summary["solar"] = solar
io.open(a.out, "w", encoding="utf-8", newline="\n").write(
json.dumps(summary, ensure_ascii=False, indent=2) + "\n")
neg = sum(y["days_with_a_negative_half_hour"] for y in price_years)
print("wrote %s (%.1f kB)" % (a.out, os.path.getsize(a.out) / 1024.0))
print(" %s-%s, %d complete days, mean %.2f GBP/MWh"
% (price_years[0]["year"], price_years[-1]["year"], len(all_days),
mean(all_days)))
print(" %d days had at least one settlement period below zero" % neg)
print(" lowest %s highest %s" % (lowest, highest))
return 0
if __name__ == "__main__":
raise SystemExit(main())