Add current €/kWh prices per charger across the stack

NDW already publishes OCPI tariffs (embedded per connector); resolve the
cheapest currently-applicable ENERGY price and surface it everywhere:

- pipeline: tariff.ts resolveConnectorPrice() matches connector power +
  build-time (Europe/Amsterdam) against each element's restrictions, with
  a €0.05–5.0 sanity band. Baked onto EnrichedConnector.priceKwh and the
  location headline LightLocation.priceKwh (min across connectors) ->
  crop-out/national point properties. Preserved through freight merge.
- webapp: detail panel shows the resolved price (falls back to parsing the
  raw tariff); new "Kleur op prijs" filter colors points by €/kWh ramp with
  legend + hover price.
- analysis: chargers.py reads priceKwh from crop-outs -> price_kwh_median/
  _mean/_n + price_pct percentile -> "Prijs" choropleth metric + scorecard.
- regenerated data: ~40k locations priced (median ≈€0.39); all 342 gemeenten
  get a median price.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
robbertjanssen85
2026-06-07 21:24:18 +02:00
co-authored by Claude Opus 4.8
parent 953e790cbd
commit 22e54a57a5
703 changed files with 1325 additions and 1022 deletions
+3
View File
@@ -20,6 +20,8 @@ METRICS = [
"desc": "Som van gerapporteerd connectorvermogen per 1.000 inwoners. Let op: NDW mist vermogen voor ±90% — onderschatting."},
{"key": "avg_occupancy", "label": "Gem. bezetting (snapshot)", "unit": "%", "decimals": 1, "category": "Gebruik",
"desc": "Gemiddeld aandeel connectoren dat 'laadt' over de geregistreerde snapshot-uren."},
{"key": "price_kwh_median", "label": "Mediaan tarief (€/kWh)", "unit": "€/kWh", "decimals": 3, "category": "Prijs",
"desc": "Mediaan van het actuele energietarief (€/kWh) uit de OCPI-tarieven (NDW) over laadlocaties met een gepubliceerde prijs. ±50% van de connectoren publiceert geen tarief; momentopname uit de laatste data-update."},
{"key": "demand_per_1000_inw", "label": "Verwachte vraag (peer-model)", "unit": "/1.000 inw", "decimals": 1, "category": "Vraag",
"desc": "Door een random-forest voorspeld 'verwacht' aantal laadpunten o.b.v. demografie, per 1.000 inwoners."},
{"key": "supply_gap", "label": "Tekort/overschot t.o.v. verwacht", "unit": "laadpunten", "decimals": 0, "category": "Vraag",
@@ -44,6 +46,7 @@ SCORECARD_COLS = [
"est_peak_load_kw", "potential_peak_load_kw", "live_peak_load_kw",
"evse_total", "charging_now", "occupancy_now",
"megawatt_sites", "supply_pct", "occupancy_pct", "gap_pct",
"price_kwh_mean", "price_kwh_n", "price_pct",
]
EXPORT_COLS = [m["key"] for m in METRICS] + SCORECARD_COLS
+22 -7
View File
@@ -5,6 +5,7 @@
"""
from __future__ import annotations
import json
import statistics
import pandas as pd
from ..paths import MUNICIPALITIES_JSON, GEMEENTEN_DIR, SNAPSHOTS_DIR
@@ -38,21 +39,32 @@ def _snapshot_metrics(slug: str) -> dict:
return {"avg_occupancy": avg, "evse_total": evse_total, "charging_now": charging_now, "occupancy_now": occ_now}
def _crop_power(slug: str) -> tuple[float, int]:
"""Sum of max power (kW) and megawatt-location count for a gemeente."""
def _crop_stats(slug: str) -> dict:
"""Per-gemeente supply stats from the crop-out: summed power, megawatt count,
and the €/kWh price distribution (median/mean) over locations that publish one."""
f = GEMEENTEN_DIR / f"{slug}.geojson"
if not f.exists():
return 0.0, 0
return {"power": 0.0, "mw": 0, "price_median": None, "price_mean": None, "price_n": 0}
data = json.loads(f.read_text())
power = 0.0
mw = 0
prices: list[float] = []
for feat in data.get("features", []):
p = feat.get("properties", {})
if p.get("type") == "charge":
power += p.get("maxPowerKw") or 0
if p.get("isMegawatt"):
mw += 1
return power, mw
price = p.get("priceKwh")
if isinstance(price, (int, float)):
prices.append(float(price))
return {
"power": power,
"mw": mw,
"price_median": round(statistics.median(prices), 3) if prices else None,
"price_mean": round(statistics.fmean(prices), 3) if prices else None,
"price_n": len(prices),
}
def fetch_chargers() -> pd.DataFrame:
@@ -62,7 +74,7 @@ def fetch_chargers() -> pd.DataFrame:
if not m.get("code"): # skip 'nederland'
continue
slug = m["slug"]
power, mw = _crop_power(slug)
crop = _crop_stats(slug)
snap = _snapshot_metrics(slug)
rows.append({
"code": m["code"],
@@ -71,8 +83,11 @@ def fetch_chargers() -> pd.DataFrame:
"population": m.get("population") or 0,
"chargers_passenger": m.get("passengerCount") or 0,
"chargers_freight": m.get("freightCount") or 0,
"total_power_kw": round(power),
"megawatt_sites": mw,
"total_power_kw": round(crop["power"]),
"megawatt_sites": crop["mw"],
"price_kwh_median": crop["price_median"],
"price_kwh_mean": crop["price_mean"],
"price_kwh_n": crop["price_n"],
"avg_occupancy": snap["avg_occupancy"],
"evse_total": snap["evse_total"],
"charging_now": snap["charging_now"],
+2
View File
@@ -77,6 +77,8 @@ def add_models(df: pd.DataFrame) -> pd.DataFrame:
df["supply_pct"] = _pct_rank(df["chargers_per_1000_inw"])
df["occupancy_pct"] = _pct_rank(df["avg_occupancy"]) if df["avg_occupancy"].notna().any() else np.nan
df["gap_pct"] = _pct_rank(-df["supply_gap"]) # high = more underserved
# Price percentile: high = relatively expensive vs other gemeenten.
df["price_pct"] = _pct_rank(df["price_kwh_median"]) if df["price_kwh_median"].notna().any() else np.nan
df.attrs["model_metrics"] = metrics
print(f" [models] demand OOF R²={metrics['r2_oof']} MAE={metrics['mae_oof']}; "