Rework freight classification and fix analysis/webapp derivations

Freight classification v2: two-tier freightKind ('dedicated' via truck
operator, truck-named location (forklifts excluded), MCS, logistics depot
>=150 kW DC, or curated hub; 'hpc' for power-only >=350 kW DC) with
freightReason carried through to the map and detail panel. Connector power
is now derived from V x A when max_electric_power is missing or implausible
(caps out NDW garbage like 7.36 MW on a 22 kW AC post), eliminating all
zero-kW points. Adds Milence Waddinxveen to curated hubs and a
nearest-gemeente fallback so coastal/industrial sites get detail bundles.
Tariff matching now honors one-sided time windows.

Analysis: peak load finally uses the 150 kW freight constant (was priced at
11 kW), crop stats split by layer so freight no longer skews supply/price
metrics, occupancy is EVSE-weighted, charging_now samples one common hour,
and a new Logistiek metric group exports chargers_freight/freight_dedicated/
freight_power_kw. Relabels peer-model outputs as modelled supply.

Webapp: freight markers colored by kind with status ring, dedicated-only
filter, filter counts respect the power filter, status tallies scoped to
passenger, national-view detail panel can jump into the point's gemeente,
connector kW display mirrors the pipeline derivation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
robbertjanssen85
2026-07-07 01:08:54 +02:00
co-authored by Claude Fable 5
parent 3b181345c9
commit cbd4531574
21 changed files with 452 additions and 94 deletions
+13 -9
View File
@@ -14,22 +14,26 @@ METRICS = [
"desc": "Laadlocaties per 1.000 personenauto's (CBS autobezit). Dekking t.o.v. het wagenpark."},
{"key": "chargers_total", "label": "Laadpunten totaal", "unit": "", "decimals": 0, "category": "Aanbod",
"desc": "Totaal aantal OCPI-laadlocaties (personen + vracht) in de gemeente."},
{"key": "chargers_freight", "label": "Vracht-laadpunten", "unit": "", "decimals": 0, "category": "Aanbod",
"desc": "Laadpunten geclassificeerd als logistiek/vracht (≥350 kW DC, MCS/megawatt of truck-exploitant)."},
{"key": "power_per_1000_inw_kw", "label": "Vermogen per 1.000 inw.", "unit": "kW", "decimals": 0, "category": "Aanbod",
"desc": "Som van gerapporteerd connectorvermogen per 1.000 inwoners. Let op: NDW mist vermogen voor ±90% — onderschatting."},
"desc": "Som van het max. connectorvermogen per 1.000 inwoners (personen + vracht). Vermogen afgeleid uit spanning × stroomsterkte waar NDW het niet rapporteert."},
{"key": "chargers_freight", "label": "Truck-laadlocaties", "unit": "", "decimals": 0, "category": "Logistiek",
"desc": "Locaties voor truckladen: dedicated voorzieningen (truck-operator, 'truck' in naam, MCS, logistiek depot) plus truck-capable snelladers (≥350 kW DC)."},
{"key": "freight_dedicated", "label": "Dedicated truck-locaties", "unit": "", "decimals": 0, "category": "Logistiek",
"desc": "Locaties met een expliciet trucksignaal: exploitant (Milence/WattHub), 'truck' in de naam, MCS-aansluiting, logistiek depot met ≥150 kW DC, of gecureerde hub. Exclusief locaties die alleen op vermogen kwalificeren."},
{"key": "freight_power_kw", "label": "Truck-laadvermogen", "unit": "kW", "decimals": 0, "category": "Logistiek",
"desc": "Som van het max. connectorvermogen van truck-laadlocaties in de gemeente. Indicatie van logistieke laadcapaciteit (bays per site niet meegenomen)."},
{"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",
"desc": "Werkelijk − verwacht aantal laadpunten. Negatief = minder aanbod dan vergelijkbare gemeenten."},
{"key": "demand_per_1000_inw", "label": "Verwacht aanbod (peer-model)", "unit": "/1.000 inw", "decimals": 1, "category": "Vraag",
"desc": "Door een random-forest voorspeld aantal laadpunten o.b.v. demografie, per 1.000 inwoners. Peer-benchmark van het aanbod, geen gemeten vraag."},
{"key": "supply_gap", "label": "Afwijking t.o.v. peers", "unit": "laadpunten", "decimals": 0, "category": "Vraag",
"desc": "Werkelijk − verwacht (peer-model) aantal laadpunten. Negatief = minder aanbod dan demografisch vergelijkbare gemeenten. Gemodelleerd; NDW-dekkingsgaten (bijv. Amsterdam) kleuren dit beeld."},
{"key": "siting_priority", "label": "Plaatsingsprioriteit (0-100)", "unit": "", "decimals": 0, "category": "Siting",
"desc": "Prioriteit voor bijplaatsen: combineert relatief + absoluut tekort en huidige bezetting. Hoger = meer behoefte."},
{"key": "load_per_1000_inw_kw", "label": "Gesch. piekbelasting /1.000 inw", "unit": "kW", "decimals": 1, "category": "Congestie",
"desc": "Gemodelleerde potentiële piek (alle EVSE's × ~11 kW × 30%) per 1.000 inwoners. Vermogen aangenomen."},
"desc": "Gemodelleerde potentiële piek ((personen-EVSE's × ~11 kW + truck-locaties × ~150 kW) × 30%) per 1.000 inwoners. Vermogens aangenomen."},
{"key": "congestion_index", "label": "Congestie-index (relatief)", "unit": "", "decimals": 0, "category": "Congestie",
"desc": "Relatieve percentielrang (0-100) van de piekbelasting per inwoner. NB: geen DSO-capaciteit ingelezen."},
{"key": "autos_per_huishouden", "label": "Auto's per huishouden", "unit": "", "decimals": 2, "category": "Demografie",
@@ -46,7 +50,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",
"price_kwh_mean", "price_kwh_n", "price_pct", "freight_pct",
]
EXPORT_COLS = [m["key"] for m in METRICS] + SCORECARD_COLS
+55 -17
View File
@@ -19,48 +19,83 @@ def _latest_day(slug: str) -> dict | None:
def _snapshot_metrics(slug: str) -> dict:
"""avg occupancy + live EVSE totals/charging-now from the latest snapshot."""
"""avg occupancy + live EVSE totals/charging-now from the latest snapshot.
- avg_occupancy is EVSE-weighted (a 147-connector hub weighs more than a
1-connector post), not a flat mean over location-hours.
- charging_now samples every location at the SAME hour (the latest hour with
any data), so the "now" figure is a real instant, not a blend of each
location's own last non-null hour.
"""
data = _latest_day(slug)
if not data:
return {"avg_occupancy": None, "evse_total": None, "charging_now": None, "occupancy_now": None}
all_occ: list[float] = []
locations = data.get("locations", {}).values()
evse_total = 0
charging_now = 0
for loc in data.get("locations", {}).values():
w_sum = 0.0
w_total = 0.0
last_idx = -1
for loc in locations:
n = loc.get("n") or 0
occ_arr = [v for v in loc.get("occ", []) if v is not None]
if occ_arr:
all_occ.extend(occ_arr)
latest = occ_arr[-1] # most recent recorded hour
charging_now += round(latest / 100 * n)
evse_total += n
avg = round(sum(all_occ) / len(all_occ), 1) if all_occ else None
occ_now = round(100 * charging_now / evse_total, 1) if evse_total else None
occ = loc.get("occ", [])
for i, v in enumerate(occ):
if v is not None:
w_sum += v * n
w_total += n
if i > last_idx:
last_idx = i
charging_now = 0
evse_now = 0
if last_idx >= 0:
for loc in locations:
n = loc.get("n") or 0
occ = loc.get("occ", [])
v = occ[last_idx] if last_idx < len(occ) else None
if v is not None:
charging_now += round(v / 100 * n)
evse_now += n
avg = round(w_sum / w_total, 1) if w_total else None
occ_now = round(100 * charging_now / evse_now, 1) if evse_now else None
return {"avg_occupancy": avg, "evse_total": evse_total, "charging_now": charging_now, "occupancy_now": occ_now}
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."""
"""Per-gemeente supply stats from the crop-out, split by layer: summed power
(passenger vs freight), megawatt + dedicated-truck counts, and the €/kWh
price distribution over PASSENGER locations that publish one (freight HPC
tariffs would skew the general-public median)."""
f = GEMEENTEN_DIR / f"{slug}.geojson"
if not f.exists():
return {"power": 0.0, "mw": 0, "price_median": None, "price_mean": None, "price_n": 0}
return {"power": 0.0, "freight_power": 0.0, "mw": 0, "freight_dedicated": 0,
"price_median": None, "price_mean": None, "price_n": 0}
data = json.loads(f.read_text())
power = 0.0
freight_power = 0.0
mw = 0
freight_dedicated = 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("type") != "charge":
continue
kw = p.get("maxPowerKw") or 0
if p.get("layer") == "freight":
freight_power += kw
if p.get("isMegawatt"):
mw += 1
if p.get("freightKind") == "dedicated":
freight_dedicated += 1
else:
power += kw
price = p.get("priceKwh")
if isinstance(price, (int, float)):
prices.append(float(price))
return {
"power": power,
"freight_power": freight_power,
"mw": mw,
"freight_dedicated": freight_dedicated,
"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),
@@ -83,7 +118,10 @@ 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(crop["power"]),
"total_power_kw": round(crop["power"] + crop["freight_power"]),
"passenger_power_kw": round(crop["power"]),
"freight_power_kw": round(crop["freight_power"]),
"freight_dedicated": crop["freight_dedicated"],
"megawatt_sites": crop["mw"],
"price_kwh_median": crop["price_median"],
"price_kwh_mean": crop["price_mean"],
+14 -3
View File
@@ -62,10 +62,19 @@ def add_models(df: pd.DataFrame) -> pd.DataFrame:
df["siting_priority"] = (raw / (raw.max() or 1) * 100).round(0)
# ---- P4: congestion risk + net impact ----
# EVSE count: prefer live snapshot total; fall back to locations if no snapshot.
# EVSE count: prefer live snapshot total (EVSE grain); the fallback is
# LOCATION grain (~2-10 EVSEs per location) and only fires for gemeenten
# without any snapshot — treat those rows as underestimates.
evse = df["evse_total"].fillna(df["chargers_passenger"].fillna(0) + df["chargers_freight"].fillna(0))
# Potential peak (planning): all EVSEs x assumed kW x concurrency.
df["potential_peak_load_kw"] = (evse * ASSUMED_EVSE_KW * CONCURRENCY).round(0)
# Potential peak (planning): passenger EVSEs at ~11 kW plus freight/truck
# locations at ~150 kW each, x concurrency. Freight sites are counted per
# location (crop-outs don't carry per-site bay counts) — conservative for
# multi-bay hubs, but far closer than pricing an MCS hub as one AC post.
freight_locs = df["chargers_freight"].fillna(0)
passenger_evse = (evse - freight_locs).clip(lower=0)
df["potential_peak_load_kw"] = (
(passenger_evse * ASSUMED_EVSE_KW + freight_locs * AVG_FREIGHT_KW) * CONCURRENCY
).round(0)
# Live peak now (grounded in OCPI status): EVSEs charging now x assumed kW.
df["live_peak_load_kw"] = (df["charging_now"] * ASSUMED_EVSE_KW).round(0)
# Scenario base = potential peak; kept as est_peak_load_kw for the scorecard slider.
@@ -79,6 +88,8 @@ def add_models(df: pd.DataFrame) -> pd.DataFrame:
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
# Freight/logistics percentile: rank on installed truck-charging power.
df["freight_pct"] = _pct_rank(df["freight_power_kw"]) if df["freight_power_kw"].notna().any() else np.nan
df.attrs["model_metrics"] = metrics
print(f" [models] demand OOF R²={metrics['r2_oof']} MAE={metrics['mae_oof']}; "