In this section
- GlobalGrid2050 Patch V3 Price History Date Window energy-data · globalgrid2050 / scripts/patch_v3_price_history_date_window.py lines 1–80
- GlobalGrid2050 Patch V3 Price History Fullscreen energy-data · globalgrid2050 / scripts/patch_v3_price_history_fullscreen.py lines 1–57
- GlobalGrid2050 Patch V3 Price History Merge System energy-data · globalgrid2050 / scripts/patch_v3_price_history_merge_system.py lines 1–28
- GlobalGrid2050 Patch V3 Price History UI energy-data · globalgrid2050 / scripts/patch_v3_price_history_ui.py lines 1–387
- GlobalGrid2050 Patch V3 Price Lazy Selectors energy-data · globalgrid2050 / scripts/patch_v3_price_lazy_selectors.py lines 1–79
GlobalGrid2050 Patch V3 Price History Date Window
A Python command-line tool in the scripts folder that reads electricity price history.
energy-dataglobalgrid2050 / scripts/patch_v3_price_history_date_window.py · lines 1–80 of 80 · Entry point · pattern patch_diary (shared by 6 files)
- What it does
- It loads electricity price history. Defines patch_page, patch_css, patch_js, patch_diary, main. Uses libraries pathlib. 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
- In: CSV file electricity_price_history.csv; form fields (user input).
- Downstream impact
- Used directly by 2 files: GlobalGrid2050 Gridbot V3 Consolidated Price History Workflow (globalgrid2050); GlobalGrid2050 Patch V3 Price History Date Window Workflow (globalgrid2050).
- What it achieves
- Defines `patch_page`, `patch_css`, `patch_js` and 1 more.
- Why it matters
- Run by GlobalGrid2050 Gridbot V3 Consolidated Price History Workflow and GlobalGrid2050 Patch V3 Price History Date Window Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib
- Used by
- run by GlobalGrid2050 Gridbot V3 Consolidated Price History Workflow (workflow run), run by GlobalGrid2050 Patch V3 Price History Date Window Workflow (workflow run)
- Produces
- patch_page, patch_css, patch_js, patch_diary, main
- Defines here
- patch_page, patch_css, patch_js, patch_diary, 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_v3_price_history_date_window.py:1-80 · blob a7a44c71ea591aef674518e136f45e9fbc245676 · 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
from pathlib import Path
PAGE = Path('uk_energy_tracking_v3/index.md')
CSS = Path('uk_energy_tracking_v3/price-history-ui.css')
JS = Path('uk_energy_tracking_v3/price-history-ui.js')
DIARY = Path('uk_energy_tracking_v3/WORK_DIARY.md')
DATE_HTML = '''
<label class="price-history-date-label">From <input type="date" id="price-history-from"></label>
<label class="price-history-date-label">To <input type="date" id="price-history-to"></label>
<button type="button" id="price-history-apply-dates" class="price-history-date-apply">Apply dates</button>'''
CSS_ADD = '''
/* V3 price history date window 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}
'''
DIARY_MARKER = '## Diary entry: 2026-05-26 V3 price history date window controls patch'
def patch_page():
text = PAGE.read_text(encoding='utf-8')
if 'id="price-history-from"' not in text:
text = text.replace(' <a href="/uk_energy_tracking_v3/electricity_price_history.csv" download>Download CSV</a>', DATE_HTML + '\n <a href="/uk_energy_tracking_v3/electricity_price_history.csv" download>Download CSV</a>', 1)
PAGE.write_text(text, encoding='utf-8')
def patch_css():
text = CSS.read_text(encoding='utf-8')
if 'price-history-date-window controls' not in text and 'price-history-date-label' not in text:
text = text.rstrip() + CSS_ADD
CSS.write_text(text, encoding='utf-8')
def patch_js():
text = JS.read_text(encoding='utf-8')
if 'function customDateWindow' not in text:
anchor = ' function cutoff(range){\n'
insert = ''' function customDateWindow(){
var fromEl = document.getElementById("price-history-from");
var toEl = document.getElementById("price-history-to");
if(!fromEl || !toEl || !fromEl.value || !toEl.value) return null;
var start = new Date(fromEl.value + "T00:00:00Z");
var end = new Date(toEl.value + "T23:59:59Z");
if(isNaN(start) || isNaN(end) || end < start) return null;
var maxMs = 60 * 24 * 60 * 60 * 1000;
if(end - start > maxMs){
end = new Date(start.getTime() + maxMs);
}
return {start:start, end:end, label:fromEl.value + " to " + end.toISOString().slice(0,10)};
}
'''
text = text.replace(anchor, insert + anchor, 1)
old = ' var cut = cutoff(range);\n var rows = cut ? allRows.filter(function(r){ return new Date(r.priceTimeUTC) >= cut; }) : allRows;'
new = ' var custom = customDateWindow();\n var cut = cutoff(range);\n var rows = custom ? allRows.filter(function(r){ var t = new Date(r.priceTimeUTC); return t >= custom.start && t <= custom.end; }) : (cut ? allRows.filter(function(r){ return new Date(r.priceTimeUTC) >= cut; }) : allRows);\n var activeRangeLabel = custom ? custom.label : range;'
text = text.replace(old, new)
text = text.replace(' renderTable(rows, range);\n draw(rows, range);', ' renderTable(rows, activeRangeLabel);\n draw(rows, activeRangeLabel);')
if 'price-history-apply-dates' not in text:
old2 = ' if(rangeEl) rangeEl.addEventListener("change", load);\n load();'
new2 = ' if(rangeEl) rangeEl.addEventListener("change", load);\n var applyDates = document.getElementById("price-history-apply-dates");\n if(applyDates) applyDates.addEventListener("click", load);\n var fromEl = document.getElementById("price-history-from");\n var toEl = document.getElementById("price-history-to");\n if(fromEl) fromEl.addEventListener("change", load);\n … [line shortened here: 463 characters; full line on GitHub]
text = text.replace(old2, new2)
JS.write_text(text, encoding='utf-8')
def patch_diary():
text = DIARY.read_text(encoding='utf-8')
if DIARY_MARKER not in text:
text += '\n\n' + DIARY_MARKER + '\n\nAdded browser date inputs above the V3 price history chart so users can inspect any retained date window without rendering the entire half hourly table at once. Custom date windows are capped to 60 days for chart and table usability. The dropdown ranges remain available for quick views and All captured data remains available for broad context.\n'
DIARY.write_text(text, encoding='utf-8')
def main():
patch_page(); patch_css(); patch_js(); patch_diary()
print('patched V3 price history date window controls')
if __name__ == '__main__':
main()GlobalGrid2050 Patch V3 Price History Fullscreen
A Python command-line tool in the scripts folder that writes changed (`write_if_changed`), covering electricity price history.
energy-dataglobalgrid2050 / scripts/patch_v3_price_history_fullscreen.py · lines 1–57 of 57 · Entry point · pattern write_if_changed (shared by 3 files)
- What it does
- It draws electricity price history. Defines write_if_changed, main. Uses libraries pathlib. Side effects: changes the web page (DOM); reads or writes files; 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; CSV file electricity_price_history.csv. Out: canvas drawing.
- Downstream impact
- Used directly by 2 files: GlobalGrid2050 Gridbot V3 Consolidated Price History Workflow (globalgrid2050); GlobalGrid2050 Patch V3 Price History Fullscreen Workflow (globalgrid2050).
- What it achieves
- Defines `write_if_changed`.
- Why it matters
- Run by GlobalGrid2050 Gridbot V3 Consolidated Price History Workflow and GlobalGrid2050 Patch V3 Price History Fullscreen Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib
- Used by
- run by GlobalGrid2050 Gridbot V3 Consolidated Price History Workflow (workflow run), run by GlobalGrid2050 Patch V3 Price History Fullscreen Workflow (workflow run)
- Produces
- write_if_changed, main
- Defines here
- write_if_changed, 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_v3_price_history_fullscreen.py:1-57 · blob 89d26664f4deed97414d0f5782f9495015f4b66d · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem, network · domain stage: hv_procurement · users: EPC_contractor, procurement_buyer · canonical: production_core
from pathlib import Path
PAGE = Path('uk_energy_tracking_v3/index.md')
CSS = Path('uk_energy_tracking_v3/price-history-ui.css')
JS = Path('uk_energy_tracking_v3/price-history-fullscreen.js')
DIARY = Path('uk_energy_tracking_v3/WORK_DIARY.md')
BUTTON = '<button type="button" id="price-history-fullscreen-btn" class="price-history-fullscreen-btn">Full screen chart</button>'
SCRIPT = "<script src='/uk_energy_tracking_v3/price-history-fullscreen.js'></script>"
OVERLAY = '''
<div id="price-history-fullscreen-overlay" class="price-history-fullscreen-overlay">
<div class="price-history-fullscreen-shell">
<div class="price-history-fullscreen-toolbar">
<strong>Electricity Price History</strong>
<span id="price-history-fullscreen-meta">Captured Elexon market index prices</span>
<button type="button" id="price-history-zoom-out">Zoom out</button>
<button type="button" id="price-history-zoom-in">Zoom in</button>
<button type="button" id="price-history-zoom-reset">Reset</button>
<button type="button" id="price-history-fullscreen-close">Close</button>
</div>
<canvas id="price-history-fullscreen-canvas"></canvas>
<div class="price-history-fullscreen-note">Wheel to zoom. Drag to pan. Esc closes the chart.</div>
</div>
</div>
'''
CSS_APPEND = '''
/* V3 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}.price- … [line shortened here: 1,620 characters; full line on GitHub]
'''
JS_TEXT = r'''(function(){var URL='/uk_energy_tracking_v3/electricity_price_history.json';var S={rows:[],a:0,b:1,drag:false,x:0};function E(i){return document.getElementById(i)}function F(n){return Number(n).toLocaleString('en-GB',{minimumFractionDigits:2,maximumFractionDigits:2})}function D(t){return new Date(t).toLocaleString('en-GB',{day:'2-digit',month:'short',hour:'2-digit',minute:'2-digit'}) … [line shortened here: 4,111 characters; full line on GitHub]
DIARY_MARKER='## Diary entry: 2026-05-25 V3 price history full screen chart patch'
DIARY_ENTRY='''\n\n## Diary entry: 2026-05-25 V3 price history full screen chart patch\n\nPurpose:\n\n```text\nadd a large full screen electricity price history chart with zoom and pan while keeping the stable tracker untouched\n```\n\nPatch method:\n\n```text\nadd full screen chart button\nadd full screen overlay and large canvas\nload V3 captured electricity price history JSON\nsupport wheel zoo … [line shortened here: 523 characters; full line on GitHub]
def write_if_changed(path,text):
old=path.read_text(encoding='utf-8') if path.exists() else ''
if old==text:return False
path.write_text(text,encoding='utf-8');return True
def main():
text=PAGE.read_text(encoding='utf-8')
if BUTTON not in text:text=text.replace('<a href="/uk_energy_tracking_v3/electricity_price_history.csv" download>Download CSV</a>','<a href="/uk_energy_tracking_v3/electricity_price_history.csv" download>Download CSV</a>\n '+BUTTON,1)
if 'price-history-fullscreen-overlay' not in text:text=text.replace('\n <div class="scada-status" id="scada-status">',OVERLAY+'\n\n <div class="scada-status" id="scada-status">',1)
if SCRIPT not in text:text=text.replace("<script src='/uk_energy_tracking_v3/price-history-ui.js'></script>","<script src='/uk_energy_tracking_v3/price-history-ui.js'></script>\n"+SCRIPT,1)
write_if_changed(PAGE,text)
css=CSS.read_text(encoding='utf-8')
if 'V3 price history fullscreen chart' not in css:css=css.rstrip()+CSS_APPEND
write_if_changed(CSS,css)
write_if_changed(JS,JS_TEXT)
diary=DIARY.read_text(encoding='utf-8')
if DIARY_MARKER not in diary:write_if_changed(DIARY,diary.rstrip()+DIARY_ENTRY+'\n')
print('Prepared V3 price history full screen chart patch')
if __name__=='__main__':main()GlobalGrid2050 Patch V3 Price History Merge System
A Python command-line tool in the scripts folder that reads Elexon system prices half hourly.
energy-dataglobalgrid2050 / scripts/patch_v3_price_history_merge_system.py · lines 1–28 of 28 · Entry point
- What it does
- It loads Elexon system prices half hourly. Defines main. Uses libraries pathlib. 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
- In: CSV file elexon_system_prices_half_hourly.csv.
- Downstream impact
- Used directly by 2 files: GlobalGrid2050 Gridbot V3 Consolidated Price History Workflow (globalgrid2050); GlobalGrid2050 Patch V3 Price History Merge System 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 Gridbot V3 Consolidated Price History Workflow and GlobalGrid2050 Patch V3 Price History Merge System Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib
- Used by
- run by GlobalGrid2050 Gridbot V3 Consolidated Price History Workflow (workflow run), run by GlobalGrid2050 Patch V3 Price History Merge System 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_v3_price_history_merge_system.py:1-28 · blob cdb4ec2667e6e1673e503215ff66b12db7e604b3 · 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
from pathlib import Path
JS = Path('uk_energy_tracking_v3/price-history-ui.js')
DIARY = Path('uk_energy_tracking_v3/WORK_DIARY.md')
MARKER = '## Diary entry: 2026-05-26 V3 merged price source patch'
def main():
text = JS.read_text(encoding='utf-8')
text = text.replace('var ENABLE_CSV_FEED = false;', 'var ENABLE_CSV_FEED = true;')
text = text.replace('var CSV_URL = "/uk_energy_tracking_v3/elexon_system_prices_half_hourly.csv";', 'var CSV_URL = "/data/electricity/elexon_system_prices_half_hourly.csv";')
if 'function mergeSystemAndCapturedRows' not in text:
anchor = ' function load(){\n var rangeEl = document.getElementById("price-history-range");'
insert = ' function mergeSystemAndCapturedRows(systemRows, capturedRows){\n var merged = {};\n (systemRows || []).forEach(function(r){ if(r.priceTimeUTC){ merged[r.priceTimeUTC] = Object.assign({}, r, {source:"Elexon BMRS System Prices", priceHealth:(r.priceHealth || "historical system price")}); } });\n (capturedRows || []).forEach(function(r){ if(r.priceTimeUTC){ merged[r.price … [line shortened here: 640 characters; full line on GitHub]
text = text.replace(anchor, insert + anchor, 1)
text = text.replace('var allRows = csvRows.length ? csvRows : jsonRows;', 'var allRows = mergeSystemAndCapturedRows(csvRows, jsonRows);')
text = text.replace('setText("ph-source", latest && latest.source ? latest.source : "Elexon BMRS");', 'setText("ph-source", csvRows.length ? "Historical Elexon System Prices plus V3 captured Market Index" : (latest && latest.source ? latest.source : "Elexon BMRS"));')
JS.write_text(text, encoding='utf-8')
diary = DIARY.read_text(encoding='utf-8')
if MARKER not in diary:
diary += '\n\n' + MARKER + '\n\nMerged the existing Elexon historical system price CSV with the V3 captured live Market Index trail. The chart and dropdown now use historical context plus new live captured rows, while the live gauge remains separate. System Prices and Market Index Prices remain labelled as different price products.\n'
DIARY.write_text(diary, encoding='utf-8')
print('patched merged V3 price source')
if __name__ == '__main__':
main()GlobalGrid2050 Patch V3 Price History UI
A Python command-line tool in the scripts folder that writes changed (`write_if_changed`), extracts panel (`extract_panel`) and patches page (`patch_page`).
energy-dataglobalgrid2050 / scripts/patch_v3_price_history_ui.py · lines 1–387 of 387 · Entry point · pattern ensure_linked_css (shared by 2 files)
- What it does
- It loads data. Defines 10 functions or classes, including read, write_if_changed, extract_panel, ensure_linked_css, ensure_panel_after_generation_mix. Uses libraries pathlib. Side effects: 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.
- Downstream impact
- Used directly by 2 files: GlobalGrid2050 Patch V3 Price History UI Workflow (globalgrid2050); GlobalGrid2050 V3 UI Patch Workflow (globalgrid2050).
- What it achieves
- It is built from the ensure linked CSS helper (`ensure_linked_css`) and the collapse price table helper (`collapse_price_table`). Defines `read`, `write_if_changed`, `extract_panel` and 6 more.
- Why it matters
- Run by GlobalGrid2050 Patch V3 Price History UI Workflow and GlobalGrid2050 V3 UI Patch Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib
- Used by
- run by GlobalGrid2050 Patch V3 Price History UI Workflow (workflow run), run by GlobalGrid2050 V3 UI Patch Workflow (workflow run)
- Produces
- read, write_if_changed, extract_panel, ensure_linked_css, ensure_panel_after_generation_mix, collapse_price_table, patch_page, patch_css, patch_diary, main
- Defines here
- read, write_if_changed, extract_panel, ensure_linked_css, ensure_panel_after_generation_mix, collapse_price_table, patch_page, patch_css, patch_diary, 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_v3_price_history_ui.py:1-387 · blob 1e031b83538735cd877b7f743307513f57714b9e · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: filesystem · domain stage: hv_procurement · users: EPC_contractor, procurement_buyer · canonical: production_core
from pathlib import Path
PAGE = Path("uk_energy_tracking_v3/index.md")
CSS = Path("uk_energy_tracking_v3/price-history-ui.css")
DIARY = Path("uk_energy_tracking_v3/WORK_DIARY.md")
CSS_LINK = '<link rel="stylesheet" href="/uk_energy_tracking_v3/price-history-ui.css">'
IMPORT_LINE = "@import url('/uk_energy_tracking_v3/price-history-ui.css');"
PANEL_START = ' <section id="electricity-price-history-panel">'
PANEL_END = "\n </section>"
CSS_TEXT = r'''
#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(190px, 32vw, 300px) !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;
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;
}
#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: 260px;
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: 680px;
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(4) {
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: 220px !important; }
#electricity-price-history-panel table.price-history-table { font-size: 11px; min-width: 620px; }
}
@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: 210px !important; }
}
'''.strip() + "\n"
DIARY_MARKER = "## Diary entry: 2026-05-25 V3 price history table dark UI patch"
DIARY_ENTRY = f'''
{DIARY_MARKER}
Purpose:
```text
repair the electricity price history table UI on mobile and desktop
keep the V3 development tracker isolated
avoid touching the stable tracker
```
Issue observed:
```text
The V3 price history table rendered with a white table background while the rest of the SCADA page remained dark.
The graph also risked overflowing on mobile if the external stylesheet was not loaded properly.
The table made the page visually heavy because it exposed raw records directly under the graph.
```
Patch method:
```text
remove the late CSS import from the inline style block
insert a normal stylesheet link for /uk_energy_tracking_v3/price-history-ui.css
rewrite the price history CSS with scoped high specificity rules under #electricity-price-history-panel
force dark table background, dark rows, cyan headings and readable body text
make the chart width responsive so it fits inside the page container
move the raw records table inside a closed details dropdown by default
retain CSV download for full data review
```
Files intentionally changed by GridBot workflow:
```text
uk_energy_tracking_v3/index.md
uk_energy_tracking_v3/price-history-ui.css
uk_energy_tracking_v3/WORK_DIARY.md
```
Stable tracker rule:
```text
No changes to uk_energy_tracking/.
```
'''
def read(path: Path) -> str:
return path.read_text(encoding="utf-8")
def write_if_changed(path: Path, text: str) -> bool:
old = path.read_text(encoding="utf-8") if path.exists() else ""
if old == text:
return False
path.write_text(text, encoding="utf-8")
return True
def extract_panel(text: str) -> tuple[str, str]:
start = text.find(PANEL_START)
if start == -1:
return text, ""
end = text.find(PANEL_END, start)
if end == -1:
raise RuntimeError("Could not locate end of electricity price history panel")
end += len(PANEL_END)
return text[:start] + text[end:], text[start:end]
def ensure_linked_css(text: str) -> str:
text = text.replace(IMPORT_LINE + "\n", "")
text = text.replace(IMPORT_LINE, "")
if CSS_LINK in text:
return text
style_pos = text.find("<style>")
if style_pos == -1:
raise RuntimeError("Could not locate opening style block")
return text[:style_pos] + CSS_LINK + "\n" + text[style_pos:]
def ensure_panel_after_generation_mix(text: str) -> str:
text, panel = extract_panel(text)
if not panel:
return text
generation_mix = ' <section>\n <h2 class="section-title">Generation Mix</h2>\n <div id="scada-mix" class="scada-mix-grid"></div>\n </section>'
if generation_mix not in text:
raise RuntimeError("Generation Mix block not found. V3 structure has changed.")
return text.replace(generation_mix, generation_mix + panel, 1)
def collapse_price_table(text: str) -> str:
if 'class="price-history-table-toggle"' in text:
return text
old = ''' <div class="price-history-table-wrap">
<table class="price-history-table">
<thead><tr><th>Settlement time</th><th>Price GBP/MWh</th><th>Captured UTC</th><th>Carbon g/kWh</th></tr></thead>
<tbody id="price-history-table-body"><tr><td colspan="4">Awaiting captured price history.</td></tr></tbody>
</table>
</div>'''
new = ''' <details class="price-history-table-toggle">
<summary>Captured records table</summary>
<div class="price-history-table-wrap">
<table class="price-history-table">
<thead><tr><th>Settlement time</th><th>Price GBP/MWh</th><th>Captured UTC</th><th>Carbon g/kWh</th></tr></thead>
<tbody id="price-history-table-body"><tr><td colspan="4">Awaiting captured price history.</td></tr></tbody>
</table>
</div>
</details>'''
if old not in text:
raise RuntimeError("Price history table block not found. V3 structure has changed.")
return text.replace(old, new, 1)
def patch_page() -> bool:
text = read(PAGE)
text = text.replace("UK LIVE GRID TRACKER V2", "UK LIVE GRID TRACKER V3")
text = text.replace("This page uses isolated V2 feeds", "This page uses isolated V3 feeds")
text = ensure_linked_css(text)
text = ensure_panel_after_generation_mix(text)
text = collapse_price_table(text)
if "price-history-ui.js" not in text:
text = text.replace(
"</div>\n\n<script>",
"</div>\n<script src='/uk_energy_tracking_v3/price-history-ui.js'></script>\n\n<script>",
)
if IMPORT_LINE in text:
raise RuntimeError("Late CSS import still present")
if CSS_LINK not in text:
raise RuntimeError("Price history stylesheet link was not inserted")
if 'class="price-history-table-toggle"' not in text:
raise RuntimeError("Price history table was not collapsed")
return write_if_changed(PAGE, text)
def patch_css() -> bool:
return write_if_changed(CSS, CSS_TEXT)
def patch_diary() -> bool:
text = read(DIARY)
if DIARY_MARKER in text:
return False
return write_if_changed(DIARY, text.rstrip() + DIARY_ENTRY + "\n")
def main() -> None:
changed = []
if patch_page():
changed.append(str(PAGE))
if patch_css():
changed.append(str(CSS))
if patch_diary():
changed.append(str(DIARY))
if changed:
print("Patched V3 price history UI:")
for path in changed:
print(f" {path}")
else:
print("V3 price history UI already patched")
if __name__ == "__main__":
main()GlobalGrid2050 Patch V3 Price Lazy Selectors
A Python command-line tool in the scripts folder that patches page (`patch_page`) and js (`patch_js`) and patches fs (`patch_fs`).
energy-dataglobalgrid2050 / scripts/patch_v3_price_lazy_selectors.py · lines 1–79 of 79 · Entry point · pattern patch_fs (shared by 2 files)
- What it does
- It draws its content. Defines patch_page, patch_js, patch_fs, patch_diary, main. Uses libraries pathlib, re. Side effects: changes the web page (DOM); reads or writes files; 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: form fields (user input).
- Downstream impact
- Used directly by 1 file: GlobalGrid2050 Patch V3 Price Lazy Selectors Workflow (globalgrid2050).
- What it achieves
- Defines `patch_page`, `patch_js`, `patch_fs` and 1 more.
- Why it matters
- Run by GlobalGrid2050 Patch V3 Price Lazy Selectors Workflow.
- Application
- globalgrid2050 · scripts · Python CLI
- Uses
- pathlib, re
- Used by
- run by GlobalGrid2050 Patch V3 Price Lazy Selectors Workflow (workflow run)
- Produces
- patch_page, patch_js, patch_fs, patch_diary, main
- Defines here
- patch_page, patch_js, patch_fs, patch_diary, 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_v3_price_lazy_selectors.py:1-79 · blob 561658fc4cb82be72b1202b1e3c7a4b3de3d7291 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem, network · domain stage: hv_procurement · users: EPC_contractor, procurement_buyer · canonical: production_core
from pathlib import Path
PAGE = Path('uk_energy_tracking_v3/index.md')
JS = Path('uk_energy_tracking_v3/price-history-ui.js')
FS = Path('uk_energy_tracking_v3/price-history-fullscreen.js')
DIARY = Path('uk_energy_tracking_v3/WORK_DIARY.md')
def patch_page():
text = PAGE.read_text(encoding='utf-8')
old = '''<h2 class="section-title">Electricity Price History</h2>'''
text = text.replace(old, '<h2 class="section-title">Half Hourly Electricity Price Settlement History, £/MWh</h2>', 1)
start = text.find('<select id="price-history-range">')
end = text.find('</select>', start)
if start != -1 and end != -1:
end += len('</select>')
new_controls = '''<select id="price-history-range">
<option value="7d">1 week</option>
<option value="1m" selected>1 month</option>
<option value="3m">3 months</option>
<option value="6m">6 months</option>
<option value="12m">12 months</option>
</select>
<select id="price-history-year" aria-label="Price history year"></select>
<select id="price-history-season" aria-label="Price history season">
<option value="all" selected>All seasons</option>
<option value="spring">Spring</option>
<option value="summer">Summer</option>
<option value="autumn">Autumn</option>
<option value="winter">Winter</option>
</select>'''
text = text[:start] + new_controls + text[end:]
desc = '''<div class="unit-panel"><strong>Unit:</strong> pounds per megawatt hour (£/MWh). <strong>Resolution:</strong> half hourly settlement period. <strong>Source:</strong> Elexon Balancing Mechanism Reporting Service (BMRS), System Prices. <strong>Attribution:</strong> Data provided by Elexon Limited via the Balancing Mechanism Reporting Service (BMRS). Official source: Elexon BMRS. <stron … [line shortened here: 586 characters; full line on GitHub]
import re
text = re.sub(r'<div class="unit-panel"><strong>Unit:</strong> pounds per Megawatt hour\..*?</div>', desc, text, count=1)
text = text.replace("price-history-ui.js?v=20260526d", "price-history-ui.js?v=20260526j")
text = text.replace("price-history-fullscreen.js?v=20260526d", "price-history-fullscreen.js?v=20260526j")
PAGE.write_text(text, encoding='utf-8')
def patch_js():
text = JS.read_text(encoding='utf-8')
if 'function populateYears()' not in text:
insert_before = 'function customWindow(){'
helper = "function populateYears(){var y=$('price-history-year');if(!y||y.options.length)return;var cur=new Date().getUTCFullYear();for(var yr=cur;yr>=2016;yr--){var o=document.createElement('option');o.value=String(yr);o.textContent=String(yr);y.appendChild(o)}}\nfunction selectedYear(){var y=$('price-history-year'),cur=new Date().getUTCFullYear(),v=y&&y.value?Number(y.value):cur;return(! … [line shortened here: 1,028 characters; full line on GitHub]
text = text.replace(insert_before, helper + insert_before, 1)
text = text.replace("function loadCsv(){return fetch(CSV_URL+'?t='+Date.now(),{cache:'no-store'}).then(r=>r.ok?r.text():'').then(parseCsv).catch(()=>[])}", "function loadCsv(){var y=selectedYear();return fetch('/data/electricity/elexon_system_prices_'+y+'.csv?t='+Date.now(),{cache:'no-store'}).then(r=>r.ok?r.text():'').then(parseCsv).catch(()=>[])}")
import re
text = re.sub(r"function rangeWindow\(range,all\)\{.*?return\{start:new Date\(now.getTime\(\)-days\*86400000\),end:now,label:range,custom:false\}\}", "function rangeWindow(range,all){var y=selectedYear(),cw=customWindow();if(cw)return cw;var se=$('price-history-season'),sw=seasonWindow(y,se?se.value:'all');if(sw)return sw;var end=(y===new Date().getUTCFullYear())?new Date():new Date(Date.UTC(y … [line shortened here: 656 characters; full line on GitHub]
if 'function drawZero(' not in text:
text = text.replace("function draw(rows,meta){", "function drawZero(g,y,w,p,rp,q){g.save();g.strokeStyle='rgba(255,255,255,.55)';g.lineWidth=2*q;g.setLineDash([7*q,5*q]);g.beginPath();g.moveTo(p,y);g.lineTo(w-rp,y);g.stroke();g.setLineDash([]);g.fillStyle='#ffffff';g.fillText('£0',8*q,y-6*q);g.restore()}\nfunction draw(rows,meta){", 1)
text = text.replace("g.strokeStyle='#00ffff';g.lineWidth=2.2*q;", "if(mm.lo<0&&mm.hi>0)drawZero(g,Y(0),w,p,rp,q);g.strokeStyle='#00ffff';g.lineWidth=2.2*q;", 1)
text = text.replace("function load(){var rangeEl=$('price-history-range'),range=rangeEl?rangeEl.value:'7d';", "function load(){populateYears();var rangeEl=$('price-history-range'),range=rangeEl?rangeEl.value:'1m';")
text = text.replace("document.addEventListener('DOMContentLoaded',function(){var r=$('price-history-range'),f=$('price-history-from'),t=$('price-history-to'),cl=$('price-history-clear-dates');if(r)r.addEventListener('change',load);", "document.addEventListener('DOMContentLoaded',function(){populateYears();var r=$('price-history-range'),y=$('price-history-year'),s=$('price-history-season'),f=$( … [line shortened here: 599 characters; full line on GitHub]
text = text.replace("var av=all.length?dlab(all[0].priceTimeUTC)+' to '+dlab(all[all.length-1].priceTimeUTC):'no source data';s.textContent='Selected range: '", "var av=all.length?dlab(all[0].priceTimeUTC)+' to '+dlab(all[all.length-1].priceTimeUTC):'no annual source data';s.textContent='Snapshot year: '+selectedYear()+' | Selected range: '")
JS.write_text(text, encoding='utf-8')
def patch_fs():
text = FS.read_text(encoding='utf-8')
if 'function drawZero(' not in text:
text = text.replace("function draw(){", "function drawZero(g,y,w,p,rp,q){g.save();g.strokeStyle='rgba(255,255,255,.55)';g.lineWidth=2*q;g.setLineDash([7*q,5*q]);g.beginPath();g.moveTo(p,y);g.lineTo(w-rp,y);g.stroke();g.setLineDash([]);g.fillStyle='#ffffff';g.fillText('£0',10*q,y-6*q);g.restore()}function draw(){", 1)
text = text.replace("g.strokeStyle='#00ffff';g.lineWidth=2.2*q;", "if(m.lo<0&&m.hi>0)drawZero(g,Y(0),w,p,rp,q);g.strokeStyle='#00ffff';g.lineWidth=2.2*q;", 1)
FS.write_text(text, encoding='utf-8')
def patch_diary():
text = DIARY.read_text(encoding='utf-8')
marker = '## Diary entry: 2026-05-26 V3 annual lazy loading UI and attribution'
if marker not in text:
text += '\n\n' + marker + '\n\nAdded annual lazy loading controls for V3 electricity price history. The browser should now load one annual Elexon System Price CSV at a time through the year selector, rather than attempting to render the full 2016 to present archive. Period choices are 1 week, 1 month, 3 months, 6 months and 12 months. Seasonal filters were added for spring, summer, autumn … [line shortened here: 719 characters; full line on GitHub]
DIARY.write_text(text, encoding='utf-8')
def main():
patch_page(); patch_js(); patch_fs(); patch_diary(); print('patched V3 annual lazy selectors, attribution and zero line')
if __name__ == '__main__':
main()