In this section
- GlobalGrid2050 Patch V5 Chart Overlap Controls render · globalgrid2050 / scripts/patch_v5_chart_overlap_controls.py lines 1–153
- GlobalGrid2050 Patch V5 Emergency Chart Repair render · globalgrid2050 / scripts/patch_v5_emergency_chart_repair.py lines 1–98
- GlobalGrid2050 Patch V5 Fullscreen Glow Controls render · globalgrid2050 / scripts/patch_v5_fullscreen_glow_controls.py lines 1–118
- GlobalGrid2050 Patch V5 Fullscreen Left Legend render · globalgrid2050 / scripts/patch_v5_fullscreen_left_legend.py lines 1–67
- GlobalGrid2050 Patch V5 Multi Year Loading render · globalgrid2050 / scripts/patch_v5_multi_year_loading.py lines 1–99
- GlobalGrid2050 Patch V5 Trend Title Safe Zone storage · globalgrid2050 / scripts/patch_v5_trend_title_safe_zone.py lines 1–50
- GlobalGrid2050 Plain Language storage · globalgrid2050 / scripts/plain_language.py lines 1–104
GlobalGrid2050 Patch V5 Chart Overlap Controls
A Python command-line tool in the scripts folder that replaces exact (`replace_exact`) and patches fullscreen (`patch_fullscreen`) and index (`patch_index`).
renderglobalgrid2050 / scripts/patch_v5_chart_overlap_controls.py · lines 1–153 of 153 · Entry point · pattern patch_ui (shared by 3 files)
- What it does
- It draws its content. Defines replace_exact, patch_ui, patch_fullscreen, patch_index, main. Uses libraries pathlib. Side effects: changes the web page (DOM); reads or writes files.
- Inputs & outputs
- Out: canvas drawing.
- Downstream impact
- It is itself an entry point (Python CLI); no other file was found loading it.
- What it achieves
- Defines `replace_exact`, `patch_ui`, `patch_fullscreen` and 1 more.
- Why it matters
- No other file in the estate was found to import it; it is an entry point.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib
- Used by
- none found
- Produces
- replace_exact, patch_ui, patch_fullscreen, patch_index, main
- Defines here
- replace_exact, patch_ui, patch_fullscreen, patch_index, 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 scripts/patch_v5_chart_overlap_controls.py:1-153 · blob 7a48bd5a5fe983e3a68e36d8a315f9b19721e5be · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem · domain stage: unknown · users: none · canonical: production_core
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
UI = ROOT / "uk_energy_tracking_v5" / "price-history-ui.js"
FS = ROOT / "uk_energy_tracking_v5" / "price-history-fullscreen.js"
INDEX = ROOT / "uk_energy_tracking_v5" / "index.md"
REPORT = ROOT / "gridbot_reports" / "patch_v5_chart_overlap_controls.md"
def replace_exact(text, old, new, label):
if old not in text:
raise SystemExit(f"Missing expected block: {label}")
return text.replace(old, new, 1)
def patch_ui(text):
text = text.replace("/uk_energy_tracking_v4/", "/uk_energy_tracking_v5/")
text = text.replace("__v4PriceHistoryState", "__v5PriceHistoryState")
text = text.replace("__v4PriceHistoryControls", "__v5PriceHistoryControls")
text = text.replace("V4 captured Elexon Market Index Price", "V5 captured Elexon Market Index Price")
text = text.replace("V4 Market Index audit", "V5 Market Index audit")
text = replace_exact(
text,
"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 axisLabel(t,span){var d=new Date(t);if(span<=45*86400000)return d.toLocaleDateString('en-GB',{day:'2-digit',month:'short'});return mlab(t)}\nfunction 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'}",
"UI drawDateTick",
)
text = replace_exact(
text,
"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(pa … [line shortened here: 879 characters; full line on GitHub]
"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(); … [line shortened here: 914 characters; full line on GitHub]
"UI drawAxes",
)
text = replace_exact(
text,
"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.lineWidt … [line shortened here: 702 characters; full line on GitHub]
"function drawMarker(g,label,r,x,y,q,above,colour){var price='£'+fmt(Number(r.priceGBPperMWh),2),time=slab(r.priceTimeUTC)+' '+tlab(r.priceTimeUTC),right=label==='HIGH';var tx=right?Math.min(g.canvas.width-126*q,x+18*q):Math.max(126*q,x-18*q);var ty=above?Math.max(50*q,y-38*q):Math.min(g.canvas.height-70*q,y+38*q);g.strokeStyle=colour;g.fillStyle=colour;g.lineWidth=1.3*q;g.beginPath();g.ar … [line shortened here: 667 characters; full line on GitHub]
"UI drawMarker",
)
text = replace_exact(
text,
"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 drawEvents(g,rows,X,Y,q){var e=eventPoints(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));drawMarker(g,'HIGH',e.hi,hx,hy,q,hy>g.canvas.height*.28,'#ff3333');drawMarker(g,'LOW',e.lo,lx,ly,q,ly>g.canvas.height*.68,'#ff3333')}",
"UI drawEvents",
)
text = replace_exact(
text,
"var g=c.getContext('2d'),w=c.width,h=c.height,pad={left:68*q,right:32*q,top:42*q,bottom:64*q};",
"var g=c.getContext('2d'),w=c.width,h=c.height,pad={left:68*q,right:32*q,top:46*q,bottom:88*q};",
"UI pad",
)
text = replace_exact(
text,
";drawEvents(g,rows,X,Y,q);g.fillStyle='#9aa3b6';g.font=11*q+'px Courier New';g.fillText(periodLabel(meta.period)+' | '+timeModeLabel()+' | '+rows.length+' pts',pad.left,h-12*q)",
";drawEvents(g,rows,X,Y,q)",
"UI footer removal",
)
return text
def patch_fullscreen(text):
text = text.replace("__v4PriceHistoryState", "__v5PriceHistoryState")
text = text.replace("__v4PriceHistoryControls", "__v5PriceHistoryControls")
text = text.replace("v4-", "v5-")
css_start = "s.textContent='"
start = text.index(css_start) + len(css_start)
end = text.index("';\n document.head.appendChild", start)
css = ".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-history-fullscreen-shell{position:fixed!important;inset:0!important;width:100vw!important;height:100dvh!important;border:0!important;border-radius … [line shortened here: 1,995 characters; full line on GitHub]
text = text[:start] + css + text[end:]
text = replace_exact(
text,
"function drawDateTick(g,x,y,t,q,align){g.textAlign=align||'center';g.fillStyle='#f5f7fb';g.font=11*q+'px Courier New';g.fillText(mlab(t),x,y);g.textAlign='left'}",
"function axisLabel(t,span){var d=new Date(t);if(span<=45*86400000)return d.toLocaleDateString('en-GB',{day:'2-digit',month:'short'});return mlab(t)}\nfunction drawDateTick(g,x,y,t,q,align,span){g.textAlign=align||'center';g.fillStyle='#f5f7fb';g.font=10*q+'px Courier New';g.fillText(axisLabel(t,span||0),x,y);g.textAlign='left'}",
"FS drawDateTick",
)
text = replace_exact(
text,
"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,.98)':'rgba(255,255,255,.17)';g.lineWidth=val===0?2*q:q;g.beginPath();g.moveTo(pa … [line shortened here: 877 characters; full line on GitHub]
"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,.98)':'rgba(255,255,255,.17)';g.lineWidth=val===0?2*q:q;g.beginPath(); … [line shortened here: 912 characters; full line on GitHub]
"FS drawAxes",
)
text = replace_exact(
text,
"function marker(g,label,r,x,y,q,above){var placeRight=label==='HIGH';var tx=placeRight?Math.min(g.canvas.width-118*q,x+18*q):Math.max(118*q,x-18*q);var ty=above?Math.max(62*q,y-32*q):Math.min(g.canvas.height-54*q,y+46*q);g.fillStyle='#ff3333';g.strokeStyle='#ff3333';g.lineWidth=1.3*q;g.beginPath();g.arc(x,y,3.8*q,0,Math.PI*2);g.fill();g.beginPath();g.moveTo(x,y);g.lineTo(tx,ty-10*q);g.str … [line shortened here: 653 characters; full line on GitHub]
"function marker(g,label,r,x,y,q,above){var right=label==='HIGH';var tx=right?Math.min(g.canvas.width-126*q,x+18*q):Math.max(126*q,x-18*q);var ty=above?Math.max(58*q,y-36*q):Math.min(g.canvas.height-68*q,y+38*q);g.fillStyle='#ff3333';g.strokeStyle='#ff3333';g.lineWidth=1.3*q;g.beginPath();g.arc(x,y,3.8*q,0,Math.PI*2);g.fill();g.beginPath();g.moveTo(x,y);g.lineTo(tx,ty-10*q);g.stroke();g.fo … [line shortened here: 638 characters; full line on GitHub]
"FS marker",
)
text = replace_exact(
text,
"function drawEvents(g,rows,X,Y,q){var e=eventPoints(rows);if(!e)return;marker(g,'HIGH',e.hi,X(e.hi),Y(Number(e.hi.priceGBPperMWh)),q,true);marker(g,'LOW',e.lo,X(e.lo),Y(Number(e.lo.priceGBPperMWh)),q,false)}",
"function drawEvents(g,rows,X,Y,q){var e=eventPoints(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));marker(g,'HIGH',e.hi,hx,hy,q,hy>g.canvas.height*.28);marker(g,'LOW',e.lo,lx,ly,q,ly>g.canvas.height*.68)}",
"FS drawEvents",
)
text = replace_exact(
text,
"var pad={left:(isLandscape?70:62)*q,right:(isLandscape?58:36)*q,top:(isLandscape?62:82)*q,bottom:(isLandscape?46:62)*q};",
"var pad={left:(isLandscape?70:62)*q,right:(isLandscape?58:36)*q,top:(isLandscape?58:76)*q,bottom:(isLandscape?58:76)*q};",
"FS pad",
)
text = replace_exact(
text,
"var lab=$('fs-label');if(lab)lab.textContent='High and low price events labelled | '+modeText()+' | '+slab(meta.start)+' to '+slab(meta.end)",
"var lab=$('fs-label');if(lab)lab.textContent=''",
"FS label removal",
)
return text
def patch_index(text):
text = text.replace("price-history-ui.js?v=20260527b", "price-history-ui.js?v=20260527c")
text = text.replace("price-history-fullscreen.js?v=20260527b", "price-history-fullscreen.js?v=20260527c")
return text
def main():
ui = patch_ui(UI.read_text())
fs = patch_fullscreen(FS.read_text())
idx = patch_index(INDEX.read_text())
UI.write_text(ui)
FS.write_text(fs)
INDEX.write_text(idx)
REPORT.parent.mkdir(parents=True, exist_ok=True)
REPORT.write_text(
"# V5 chart overlap and control placement patch\n\n"
"Updated `uk_energy_tracking_v5/price-history-ui.js`, `uk_energy_tracking_v5/price-history-fullscreen.js` and `uk_energy_tracking_v5/index.md`.\n\n"
"Changes applied:\n"
"1. Removed the drawn footer text from the normal canvas to stop overlap with x axis labels.\n"
"2. Increased normal chart bottom padding and made low labels flip above when close to the bottom.\n"
"3. Reduced repeated centre date labels on short windows.\n"
"4. Removed the full screen floating bottom label.\n"
"5. Moved full screen arrows into the top left chart corner.\n"
"6. Kept All, Day, Night and Close in the top right chart corner.\n"
"7. Updated script cache keys to `20260527c`.\n"
)
if __name__ == "__main__":
main()GlobalGrid2050 Patch V5 Emergency Chart Repair
A Python command-line tool in the scripts folder that patches fullscreen (`patch_fullscreen`) and normal (`patch_normal`).
renderglobalgrid2050 / scripts/patch_v5_emergency_chart_repair.py · lines 1–98 of 98 · Entry point · pattern patch_normal (shared by 2 files)
- What it does
- It loads data. Defines patch_fullscreen, patch_normal, main. Uses libraries pathlib, re. Side effects: changes the web page (DOM); reads or writes files.
- Downstream impact
- Used directly by 1 file: GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (globalgrid2050).
- What it achieves
- Defines `patch_fullscreen` and `patch_normal`.
- Why it matters
- Run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib, re
- Used by
- run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (workflow run)
- Produces
- patch_fullscreen, patch_normal, main
- Defines here
- patch_fullscreen, patch_normal, 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 scripts/patch_v5_emergency_chart_repair.py:1-98 · blob af05f609f96ab51a9e736610fac482d297ebefd1 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem · domain stage: unknown · users: none · canonical: production_core
from pathlib import Path
import re
ROOT = Path(__file__).resolve().parents[1]
UI = ROOT / "uk_energy_tracking_v5" / "price-history-ui.js"
FS = ROOT / "uk_energy_tracking_v5" / "price-history-fullscreen.js"
INDEX = ROOT / "uk_energy_tracking_v5" / "index.md"
REPORT = ROOT / "gridbot_reports" / "patch_v5_emergency_chart_repair.md"
def patch_fullscreen(txt):
# Critical bug fix: previous patch changed rows.forEach to lineRows.forEach but did not define lineRows.
if "lineRows.forEach" in txt and "var lineRows=" not in txt:
txt = txt.replace(
"drawAxes(g,w,h,q,m,t0,t1,pad);g.strokeStyle='#00ffff';",
"drawAxes(g,w,h,q,m,t0,t1,pad);var lineRows=(window.decimateRows?window.decimateRows(rows,Math.max(900,Math.floor((w/q)*1.8))):rows);g.strokeStyle='#00ffff';",
)
# In fullscreen axes, draw only full start and full end dates. No middle labels.
txt = re.sub(
r"if\(!\(count===3&&i===1\)\)drawDateTick\(g,x,h-68\*q,ts,q,i===0\?'left':\(i===count-1\?'right':'center'\),span\)",
"if(i===0||i===count-1)drawDateTick(g,x,h-68*q,ts,q,i===0?'left':'right',span)",
txt,
)
txt = re.sub(
r"if\(!\(count===3&&i===1\)\)\{g\.fillStyle='#f5f7fb';g\.font=10\*q\+'px Courier New';g\.textAlign=i===0\?'left':\(i===count-1\?'right':'center'\);g\.fillText\(axisLabel\(ts,span\),x,h-52\*q\)\}",
"if(i===0||i===count-1){g.fillStyle='#f5f7fb';g.font=10*q+'px Courier New';g.textAlign=i===0?'left':'right';g.fillText(axisLabel(ts,span),x,h-52*q)}",
txt,
)
# If Trend mode exists, keep the title in a protected header band and use it correctly.
txt = txt.replace(
"g.fillText('ELECTRICITY PRICE £/MWh',pad.left,(isLandscape?28:64)*q);",
"g.fillText(MINIMAL?'£/MWh':'ELECTRICITY PRICE £/MWh',pad.left,MINIMAL?40*q:(isLandscape?28:64)*q);",
)
txt = txt.replace(
"g.fillText(slab(meta.start)+' to '+slab(meta.end)+' | '+modeText()+' | '+rows.length.toLocaleString('en-GB')+' price points',pad.left,(isLandscape?46:84)*q);",
"if(!MINIMAL)g.fillText(slab(meta.start)+' to '+slab(meta.end)+' | '+modeText()+' | '+rows.length.toLocaleString('en-GB')+' price points',pad.left,(isLandscape?46:84)*q);",
)
return txt
def patch_normal(txt):
# Normal mode x axis: show full start and full end dates only.
txt = re.sub(
r"if\(i===0\|\|i===count-1\)drawDateTick\(g,x,h-74\*q,ts,q,i===0\?'left':\(i===count-1\?'right':'center'\),span\)",
"if(i===0||i===count-1)drawDateTick(g,x,h-74*q,ts,q,i===0?'left':'right',span)",
txt,
)
txt = re.sub(
r"if\(!\(count===3&&i===1\)\)drawDateTick\(g,x,h-74\*q,ts,q,i===0\?'left':\(i===count-1\?'right':'center'\),span\)",
"if(i===0||i===count-1)drawDateTick(g,x,h-74*q,ts,q,i===0?'left':'right',span)",
txt,
)
# Keep HIGH and LOW labels inside the plot safe zone, away from x axis labels.
txt = re.sub(
r"glowingLabel\(g,'HIGH',e\.hi,\{x:hx,y:hy\},q,hxText,pad\.top-22\*q,hxText>=hx\);glowingLabel\(g,'LOW',e\.lo,\{x:lx,y:ly\},q,lxText,h-pad\.bottom\+32\*q,lxText>=lx\)",
"glowingLabel(g,'HIGH',e.hi,{x:hx,y:hy},q,hxText,pad.top+22*q,hxText>=hx);glowingLabel(g,'LOW',e.lo,{x:lx,y:ly},q,lxText,h-pad.bottom-26*q,lxText>=lx)",
txt,
)
txt = re.sub(
r"glowingLabel\(g,'HIGH',e\.hi,\{x:hx,y:hy\},q,hxText,pad\.top-8\*q,hxText>=hx\);glowingLabel\(g,'LOW',e\.lo,\{x:lx,y:ly\},q,lxText,h-pad\.bottom\+18\*q,lxText>=lx\)",
"glowingLabel(g,'HIGH',e.hi,{x:hx,y:hy},q,hxText,pad.top+22*q,hxText>=hx);glowingLabel(g,'LOW',e.lo,{x:lx,y:ly},q,lxText,h-pad.bottom-26*q,lxText>=lx)",
txt,
)
return txt
def main():
FS.write_text(patch_fullscreen(FS.read_text()))
UI.write_text(patch_normal(UI.read_text()))
idx = INDEX.read_text()
for old in ["20260527b", "20260527c", "20260527d", "20260527e", "20260527f", "20260527g", "20260527h", "20260527i", "20260527j", "20260527k", "20260527l", "20260527m", "20260527n", "20260527o", "20260527p"]:
idx = idx.replace(f"price-history-fullscreen.js?v={old}", "price-history-fullscreen.js?v=20260527q")
idx = idx.replace(f"price-history-ui.js?v={old}", "price-history-ui.js?v=20260527q")
INDEX.write_text(idx)
REPORT.parent.mkdir(parents=True, exist_ok=True)
REPORT.write_text(
"# V5 emergency chart repair\n\n"
"Diagnosed and repaired the immediate V5 chart breakage.\n\n"
"Findings:\n"
"1. Fullscreen chart drawing was broken because `lineRows.forEach(...)` was introduced without defining `lineRows`. This produced axes and labels but no cyan price line.\n"
"2. V4 did not have this issue because it drew directly from `rows.forEach(...)`.\n"
"3. Normal chart event labels were still allowed to sit in the x axis label zone.\n\n"
"Repairs:\n"
"1. Defined `lineRows` before fullscreen rendering.\n"
"2. Kept decimated drawing for performance while preserving HIGH and LOW detection from full rows.\n"
"3. Reduced x axis labels to full start date and full end date only.\n"
"4. Moved HIGH and LOW normal chart annotations inside the plot safe zone, away from x axis labels.\n"
"5. Updated cache keys to 20260527q.\n"
)
if __name__ == "__main__":
main()GlobalGrid2050 Patch V5 Fullscreen Glow Controls
A Python command-line tool in the scripts folder that replaces function (`replace_function`), patches dates (`patch_dates`) and removes MWh axis (`remove_mwh_from_y_axis`) (units: MWh).
renderglobalgrid2050 / scripts/patch_v5_fullscreen_glow_controls.py · lines 1–118 of 118 · Entry point · pattern patch_normal (shared by 2 files)
- What it does
- It draws its content. Defines 6 functions or classes, including replace_function, patch_dates, remove_mwh_from_y_axis, patch_fullscreen, patch_normal. Uses libraries pathlib, re. Side effects: changes the web page (DOM); reads or writes files.
- Inputs & outputs
- Out: canvas drawing.
- Downstream impact
- Used directly by 1 file: GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (globalgrid2050).
- What it achieves
- Defines `replace_function`, `patch_dates`, `remove_mwh_from_y_axis` and 2 more.
- Why it matters
- Run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib, re
- Used by
- run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (workflow run)
- Produces
- replace_function, patch_dates, remove_mwh_from_y_axis, patch_fullscreen, patch_normal, main
- Defines here
- replace_function, patch_dates, remove_mwh_from_y_axis, patch_fullscreen, patch_normal, 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 scripts/patch_v5_fullscreen_glow_controls.py:1-118 · blob 357fb6526002959cf5ddf25698b2ebe2f584b31e · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem · domain stage: unknown · users: none · canonical: production_core
from pathlib import Path
import re
ROOT = Path(__file__).resolve().parents[1]
UI = ROOT / "uk_energy_tracking_v5" / "price-history-ui.js"
FS = ROOT / "uk_energy_tracking_v5" / "price-history-fullscreen.js"
INDEX = ROOT / "uk_energy_tracking_v5" / "index.md"
REPORT = ROOT / "gridbot_reports" / "patch_v5_fullscreen_glow_controls.md"
ARROW_CLOSE_CSS = ".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-history-fullscreen-shell{position:fixed!important;inset:0!important;width:100vw!important;height:100dvh!important;border:0!important;borde … [line shortened here: 1,678 characters; full line on GitHub]
ENSURE_ARROWS_CLOSE = """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( … [line shortened here: 798 characters; full line on GitHub]
BIND_ARROWS_CLOSE = """function bindControls(){var c=window.__v5PriceHistoryControls;if(!c)return;var prev=$('fs-prev'),next=$('fs-next'),closeBtn=$('fs-close-lite');if(closeBtn)closeBtn.onclick=close;if(prev)prev.onclick=function(){var st=window.__v5PriceHistoryState||{},days=c.periodDays((st.meta||{}).period||'7d'),v=c.offsetFromDate((st.meta||{}).start||new Date());c.setOffset(Math.max(0,v-days … [line shortened here: 674 characters; full line on GitHub]
SYNC_NONE = "function syncFs(){}"
FS_LABELS = """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 glowingLabel(g,label,r,point,q,x,y,right){g.save();g.strokeStyle='#ff3333';g.shadowColor='rgba(0,255,255,.85)';g.shadowBlur=10*q;g.lineWidth=1.8*q;g.beginPath();g.moveTo(point.x,point.y);g.lineTo(x,y);g.stroke();g.fillStyle='#ff3333';g.font='bold '+(12*q)+'px Courier New';g.textAlign=right?'left':'right';g.fillText(label+' £'+fmt(Number(r.priceGBPperMWh),2)+'/MWh',x,y);g.font='bold '+(10* … [line shortened here: 499 characters; full line on GitHub]
function drawEvents(g,rows,X,Y,q,w,h,pad){var e=eventPoints(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,.90)';g.shadowBlur=11*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 hxText=Math.min(w-pad. … [line shortened here: 671 characters; full line on GitHub]
NORMAL_LABELS = FS_LABELS.replace("12*q", "11*q").replace("10*q", "9.5*q").replace("pad.top-24*q", "pad.top-22*q").replace("h-pad.bottom+34*q", "h-pad.bottom+32*q")
def replace_function(text, name, new_code):
pattern = r"function " + re.escape(name) + r"\([^)]*\)\{.*?\nfunction "
m = re.search(pattern, text, flags=re.S)
if not m:
raise SystemExit(f"Could not locate function {name}")
return text[:m.start()] + new_code + "\nfunction " + text[m.end():]
def patch_dates(text):
text = re.sub(
r"function slab\(t\)\{.*?\}\nfunction tlab",
"function slab(t){return new Date(t).toLocaleDateString('en-GB',{day:'2-digit',month:'long',year:'numeric'})}\nfunction tlab",
text,
flags=re.S,
)
text = re.sub(
r"function axisLabel\(t,span\)\{.*?\}\nfunction drawDateTick",
"function axisLabel(t,span){var d=new Date(t);if(span<=45*86400000)return d.toLocaleDateString('en-GB',{day:'2-digit',month:'long',year:'numeric'});return d.toLocaleDateString('en-GB',{month:'long',year:'numeric'})}\nfunction drawDateTick",
text,
flags=re.S,
)
return text
def remove_mwh_from_y_axis(text):
text = text.replace("val===0?'£0/MWh':'£'+fmt(val,0)+'/MWh'", "val===0?'£0':'£'+fmt(val,0)")
text = text.replace("(val===0?'£0/MWh':'£'+fmt(val,0)+'/MWh')", "(val===0?'£0':'£'+fmt(val,0))")
return text
def patch_fullscreen():
txt = patch_dates(FS.read_text())
txt = remove_mwh_from_y_axis(txt)
txt = re.sub(r"s\.textContent='.*?';document\.head\.appendChild\(s\)", "s.textContent='" + ARROW_CLOSE_CSS + "';document.head.appendChild(s)", txt, flags=re.S)
txt = replace_function(txt, "ensureControls", ENSURE_ARROWS_CLOSE)
txt = replace_function(txt, "bindControls", BIND_ARROWS_CLOSE)
txt = replace_function(txt, "syncFs", SYNC_NONE)
txt = re.sub(r"function eventPoints\(rows\)\{.*?\nfunction draw\(\)", FS_LABELS + "\nfunction draw()", txt, flags=re.S)
txt = txt.replace("g.fillText('ELECTRICITY PRICE',pad.left,(isLandscape?28:64)*q)", "g.fillText('ELECTRICITY PRICE £/MWh',pad.left,(isLandscape?28:64)*q)")
txt = txt.replace("g.fillText('ELECTRICITY PRICE £/MWh',pad.left,(isLandscape?28:64)*q)", "g.fillText('ELECTRICITY PRICE £/MWh',pad.left,(isLandscape?28:64)*q)")
txt = re.sub(
r"var pad=\{left:\(isLandscape\?\d+:\d+\)\*q,right:\(isLandscape\?\d+:\d+\)\*q,top:\(isLandscape\?\d+:\d+\)\*q,bottom:\(isLandscape\?\d+:\d+\)\*q\};",
"var pad={left:(isLandscape?82:86)*q,right:(isLandscape?26:28)*q,top:(isLandscape?74:112)*q,bottom:(isLandscape?96:128)*q};",
txt,
)
FS.write_text(txt)
def patch_normal():
txt = patch_dates(UI.read_text())
txt = remove_mwh_from_y_axis(txt)
txt = re.sub(r"function eventPoints\(rows\)\{.*?\nfunction draw\(rows,meta\)", NORMAL_LABELS + "\nfunction draw(rows,meta)", txt, flags=re.S)
txt = re.sub(
r"var g=c\.getContext\('2d'\),w=c\.width,h=c\.height,pad=\{left:[^}]+\};",
"var g=c.getContext('2d'),w=c.width,h=c.height,pad={left:74*q,right:24*q,top:58*q,bottom:124*q};",
txt,
count=1,
)
txt = txt.replace("drawDateTick(g,x,h-54*q,ts,q", "drawDateTick(g,x,h-74*q,ts,q")
txt = txt.replace("drawDateTick(g,x,h-70*q,ts,q", "drawDateTick(g,x,h-74*q,ts,q")
UI.write_text(txt)
def main():
patch_fullscreen()
patch_normal()
idx = INDEX.read_text()
idx = idx.replace("Electricity Price History</strong>", "Electricity Price History £/MWh</strong>")
idx = idx.replace("Electricity Price History £/MWh £/MWh</strong>", "Electricity Price History £/MWh</strong>")
for old in ["20260527b", "20260527c", "20260527d", "20260527e", "20260527f", "20260527g", "20260527h", "20260527i", "20260527j", "20260527k"]:
idx = idx.replace(f"price-history-fullscreen.js?v={old}", "price-history-fullscreen.js?v=20260527l")
idx = idx.replace(f"price-history-ui.js?v={old}", "price-history-ui.js?v=20260527l")
INDEX.write_text(idx)
REPORT.parent.mkdir(parents=True, exist_ok=True)
REPORT.write_text(
"# V5 chart glow controls refinement\n\n"
"Implemented the latest chart layout refinement in both normal and fullscreen views.\n\n"
"Changes:\n"
"1. Fullscreen now keeps only left arrow, right arrow and a small Close button at top right.\n"
"2. Removed fullscreen All, Day, Night and period buttons to reduce clutter.\n"
"3. Y axis labels now show currency only, with £/MWh stated in the chart title.\n"
"4. Normal chart title text now also states £/MWh.\n"
"5. HIGH remains in the top band and LOW remains in the bottom band.\n"
"6. Red annotation text remains bold with cyan glow.\n"
"7. Chart plot area is stretched wider while preserving room for annotations.\n"
"8. Date labels remain fully spelled out to avoid UK or US ambiguity.\n"
"9. Updated both chart cache keys to 20260527l.\n"
)
if __name__ == "__main__":
main()GlobalGrid2050 Patch V5 Fullscreen Left Legend
A Python command-line tool in the scripts folder that replaces function (`replace_function`).
renderglobalgrid2050 / scripts/patch_v5_fullscreen_left_legend.py · lines 1–67 of 67 · Entry point · pattern replace_function (shared by 4 files)
- What it does
- It draws its content. Defines replace_function, main. Uses libraries pathlib, re. Side effects: changes the web page (DOM); reads or writes files.
- Downstream impact
- Used directly by 1 file: GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (globalgrid2050).
- What it achieves
- Defines `replace_function`.
- Why it matters
- Run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib, re
- Used by
- run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (workflow run)
- Produces
- replace_function, main
- Defines here
- replace_function, 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 scripts/patch_v5_fullscreen_left_legend.py:1-67 · blob 5400cd23ad4981eea17f8801775e8cb1fbc2eba0 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem · domain stage: unknown · users: none · canonical: production_core
from pathlib import Path
import re
ROOT = Path(__file__).resolve().parents[1]
FS = ROOT / "uk_energy_tracking_v5" / "price-history-fullscreen.js"
INDEX = ROOT / "uk_energy_tracking_v5" / "index.md"
REPORT = ROOT / "gridbot_reports" / "patch_v5_fullscreen_left_legend.md"
CSS = ".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-history-fullscreen-shell{position:fixed!important;inset:0!important;width:100vw!important;height:100dvh!important;border:0!important;border-radius:0!i … [line shortened here: 1,742 characters; full line on GitHub]
ENSURE = """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') … [line shortened here: 839 characters; full line on GitHub]
BIND = """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(){var st=window.__v5PriceHistoryState||{},d … [line shortened here: 800 characters; full line on GitHub]
LABELS = """function events(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 sideLabel(g,label,r,point,q,x,y){g.save();g.strokeStyle='#ff3333';g.shadowColor='rgba(0,255,255,.85)';g.shadowBlur=10*q;g.lineWidth=1.7*q;g.beginPath();g.moveTo(point.x,point.y);g.lineTo(x+8*q,y-3*q);g.stroke();g.fillStyle='#ff3333';g.font='bold '+(11*q)+'px Courier New';g.textAlign='right';g.fillText(label+' £'+fmt(Number(r.priceGBPperMWh),2)+'/MWh',x,y);g.font='bold '+(9.5*q)+'px Courie … [line shortened here: 486 characters; full line on GitHub]
function drawEvents(g,rows,X,Y,q,w,h,pad){var e=events(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,.90)';g.shadowBlur=10*q;g.beginPath();g.arc(hx,hy,4.8*q,0,Math.PI*2);g.fill();g.beginPath();g.arc(lx,ly,4.8*q,0,Math.PI*2);g.fill();g.restore();var labelX=pad.left-14*q;si … [line shortened here: 523 characters; full line on GitHub]
def replace_function(text, name, new_code):
pattern = r"function " + re.escape(name) + r"\([^)]*\)\{.*?\nfunction "
m = re.search(pattern, text, flags=re.S)
if not m:
raise SystemExit(f"Could not locate function {name}")
return text[:m.start()] + new_code + "\nfunction " + text[m.end():]
def main():
txt = FS.read_text()
if "var MINIMAL=" not in txt:
txt = txt.replace("var S={rows:[],meta:null};", "var S={rows:[],meta:null};\nvar MINIMAL=false;")
txt = re.sub(r"s\.textContent='.*?';document\.head\.appendChild\(s\)", "s.textContent='" + CSS + "';document.head.appendChild(s)", txt, flags=re.S)
txt = replace_function(txt, "ensureControls", ENSURE)
txt = replace_function(txt, "bindControls", BIND)
txt = re.sub(r"function events\(rows\)\{.*?\nfunction draw\(\)", LABELS + "\nfunction draw()", txt, flags=re.S)
txt = re.sub(r"function eventPoints\(rows\)\{.*?\nfunction draw\(\)", LABELS + "\nfunction draw()", txt, flags=re.S)
txt = re.sub(
r"var pad=MINIMAL\?\{left:[^}]+\}:\{left:[^}]+\};",
"var pad=MINIMAL?{left:68*q,right:62*q,top:42*q,bottom:68*q}:{left:(isLandscape?238:158)*q,right:(isLandscape?74:62)*q,top:(isLandscape?76:112)*q,bottom:(isLandscape?118:142)*q};",
txt,
)
txt = re.sub(
r"var pad=\{left:\(isLandscape\?\d+:\d+\)\*q,right:\(isLandscape\?\d+:\d+\)\*q,top:\(isLandscape\?\d+:\d+\)\*q,bottom:\(isLandscape\?\d+:\d+\)\*q\};",
"var pad=MINIMAL?{left:68*q,right:62*q,top:42*q,bottom:68*q}:{left:(isLandscape?238:158)*q,right:(isLandscape?74:62)*q,top:(isLandscape?76:112)*q,bottom:(isLandscape?118:142)*q};",
txt,
)
txt = txt.replace("if(!MINIMAL)drawEvents(g,rows,X,Y,q,w,h,pad)", "if(!MINIMAL)drawEvents(g,rows,X,Y,q,w,h,pad)")
if "if(!MINIMAL)drawEvents" not in txt:
txt = txt.replace("drawEvents(g,rows,X,Y,q,w,h,pad);", "if(!MINIMAL)drawEvents(g,rows,X,Y,q,w,h,pad);")
FS.write_text(txt)
idx = INDEX.read_text()
for old in ["20260527b", "20260527c", "20260527d", "20260527e", "20260527f", "20260527g", "20260527h", "20260527i", "20260527j", "20260527k", "20260527l", "20260527m"]:
idx = idx.replace(f"price-history-fullscreen.js?v={old}", "price-history-fullscreen.js?v=20260527n")
INDEX.write_text(idx)
REPORT.parent.mkdir(parents=True, exist_ok=True)
REPORT.write_text(
"# V5 fullscreen left legend patch\n\n"
"Moved fullscreen HIGH and LOW annotation text into a left side legend outside the plotting area. "
"Moved the navigation arrows to the right hand side so they do not clash with the annotation legend or y axis labels. "
"Retained the minimalist Trend toggle and updated the fullscreen cache key to 20260527n.\n"
)
if __name__ == "__main__":
main()GlobalGrid2050 Patch V5 Multi Year Loading
A Python command-line tool in the scripts folder that patches fs (`patch_fs`).
renderglobalgrid2050 / scripts/patch_v5_multi_year_loading.py · lines 1–99 of 99 · Entry point · pattern patch_fs (shared by 2 files)
- What it does
- It draws its content. Defines patch_ui, patch_fs, main. Uses libraries pathlib, re. Side effects: changes the web page (DOM); reads or writes files.
- Downstream impact
- Used directly by 1 file: GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (globalgrid2050).
- What it achieves
- Defines `patch_ui` and `patch_fs`.
- Why it matters
- Run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib, re
- Used by
- run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (workflow run)
- Produces
- patch_ui, patch_fs, main
- Defines here
- patch_ui, patch_fs, 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 scripts/patch_v5_multi_year_loading.py:1-99 · blob d7bbe5f6890d76315ca48aefc1fc8ea495995d5d · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem · domain stage: unknown · users: none · canonical: production_core
from pathlib import Path
import re
ROOT = Path(__file__).resolve().parents[1]
UI = ROOT / "uk_energy_tracking_v5" / "price-history-ui.js"
FS = ROOT / "uk_energy_tracking_v5" / "price-history-fullscreen.js"
INDEX = ROOT / "uk_energy_tracking_v5" / "index.md"
REPORT = ROOT / "gridbot_reports" / "patch_v5_multi_year_loading.md"
LOADER_HELPERS = r'''
function periodIsLong(p){return ['12m','2y','5y','10y'].indexOf(p)>=0}
function sleep(ms){return new Promise(function(resolve){setTimeout(resolve,ms)})}
function setLoader(show,pct,msg){
var id='price-history-loader',el=document.getElementById(id);
if(!el){
el=document.createElement('div');el.id=id;
el.innerHTML='<div class="ph-loader-card"><strong>Loading price history</strong><div class="ph-loader-text"></div><div class="ph-loader-track"><div class="ph-loader-bar"></div></div></div>';
document.body.appendChild(el);
var s=document.createElement('style');s.id='price-history-loader-style';
s.textContent='#price-history-loader{position:fixed;inset:0;z-index:100000;background:rgba(0,0,0,.58);display:none;align-items:center;justify-content:center;pointer-events:none}.ph-loader-card{width:min(360px,82vw);border:1px solid rgba(0,255,255,.45);border-radius:10px;background:rgba(5,7,12,.92);box-shadow:0 0 22px rgba(0,255,255,.18);padding:14px 16px;color:#f5f7fb;font:13px Courier New,monos … [line shortened here: 813 characters; full line on GitHub]
document.head.appendChild(s);
}
if(show){el.style.display='flex';el.querySelector('.ph-loader-bar').style.width=Math.max(0,Math.min(100,pct||0))+'%';el.querySelector('.ph-loader-text').textContent=msg||'Preparing data'}else{el.style.display='none'}
}
function slowLoadYears(years,period){
var out=[],i=0,delay=periodIsLong(period)?260:0;
setLoader(periodIsLong(period),4,'Preparing '+years.length+' annual file'+(years.length===1?'':'s'));
function next(){
if(i>=years.length){setLoader(periodIsLong(period),82,'Preparing chart points');return Promise.resolve(out)}
var y=years[i],pct=8+Math.round((i/Math.max(1,years.length))*66);
setLoader(periodIsLong(period),pct,'Loading '+y+' price file');
return loadAnnual(y).then(function(rows){out.push(rows);i++;return sleep(delay)}).then(next);
}
return next();
}
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 Date(hi.priceTimeUTC)){out.push(lo);if(hi!==lo)out.push(hi)}else{out.push(hi);if(hi!==lo)out.push(lo)}
}
return out.sort(function(a,b){return new Date(a.priceTimeUTC)-new Date(b.priceTimeUTC)});
}
'''
def patch_ui(txt):
txt = txt.replace("var MAX_VISIBLE_ROWS=19000;", "var MAX_VISIBLE_ROWS=90000;")
txt = txt.replace("{'7d':7,'30d':30,'3m':92,'6m':183,'12m':366}", "{'7d':7,'30d':30,'3m':92,'6m':183,'12m':366,'2y':732,'5y':1830,'10y':3653}")
txt = txt.replace("{'7d':'1 week','30d':'1 month','3m':'3 months','6m':'6 months','12m':'12 months'}", "{'7d':'1 week','30d':'1 month','3m':'3 months','6m':'6 months','12m':'12 months','2y':'2 years','5y':'5 years','10y':'10 years'}")
txt = txt.replace("[['7d','1 week'],['30d','1 month'],['3m','3 months'],['6m','6 months'],['12m','12 months']]", "[['7d','1 week'],['30d','1 month'],['3m','3 months'],['6m','6 months'],['12m','12 months'],['2y','2 years'],['5y','5 years'],['10y','10 years']]")
if "function periodIsLong" not in txt:
txt = txt.replace("function loadAnnual(year){", LOADER_HELPERS + "\nfunction loadAnnual(year){")
txt = txt.replace("Promise.all([loadJson()].concat(years.map(loadAnnual))).then(function(parts){", "slowLoadYears(years,meta.period).then(function(yearParts){return loadJson().then(function(jsonRows){return [jsonRows].concat(yearParts)})}).then(function(parts){")
txt = txt.replace("if(rows.length>MAX_VISIBLE_ROWS)rows=rows.slice(rows.length-MAX_VISIBLE_ROWS);", "if(rows.length>MAX_VISIBLE_ROWS)rows=rows.slice(rows.length-MAX_VISIBLE_ROWS);setLoader(periodIsLong(meta.period),88,'Rendering '+rows.length.toLocaleString('en-GB')+' price points');")
txt = txt.replace("table(rows,meta);draw(rows,meta)}).catch(function(){", "table(rows,meta);draw(rows,meta);setLoader(false,100,'Ready')}).catch(function(){setLoader(false,0,'Failed');")
txt = txt.replace("if(!(count===3&&i===1))drawDateTick(g,x,h-74*q,ts,q", "if(i===0||i===count-1)drawDateTick(g,x,h-74*q,ts,q")
txt = txt.replace("if(!(count===3&&i===1))drawDateTick(g,x,h-70*q,ts,q", "if(i===0||i===count-1)drawDateTick(g,x,h-70*q,ts,q")
# Line decimation for normal chart.
txt = txt.replace("drawAxes(g,w,h,q,mm,t0,t1,pad);g.strokeStyle='#00ffff';", "drawAxes(g,w,h,q,mm,t0,t1,pad);var lineRows=decimateRows(rows,Math.max(900,Math.floor((w/q)*1.8)));g.strokeStyle='#00ffff';")
txt = txt.replace("rows.forEach(function(r,i){var xx=X(r),yy=Y(Number(r.priceGBPperMWh));if(i)g.lineTo(xx,yy);else g.moveTo(xx,yy)});g.stroke();", "lineRows.forEach(function(r,i){var xx=X(r),yy=Y(Number(r.priceGBPperMWh));if(i)g.lineTo(xx,yy);else g.moveTo(xx,yy)});g.stroke();")
return txt
def patch_fs(txt):
# Use start and end only for axis labels, no crowded middle ticks.
txt = re.sub(r"if\(!\(count===3&&i===1\)\)\{g\.fillStyle='#f5f7fb';g\.font=10\*q\+'px Courier New';g\.textAlign=i===0\?'left':\(i===count-1\?'right':'center'\);g\.fillText\(axisLabel\(ts,span\),x,h-52\*q\)\}", "if(i===0||i===count-1){g.fillStyle='#f5f7fb';g.font=10*q+'px Courier New';g.textAlign=i===0?'left':'right';g.fillText(axisLabel(ts,span),x,h-52*q)}", txt)
txt = txt.replace("g.strokeStyle='#00ffff';g.lineWidth=2.2*q;", "var lineRows=window.decimateRows?window.decimateRows(rows,Math.max(900,Math.floor((w/q)*1.8))):rows;g.strokeStyle='#00ffff';g.lineWidth=2.2*q;")
txt = txt.replace("rows.forEach(function(x,i){var xx=X(x),yy=Y(Number(x.priceGBPperMWh));if(i)g.lineTo(xx,yy);else g.moveTo(xx,yy)});g.stroke();", "lineRows.forEach(function(x,i){var xx=X(x),yy=Y(Number(x.priceGBPperMWh));if(i)g.lineTo(xx,yy);else g.moveTo(xx,yy)});g.stroke();")
return txt
def main():
ui = patch_ui(UI.read_text())
# expose decimator for fullscreen file
if "window.decimateRows=decimateRows" not in ui:
ui = ui.replace("function decimateRows(rows,limit){", "function decimateRows(rows,limit){")
ui = ui.replace("function drawDateTick", "window.decimateRows=decimateRows;\nfunction drawDateTick", 1)
UI.write_text(ui)
FS.write_text(patch_fs(FS.read_text()))
idx = INDEX.read_text()
for old in ["20260527b","20260527c","20260527d","20260527e","20260527f","20260527g","20260527h","20260527i","20260527j","20260527k","20260527l","20260527m","20260527n"]:
idx = idx.replace(f"price-history-ui.js?v={old}", "price-history-ui.js?v=20260527o")
idx = idx.replace(f"price-history-fullscreen.js?v={old}", "price-history-fullscreen.js?v=20260527o")
INDEX.write_text(idx)
REPORT.parent.mkdir(parents=True, exist_ok=True)
REPORT.write_text(
"# V5 multi year loading patch\n\n"
"Implemented 2 year, 5 year and 10 year price history windows. Added a deliberately paced loader for 12 month, 2 year, 5 year and 10 year windows so Safari has breathing time while annual files load. Added draw decimation to reduce canvas overload while preserving true HIGH and LOW event detection from the full filtered row set. Simplified x axis labelling to full start date and full end d … [line shortened here: 478 characters; full line on GitHub]
)
if __name__ == "__main__":
main()GlobalGrid2050 Patch V5 Trend Title Safe Zone
A Python command-line tool in the scripts folder.
storageglobalgrid2050 / scripts/patch_v5_trend_title_safe_zone.py · lines 1–50 of 50 · Entry point
- What it does
- It loads data. Defines main. Uses libraries pathlib, re. Side effects: reads or writes files.
- Downstream impact
- Used directly by 1 file: GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (globalgrid2050).
- What it achieves
- No statement of purpose was found in the file, a README line naming it, or its name.
- Why it matters
- Run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib, re
- Used by
- run by GlobalGrid2050 Patch V5 Fullscreen Glow Controls Workflow (workflow run)
- Produces
- main
- Defines here
- 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 scripts/patch_v5_trend_title_safe_zone.py:1-50 · blob eb7f0890ff8c59305b46068b12f503512a620361 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: filesystem · domain stage: unknown · users: none · canonical: production_core
from pathlib import Path
import re
ROOT = Path(__file__).resolve().parents[1]
FS = ROOT / "uk_energy_tracking_v5" / "price-history-fullscreen.js"
INDEX = ROOT / "uk_energy_tracking_v5" / "index.md"
REPORT = ROOT / "gridbot_reports" / "patch_v5_trend_title_safe_zone.md"
def main():
txt = FS.read_text()
# In minimalist Trend mode, reserve a proper header band so the cyan trace cannot cut through the title.
txt = re.sub(
r"var pad=MINIMAL\?\{left:[^}]+\}:\{left:[^}]+\};",
"var pad=MINIMAL?{left:72*q,right:62*q,top:96*q,bottom:76*q}:{left:(isLandscape?238:158)*q,right:(isLandscape?74:62)*q,top:(isLandscape?76:112)*q,bottom:(isLandscape?118:142)*q};",
txt,
count=1,
)
# Keep the minimalist title visually above the chart activity zone.
txt = txt.replace(
"g.fillText(MINIMAL?'£/MWh':'ELECTRICITY PRICE £/MWh',pad.left,MINIMAL?24*q:(isLandscape?28:64)*q);",
"g.fillText(MINIMAL?'£/MWh':'ELECTRICITY PRICE £/MWh',pad.left,MINIMAL?40*q:(isLandscape?28:64)*q);",
)
# Strengthen the separation by pushing Trend mode x axis labels slightly lower but still above browser chrome.
txt = txt.replace(
"g.fillText(axisLabel(ts,span),x,h-52*q)",
"g.fillText(axisLabel(ts,span),x,MINIMAL?h-44*q:h-52*q)",
)
FS.write_text(txt)
idx = INDEX.read_text()
for old in ["20260527b", "20260527c", "20260527d", "20260527e", "20260527f", "20260527g", "20260527h", "20260527i", "20260527j", "20260527k", "20260527l", "20260527m", "20260527n", "20260527o"]:
idx = idx.replace(f"price-history-fullscreen.js?v={old}", "price-history-fullscreen.js?v=20260527p")
INDEX.write_text(idx)
REPORT.parent.mkdir(parents=True, exist_ok=True)
REPORT.write_text(
"# V5 trend title safe zone patch\n\n"
"Moved the minimalist Trend mode title into a protected header band above the chart activity zone. "
"In Trend mode the plot now starts lower, so cyan price spikes cannot cut through the `£/MWh` title. "
"The start and end date labels remain visible at the bottom, with cache key updated to 20260527p.\n"
)
if __name__ == "__main__":
main()GlobalGrid2050 Plain Language
A Python command-line tool in the scripts folder. It keeps case (`keep_case`) and is built from the rewrite text helper (`rewrite_text`) and the sub step (`sub`).
storageglobalgrid2050 / scripts/plain_language.py · lines 1–104 of 104 · Entry point · pattern visible (shared by 17 files)
- What it does
- It loads data. Defines keep_case, rewrite_text, sub, main, visible. Uses libraries __future__, re, sys, pathlib. Side effects: reads or writes files.
- Inputs & outputs
- In: command-line arguments.
- Downstream impact
- It is itself an entry point (Python CLI); no other file was found loading it.
- What it achieves
- Replace informal or science-fiction wording on the public homepage with plain business language.
- Why it matters
- No other file in the estate was found to import it; it is an entry point.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- __future__, re, sys, pathlib
- Used by
- none found
- Produces
- keep_case, rewrite_text, main
- Defines here
- keep_case, rewrite_text, sub, main, visible
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 scripts/plain_language.py:1-104 · blob 4f7a2f7d967d9b9c4cfad0fcb5dda763604b3228 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: filesystem · domain stage: unknown · users: none · canonical: production_core
#!/usr/bin/env python3
"""Replace informal or science-fiction wording on the public homepage with plain business language.
What it touches: the reader-visible text of index.html only, meaning the words inside <summary>, the link
labels and the <small> descriptions in the menu's template strings. What it never touches: hrefs, ids, class
names (for example `details.nest`, which is CSS), query strings (`?graph=vedic`), or any identifier in the
script. A term inside a URL is an address, not language, and changing it would break the link.
Default is a dry run: it prints every visible occurrence with its proposed replacement and changes nothing.
`--apply` rewrites index.html in place. The homepage rules still apply before applying: take the numbered
snapshot in homepage_versions/ first, then commit, push and compare served bytes.
python scripts/plain_language.py # report only
python scripts/plain_language.py --apply # rewrite index.html
The dictionary is deliberately small and exact-phrase first, so a word that is also a product name (the
Spider dashboard's own title "Spider Sandbox" is Vikram's design and is listed here as a decision, not
replaced by default) is never rewritten by accident.
"""
from __future__ import annotations
import re
import sys
from pathlib import Path
INDEX = Path(__file__).resolve().parent.parent / "index.html"
# exact phrases first (longest match wins), then single words; matching is case-insensitive and the
# replacement keeps the original's initial capital
PHRASES = [
("Spider universe", "Code relationship map"),
("universe journey experiment", "code navigation experiment"),
("Spider universe, ten versions", "Code relationship map, ten versions"),
("particle universe", "block and function map"),
("ring journey", "ring navigation"),
("line river", "line view"),
]
WORDS = [
("universe", "code map"),
("galaxy", "map"),
("constellation", "group"),
("swarm", "set of agents"),
("particles", "items"),
("particle", "item"),
("cosmic", "estate-wide"),
]
# Product names left alone by default; each is a decision for the owner, listed in the report.
DECISIONS = ["Spider Sandbox", "Spider", "Periodic Table", "Grid Engine", "Grid Atlas"]
VISIBLE = re.compile(r"(<summary>)(.*?)(</summary>)|(>)([^<>]*?)(<small>)|(<small>)(.*?)(</small>)|(\">)([^<>]+?)(</a>)", re.S)
def keep_case(src: str, rep: str) -> str:
return rep[0].upper() + rep[1:] if src[:1].isupper() else rep
def rewrite_text(text: str, log: list[str]) -> str:
out = text
for a, b in PHRASES + WORDS:
pat = re.compile(r"\b" + re.escape(a) + r"\b", re.I)
def sub(m, b=b):
r = keep_case(m.group(0), b)
log.append(f" {m.group(0)!r} -> {r!r}")
return r
out = pat.sub(sub, out)
return out
def main() -> int:
apply = "--apply" in sys.argv
src = INDEX.read_text(encoding="utf-8")
log: list[str] = []
def visible(m: re.Match) -> str:
g = m.groups()
# the match is one of four shapes; the text is the middle group of whichever matched
for i in (0, 3, 6, 9):
if g[i] is not None:
return g[i] + rewrite_text(g[i + 1], log) + g[i + 2]
return m.group(0)
out = VISIBLE.sub(visible, src)
print(f"{len(log)} visible replacement(s) proposed in {INDEX.name}:")
for line in log:
print(line)
for name in DECISIONS:
n = len(re.findall(r"\b" + re.escape(name) + r"\b", src))
if n:
print(f" decision for the owner: {name!r} appears {n} time(s) as a product name; left unchanged")
urls = len(re.findall(r"href=\"[^\"]*(universe|vedic|chemistry|stars)[^\"]*\"", src))
print(f" {urls} link address(es) contain such words and are left exactly as they are")
if not apply:
print("dry run: nothing written (use --apply)")
return 0
if out == src:
print("nothing to change")
return 0
INDEX.write_text(out, encoding="utf-8")
print("index.html rewritten; take the homepage_versions snapshot before committing")
return 0
if __name__ == "__main__":
raise SystemExit(main())