Spaces:
Running
Running
Download datasets.py from kugguk/electrocheap: direct link, hf CLI and curl.
- Browser
- Download file 4.93 kB
-
https://huggingface.co/spaces/kugguk/electrocheap/resolve/main/datasets.py
- Command line
-
hf download hf://spaces/kugguk/electrocheap/datasets.py
-
curl -L -o datasets.py https://huggingface.co/spaces/kugguk/electrocheap/resolve/main/datasets.py
4.93 kB
| """Public benchmark data only. Customer billing imports never enter this registry.""" | |
| from io import BytesIO | |
| from pathlib import Path | |
| from zipfile import ZipFile, ZIP_DEFLATED | |
| import csv | |
| import hashlib | |
| import json | |
| ROOT=Path(__file__).resolve().parent | |
| REGISTRY={ | |
| "pt-grid-monthly":("data/pt_monthly.csv","REN Portugal national grid demand","GWh","data/pt_provenance.json"), | |
| "de-grid-monthly":("data/de_monthly.csv","SMARD Germany national grid demand","GWh","data/de_provenance.json"), | |
| "au-nem-monthly":("data/au_monthly.csv","AEMO Australia five-region NEM demand proxy","GWh","data/au_provenance.json"), | |
| "model-test-metrics":("evidence/full_model_benchmark/outputs/test_metrics.csv","Archived model test scores","mixed metrics",None), | |
| "model-test-predictions":("evidence/full_model_benchmark/outputs/test_predictions_with_truth.csv","Archived test predictions and observed truth","GWh",None), | |
| "grokked-extension-predictions":("evidence/sarima_rl_extension/outputs/test_forecasts.csv","DE/AU SARIMA-bias-RL extension predictions","GWh",None), | |
| } | |
| def manifest(): | |
| output=[] | |
| for key,(relative,title,unit,provenance) in REGISTRY.items(): | |
| path=ROOT/relative | |
| if not path.is_file(): | |
| continue | |
| rows=list(csv.DictReader(path.open())) | |
| item={"dataset_id":key,"title":title,"unit":unit,"rows":len(rows),"bytes":path.stat().st_size, | |
| "sha256":hashlib.sha256(path.read_bytes()).hexdigest(),"download_path":f"/api/datasets/{key}/download"} | |
| if provenance and (ROOT/provenance).is_file(): | |
| item["provenance"]=json.loads((ROOT/provenance).read_text()) | |
| output.append(item) | |
| return {"status":"public_auditable_datasets","datasets":output, | |
| "privacy":"Official grid snapshots and already recorded benchmark evidence only. User bills, normalized customer usage and private jobs are excluded.", | |
| "archive_scope":"Historical snapshots through September 2026; not a live provider-tariff history. Hosted LLM lanes contain delegated diagnostics rather than independently authenticated API competitor measurements."} | |
| def dataset_inspect(payload): | |
| selected=payload.get("dataset_id") | |
| catalog=manifest() | |
| if not selected: | |
| return catalog | |
| if selected not in REGISTRY or not (ROOT/REGISTRY[selected][0]).is_file(): | |
| raise ValueError("Unknown dataset_id; request the manifest first.") | |
| offset=payload.get("offset",0);limit=payload.get("limit",100) | |
| if isinstance(offset,bool) or isinstance(limit,bool) or not isinstance(offset,int) or not isinstance(limit,int) or offset<0 or not 1<=limit<=1000: | |
| raise ValueError("Use integer offset>=0 and limit 1–1000.") | |
| path=ROOT/REGISTRY[selected][0] | |
| rows=list(csv.DictReader(path.open())) | |
| metadata=next(x for x in catalog["datasets"] if x["dataset_id"]==selected) | |
| return {**metadata,"records":rows[offset:offset+limit],"next_offset":offset+limit if offset+limit<len(rows) else None} | |
| def public_audit_archive(): | |
| catalog=manifest() | |
| files={} | |
| for item in catalog["datasets"]: | |
| relative,_,_,provenance=REGISTRY[item["dataset_id"]] | |
| files[relative]=(ROOT/relative).read_bytes() | |
| if provenance and (ROOT/provenance).is_file(): | |
| files[provenance]=(ROOT/provenance).read_bytes() | |
| for relative in ["benchmark.py","evidence/full_model_benchmark/protocol.json", | |
| "evidence/full_model_benchmark/scoring_policy.json","evidence/full_model_benchmark/foundation_config.json", | |
| "evidence/full_model_benchmark/vendor/forecast_lab_pro_v2/SNAPSHOT.json", | |
| "evidence/sarima_rl_extension/protocol.json","evidence/sarima_rl_extension/outputs/selection.json", | |
| "evidence/full_model_benchmark/outputs/selection.json", | |
| "evidence/full_model_benchmark/benchmark_core.py", | |
| "evidence/full_model_benchmark/score_benchmark.py", | |
| "evidence/full_model_benchmark/foundation_runner.py", | |
| "evidence/full_model_benchmark/foundation_manifest.json", | |
| "evidence/full_model_benchmark/outputs/calibration_parameters.csv", | |
| "evidence/full_model_benchmark/outputs/development_metrics.csv", | |
| "evidence/full_model_benchmark/outputs/classical_environment.json", | |
| "evidence/sarima_rl_extension/source_reference/grokked_sarima.py"]: | |
| path=ROOT/relative | |
| if path.is_file(): | |
| files[relative]=path.read_bytes() | |
| hashes={name:hashlib.sha256(body).hexdigest() for name,body in files.items()} | |
| files["manifest.json"]=json.dumps({**catalog,"files_sha256":hashes},indent=2).encode() | |
| buf=BytesIO() | |
| with ZipFile(buf,"w",ZIP_DEFLATED) as archive: | |
| for name,body in files.items(): | |
| archive.writestr(name,body) | |
| return buf.getvalue() | |