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>
88 lines
6.4 KiB
Python
88 lines
6.4 KiB
Python
"""Export the golden dataset + models as a viewer choropleth layer + metadata."""
|
||
from __future__ import annotations
|
||
import json
|
||
import math
|
||
import pandas as pd
|
||
from .ingest.boundaries import fetch_gemeente_geojson
|
||
from .paths import DERIVED_DIR
|
||
|
||
# Choropleth-selectable metrics (order = display order). category groups the switcher.
|
||
METRICS = [
|
||
{"key": "chargers_per_1000_inw", "label": "Laadpunten per 1.000 inwoners", "unit": "", "decimals": 1, "category": "Aanbod",
|
||
"desc": "Aantal OCPI-laadlocaties (NDW) gedeeld door inwoners (CBS) × 1.000. Maat voor dekking."},
|
||
{"key": "chargers_per_1000_auto", "label": "Laadpunten per 1.000 auto's", "unit": "", "decimals": 1, "category": "Aanbod",
|
||
"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": "power_per_1000_inw_kw", "label": "Vermogen per 1.000 inw.", "unit": "kW", "decimals": 0, "category": "Aanbod",
|
||
"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": "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 ((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",
|
||
"desc": "CBS: personenauto's per huishouden — driver van laadbehoefte."},
|
||
{"key": "inkomen_per_inwoner", "label": "Gem. inkomen per inwoner", "unit": "×€1.000", "decimals": 1, "category": "Demografie",
|
||
"desc": "CBS gemiddeld inkomen per inwoner (×€1.000)."},
|
||
{"key": "stedelijkheid", "label": "Stedelijkheid (1=zeer sterk)", "unit": "", "decimals": 0, "category": "Demografie",
|
||
"desc": "CBS stedelijkheidsklasse 1 (zeer sterk stedelijk) t/m 5 (niet stedelijk)."},
|
||
]
|
||
|
||
# Extra fields carried in properties for the gemeente scorecard panel.
|
||
SCORECARD_COLS = [
|
||
"expected_chargers", "chargers_passenger", "inwoners", "autos_totaal",
|
||
"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", "freight_pct",
|
||
]
|
||
EXPORT_COLS = [m["key"] for m in METRICS] + SCORECARD_COLS
|
||
|
||
|
||
def _clean(v):
|
||
if v is None or (isinstance(v, float) and (math.isnan(v) or math.isinf(v))):
|
||
return None
|
||
return v
|
||
|
||
|
||
def export_layer(gold: pd.DataFrame) -> None:
|
||
print("Exporting derived viewer layer...")
|
||
fc = fetch_gemeente_geojson()
|
||
by_code = {c: gold.loc[c] for c in gold.index}
|
||
|
||
for feat in fc["features"]:
|
||
code = feat["properties"].get("statcode")
|
||
props = {"code": code, "gemeente": feat["properties"].get("statnaam")}
|
||
row = by_code.get(code)
|
||
if row is not None:
|
||
props["slug"] = row.get("slug")
|
||
for col in EXPORT_COLS:
|
||
val = row.get(col)
|
||
props[col] = _clean(float(val)) if pd.notna(val) else None
|
||
feat["properties"] = props
|
||
|
||
meta = {"metrics": METRICS, "model": gold.attrs.get("model_metrics", {})}
|
||
fc["metadata"] = meta
|
||
DERIVED_DIR.mkdir(parents=True, exist_ok=True)
|
||
(DERIVED_DIR / "gemeente-metrics.geojson").write_text(json.dumps(fc))
|
||
(DERIVED_DIR / "metrics-meta.json").write_text(json.dumps(meta, ensure_ascii=False, indent=2))
|
||
|
||
n = sum(1 for f in fc["features"] if f["properties"].get("chargers_total") is not None)
|
||
print(f" wrote gemeente-metrics.geojson ({n}/{len(fc['features'])} gemeenten with data)")
|