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
+35 -4
View File
@@ -13,6 +13,7 @@ import AboutModal from "@/components/AboutModal";
import ShareModal from "@/components/ShareModal";
import GuidedTour, { type TourStep } from "@/components/GuidedTour";
import type { ChoroplethData, AreaProps } from "@/types/analysis";
import { findGemeenteSlug } from "@/lib/pointInGemeente";
import {
Municipality,
CropoutData,
@@ -222,6 +223,10 @@ export default function Home() {
window.history.replaceState({}, "", url.toString());
}, [selectedMunicipality, municipalities, isNational]);
// A locationId to re-select once the next gemeente load finishes (used by the
// "jump to gemeente" action in the detail panel from the national view).
const pendingSelectRef = useRef<string | null>(null);
// Load data when municipality changes.
useEffect(() => {
if (!selectedMunicipality) return;
@@ -269,6 +274,11 @@ export default function Home() {
setBounds(crop.metadata.bounds ?? null);
setDetails(bundle);
setGemeenteName(crop.metadata.gemeente ?? selectedMunicipality);
if (pendingSelectRef.current) {
const again = charges.find((f) => f.properties.locationId === pendingSelectRef.current);
pendingSelectRef.current = null;
if (again) setSelected(again);
}
}
};
@@ -281,18 +291,38 @@ export default function Home() {
};
}, [selectedMunicipality]);
// Counts shown in the filter panel: same power/kind filtering as the map layers,
// so "the counts reflect the current view" actually holds.
const { passengerCount, freightCount } = useMemo(() => {
let p = 0;
let f = 0;
for (const feat of chargeFeatures) {
if (feat.properties.layer === "freight") f++;
else p++;
if (feat.properties.maxPowerKw < filters.minPowerKw) continue;
if (feat.properties.layer === "freight") {
if (filters.dedicatedFreightOnly && feat.properties.freightKind === "hpc") continue;
f++;
} else p++;
}
return { passengerCount: p, freightCount: f };
}, [chargeFeatures]);
}, [chargeFeatures, filters.minPowerKw, filters.dedicatedFreightOnly]);
const selectedDetail = selected ? details[selected.properties.locationId] ?? null : null;
// From the national view, jump into the gemeente containing the selected point
// (found via the choropleth polygons) and re-open its detail panel there.
const jumpToGemeente = useMemo(() => {
if (!selected || selectedDetail || !isNational) return undefined;
const [lng, lat] = selected.geometry.coordinates;
const slug = findGemeenteSlug(choropleth, lng, lat);
if (!slug) return undefined;
const locationId = selected.properties.locationId;
return () => {
pendingSelectRef.current = locationId;
setAnalysisMetric(null);
setSelectedMunicipality(slug);
};
}, [selected, selectedDetail, isNational, choropleth]);
const handleAddressSelected = (slug: string) => {
setSelectedMunicipality(slug);
setMobileSidebarOpen(false);
@@ -416,9 +446,10 @@ export default function Home() {
<LocationDetailPanel
selected={selected}
detail={selectedDetail}
loading={false}
loading={loading}
slug={selectedMunicipality}
onClose={() => setSelected(null)}
onJumpToGemeente={jumpToGemeente}
/>
{/* Mobile filter button */}
+6 -3
View File
@@ -79,9 +79,12 @@ export default function AboutModal({ isOpen, onClose, onStartTutorial }: Props)
<Section title="Personenauto vs. logistiek/vracht">
<p>
Een laadpunt is <strong>vracht</strong> bij: een truck-exploitant (Milence/WattHub…), de MCS/megawatt-standaard,
of een DC-connector ≥ 350 kW. Daardoor blijven gewone snelladers (150–350 kW) in de personenauto-laag.
Megawatt-locaties (≥ 1 MW) krijgen een aparte kleur.
Een laadpunt is <strong>dedicated truck</strong> bij een expliciet signaal: een truck-exploitant
(Milence/WattHub…), “truck” of “vrachtwagen” in de naam, de MCS/megawatt-standaard, of een logistiek
depot met ≥ 150 kW DC. Locaties die alléén op vermogen kwalificeren (DC ≥ 350 kW, zoals 400 kW-lanen
van personenauto-netwerken) heten <strong>truck-capable</strong> en krijgen een lichtere kleur — niet
elke locatie daarvan is fysiek toegankelijk voor een trekker-oplegger. Megawatt-locaties (≥ 1 MW of
MCS) krijgen een aparte kleur. Connectorvermogen wordt waar nodig afgeleid uit spanning × stroomsterkte.
</p>
</Section>
+22 -2
View File
@@ -56,6 +56,25 @@ export default function FilterPanel({ filters, onChange, passengerCount, freight
<span className="text-xs text-gray-500 tabular-nums">{freightCount.toLocaleString("nl-NL")}</span>
</label>
{filters.showFreight && (
<label className="flex items-center gap-2 cursor-pointer pl-6">
<input
type="checkbox"
checked={filters.dedicatedFreightOnly}
onChange={(e) => set({ dedicatedFreightOnly: e.target.checked })}
className="w-4 h-4 accent-amber-600"
/>
<span className="text-sm text-gray-800 flex items-center gap-1">
Alleen dedicated truck-locaties
<InfoTip title="Dedicated truck-locaties">
Verbergt snelladers die alleen op vermogen (≥350 kW DC) als truck-capable gelden, zoals
400 kW-lanen van personenauto-netwerken. Wat overblijft zijn locaties met een expliciet
trucksignaal: exploitant (Milence, WattHub…), “truck” in de naam, MCS of een logistiek depot.
</InfoTip>
</span>
</label>
)}
<label className="flex items-center gap-2 cursor-pointer">
<input
type="checkbox"
@@ -74,8 +93,9 @@ export default function FilterPanel({ filters, onChange, passengerCount, freight
<span className="text-sm font-medium text-gray-700 flex items-center gap-1">
Min. vermogen
<InfoTip title="Minimaal vermogen">
Toon alleen laadpunten met een gerapporteerd maximaal connectorvermogen ≥ de gekozen kW. Let op:
NDW publiceert voor veel AC-laders géén vermogen (telt als 0), dus een hoge drempel verbergt die.
Toon alleen laadpunten met een maximaal connectorvermogen ≥ de gekozen kW. Waar NDW geen
vermogen publiceert wordt het afgeleid uit spanning × stroomsterkte; een klein restdeel blijft
onbekend (0 kW) en verdwijnt bij een hoge drempel.
</InfoTip>
</span>
<span className="text-xs text-gray-500">
+33 -4
View File
@@ -10,6 +10,29 @@ const fmtPrice = (v: number) =>
// Prefer the price baked by the pipeline; fall back to a best-effort parse of the
// raw tariff (for data generated before the price field existed).
// Best-effort connector kW mirroring the pipeline: plausible declared power,
// else derived from V×A (×3 for three-phase AC). Filters out garbage values
// like 7,360,000 W on a 230 V/32 A AC post.
function connectorKw(c: EnrichedConnector): number | null {
const declared = c.max_electric_power ?? 0;
if (declared > 0 && declared <= 1_500_000) return declared / 1000;
const v = c.max_voltage ?? 0;
const a = c.max_amperage ?? 0;
if (v <= 0 || a <= 0) return null;
const phases = (c.power_type ?? "").toUpperCase() === "AC_3_PHASE" ? 3 : 1;
return (v * a * phases) / 1000;
}
const FREIGHT_REASON_LABEL: Record<string, string> = {
operator: "truck-exploitant",
"truck-name": "“truck” in de naam",
mcs: "MCS-aansluiting",
"depot-name": "logistiek depot",
motorway: "snelweglocatie ≥350 kW",
power: "alleen op vermogen (≥350 kW DC)",
curated: "handmatig toegevoegde hub",
};
function connectorPriceKwh(c: EnrichedConnector): number | null {
if (typeof c.priceKwh === "number") return c.priceKwh;
for (const t of c.tariffs ?? []) {
@@ -50,12 +73,17 @@ export default function LocationDetailPanel({ selected, detail, loading, slug, o
}`}
>
{isFreight ? <Truck className="h-3 w-3" /> : <Zap className="h-3 w-3" />}
{isFreight ? "Vracht" : "Personenauto"}
{isFreight ? (p.freightKind === "hpc" ? "Truck-capable" : "Truck") : "Personenauto"}
</span>
{p.isMegawatt && (
<span className="px-1.5 py-0.5 rounded text-xs text-white bg-orange-600">Megawatt</span>
)}
</div>
{isFreight && p.freightReason && FREIGHT_REASON_LABEL[p.freightReason] && (
<div className="text-xs text-amber-700 mt-1">
Classificatie: {FREIGHT_REASON_LABEL[p.freightReason]}
</div>
)}
<h3 className="font-semibold text-lg truncate mt-1">{p.name}</h3>
{p.address && (
<div className="flex items-center gap-1 text-sm text-gray-600 mt-1">
@@ -160,9 +188,10 @@ export default function LocationDetailPanel({ selected, detail, loading, slug, o
</div>
<div className="flex justify-between text-gray-600">
<span>{formatPowerType(c.power_type)}</span>
{c.max_electric_power ? (
<span className="font-medium">{(c.max_electric_power / 1000).toFixed(1)} kW</span>
) : null}
{(() => {
const kw = connectorKw(c);
return kw ? <span className="font-medium">{kw.toFixed(1)} kW</span> : null;
})()}
</div>
{(() => {
const price = connectorPriceKwh(c);
+35 -12
View File
@@ -107,11 +107,13 @@ export default function MapDeck({
const f: ChargeFeature[] = [];
for (const feat of chargeFeatures) {
if (feat.properties.maxPowerKw < filters.minPowerKw) continue;
if (feat.properties.layer === "freight") f.push(feat);
else p.push(feat);
if (feat.properties.layer === "freight") {
if (filters.dedicatedFreightOnly && feat.properties.freightKind === "hpc") continue;
f.push(feat);
} else p.push(feat);
}
return { passenger: p, freight: f };
}, [chargeFeatures, filters.minPowerKw]);
}, [chargeFeatures, filters.minPowerKw, filters.dedicatedFreightOnly]);
const handleHover = useCallback((info: PickingInfo<ChargeFeature>) => {
setHovered(info.object ?? null);
@@ -220,11 +222,21 @@ export default function MapDeck({
radiusMinPixels: 5,
radiusMaxPixels: 16,
getRadius: (d) =>
d.properties.locationId === selectedLocationId ? 16 : d.properties.isMegawatt ? 11 : 8,
getFillColor: (d) => (priceActive ? priceColor(d.properties.priceKwh) : freightColor(d.properties.isMegawatt)),
d.properties.locationId === selectedLocationId
? 16
: d.properties.isMegawatt
? 11
: d.properties.freightKind === "hpc"
? 6
: 8,
getFillColor: (d) =>
priceActive ? priceColor(d.properties.priceKwh) : freightColor(d.properties.isMegawatt, d.properties.freightKind),
// Ring encodes live OCPI status (freight fill stays amber for identity).
getLineColor: (d) =>
d.properties.isMegawatt ? ([124, 45, 18, 255] as RGBA) : ([255, 255, 255, 230] as RGBA),
getLineWidth: (d) => (d.properties.isMegawatt ? 2 : 1),
d.properties.status === "UNKNOWN"
? ([255, 255, 255, 230] as RGBA)
: (statusColor(d.properties.status).slice(0, 3).concat(255) as RGBA),
getLineWidth: (d) => (d.properties.isMegawatt ? 2.5 : 1.5),
updateTriggers: { getRadius: [selectedLocationId], getFillColor: [priceActive, priceDomain] },
}),
);
@@ -311,7 +323,9 @@ export default function MapDeck({
hovered.properties.layer === "freight"
? hovered.properties.isMegawatt
? LEGEND.freightMegawatt
: LEGEND.freight
: hovered.properties.freightKind === "hpc"
? LEGEND.freightHpc
: LEGEND.freight
: LEGEND[
(
{
@@ -320,11 +334,15 @@ export default function MapDeck({
UNAVAILABLE: "unavailable",
UNKNOWN: "unknown",
} as const
)[hovered.properties.status]
)[hovered.properties.status] ?? "unknown"
],
}}
>
{hovered.properties.layer === "freight" ? "Vracht" : "Personenauto"}
{hovered.properties.layer === "freight"
? hovered.properties.freightKind === "hpc"
? "Truck-capable ≥350 kW"
: "Truck"
: "Personenauto"}
</span>
{hovered.properties.maxPowerKw > 0 && <span>{hovered.properties.maxPowerKw} kW</span>}
</div>
@@ -425,12 +443,17 @@ export default function MapDeck({
<div className="space-y-1">
<div className="flex items-center gap-2">
<span className="w-3 h-3 rounded-full" style={{ background: LEGEND.freight }} />
<span>Vracht-laadpunt</span>
<span>Dedicated truck-locatie</span>
</div>
<div className="flex items-center gap-2">
<span className="w-3 h-3 rounded-full" style={{ background: LEGEND.freightHpc }} />
<span>Truck-capable ≥350 kW</span>
</div>
<div className="flex items-center gap-2">
<span className="w-3 h-3 rounded-full" style={{ background: LEGEND.freightMegawatt }} />
<span>Megawatt charging</span>
<span>Megawatt charging (MCS)</span>
</div>
<div className="text-gray-400">rand = status (groen/blauw/rood)</div>
</div>
</div>
)}
+18 -8
View File
@@ -14,6 +14,7 @@ export default function StatsPanel({ gemeente, chargeFeatures }: StatsPanelProps
const stats = useMemo(() => {
let passenger = 0;
let freight = 0;
let freightDedicated = 0;
let megawatt = 0;
let available = 0;
let charging = 0;
@@ -23,17 +24,19 @@ export default function StatsPanel({ gemeente, chargeFeatures }: StatsPanelProps
const p = f.properties;
if (p.layer === "freight") {
freight++;
if (p.freightKind !== "hpc") freightDedicated++;
if (p.isMegawatt) megawatt++;
} else {
passenger++;
// Status tallies match the map, which only colors passenger points by status.
if (p.status === "AVAILABLE") available++;
else if (p.status === "CHARGING") charging++;
else if (p.status === "UNAVAILABLE") unavailable++;
}
if (p.status === "AVAILABLE") available++;
else if (p.status === "CHARGING") charging++;
else if (p.status === "UNAVAILABLE") unavailable++;
if (p.operatorName) operators.set(p.operatorName, (operators.get(p.operatorName) ?? 0) + 1);
}
const topOperators = [...operators.entries()].sort((a, b) => b[1] - a[1]).slice(0, 5);
return { passenger, freight, megawatt, available, charging, unavailable, topOperators };
return { passenger, freight, freightDedicated, megawatt, available, charging, unavailable, topOperators };
}, [chargeFeatures]);
return (
@@ -54,14 +57,20 @@ export default function StatsPanel({ gemeente, chargeFeatures }: StatsPanelProps
<div className="text-xs text-amber-900 flex items-center gap-1">
Logistiek / vracht
<InfoTip title="Logistiek / vracht">
Laadpunten geclassificeerd als zware-voertuiglader: een truck-exploitant (Milence, WattHub…),
de MCS/megawatt-standaard, of een DC-connector ≥ 350 kW. Gewone snelladers (150–350 kW) blijven
personenauto.
Truck-laadlocaties: <strong>dedicated</strong> voorzieningen (truck-exploitant zoals
Milence/WattHub, “truck” in de naam, MCS-aansluiting, of een logistiek depot met ≥150 kW DC)
plus <strong>truck-capable</strong> snelladers met ≥350 kW DC die niet aantoonbaar op trucks
zijn ingericht.
</InfoTip>
</div>
</div>
</div>
{stats.freight > 0 && (
<div className="text-xs text-amber-800 bg-amber-50 rounded px-2 py-1">
{stats.freightDedicated} dedicated · {stats.freight - stats.freightDedicated} truck-capable ≥350 kW
</div>
)}
{stats.megawatt > 0 && (
<div className="text-xs text-orange-700 bg-orange-50 rounded px-2 py-1">
waarvan {stats.megawatt} megawatt-locatie{stats.megawatt !== 1 ? "s" : ""}
@@ -71,10 +80,11 @@ export default function StatsPanel({ gemeente, chargeFeatures }: StatsPanelProps
{/* OCPI status breakdown */}
<div>
<div className="text-xs font-medium text-gray-600 mb-1 flex items-center gap-1">
Status (OCPI-momentopname)
Status personenauto (OCPI-momentopname)
<InfoTip title="OCPI-status">
Beschikbaar/bezet/niet-beschikbaar komt uit de OCPI-status in de laatste uurlijkse momentopname van
de NDW-data — een snapshot, geen continue realtime stream. “Bezet” = connector aan het laden.
Telt alleen personenauto-punten; bij truckpunten zit de status in de ringkleur op de kaart.
</InfoTip>
</div>
<div className="flex flex-wrap gap-x-3 gap-y-1 text-xs">
+6 -3
View File
@@ -9,9 +9,10 @@ export const STATUS_CHARGING: RGBA = [59, 130, 246, 210]; // blue-500
export const STATUS_UNAVAILABLE: RGBA = [239, 68, 68, 210]; // red-500
export const STATUS_UNKNOWN: RGBA = [107, 114, 128, 200]; // gray-500
// Freight points: amber/orange; megawatt = red-orange.
// Freight points: amber/orange; megawatt = red-orange; truck-capable HPC = light amber.
export const FREIGHT: RGBA = [245, 158, 11, 235]; // amber-500
export const FREIGHT_MEGAWATT: RGBA = [234, 88, 12, 245]; // orange-600
export const FREIGHT_HPC: RGBA = [252, 211, 77, 220]; // amber-300
export const BOUNDARY_LINE: RGBA = [79, 70, 229, 200]; // indigo-600
@@ -28,8 +29,9 @@ export function statusColor(status: AggregateStatus): RGBA {
}
}
export function freightColor(isMegawatt: boolean): RGBA {
return isMegawatt ? FREIGHT_MEGAWATT : FREIGHT;
export function freightColor(isMegawatt: boolean, kind?: string): RGBA {
if (isMegawatt) return FREIGHT_MEGAWATT;
return kind === "hpc" ? FREIGHT_HPC : FREIGHT;
}
// Hex equivalents for legend / UI swatches.
@@ -40,5 +42,6 @@ export const LEGEND = {
unknown: "#6b7280",
freight: "#f59e0b",
freightMegawatt: "#ea580c",
freightHpc: "#fcd34d",
boundary: "#4f46e5",
};
+40
View File
@@ -0,0 +1,40 @@
// Locate the gemeente (by slug) whose polygon contains a point, using the
// analysis choropleth as the polygon source. Ray casting; holes respected.
import type { ChoroplethData } from "@/types/analysis";
function inRing(ring: number[][], lng: number, lat: number): boolean {
let inside = false;
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
const [xi, yi] = ring[i];
const [xj, yj] = ring[j];
if (yi > lat !== yj > lat && lng < ((xj - xi) * (lat - yi)) / (yj - yi) + xi) inside = !inside;
}
return inside;
}
function inPolygon(coords: number[][][], lng: number, lat: number): boolean {
if (!coords.length || !inRing(coords[0], lng, lat)) return false;
for (let k = 1; k < coords.length; k++) {
if (inRing(coords[k], lng, lat)) return false; // inside a hole
}
return true;
}
export function findGemeenteSlug(
choropleth: ChoroplethData | null,
lng: number,
lat: number,
): string | null {
if (!choropleth) return null;
for (const f of choropleth.features) {
const g = f.geometry;
const hit =
g.type === "Polygon"
? inPolygon(g.coordinates as number[][][], lng, lat)
: g.type === "MultiPolygon"
? (g.coordinates as number[][][][]).some((p) => inPolygon(p, lng, lat))
: false;
if (hit) return f.properties.slug ?? null;
}
return null;
}
+9
View File
@@ -2,6 +2,9 @@
export type ChargeLayer = "passenger" | "freight";
export type AggregateStatus = "AVAILABLE" | "CHARGING" | "UNAVAILABLE" | "UNKNOWN";
// 'dedicated' = explicit truck facility (operator/naam/MCS/depot/curated);
// 'hpc' = qualifies only on >=350 kW DC (truck-capable, not per se truck-toegankelijk).
export type FreightKind = "dedicated" | "hpc";
export interface Municipality {
name: string;
@@ -26,6 +29,8 @@ export interface ChargeProperties {
status: AggregateStatus;
source: string; // 'ndw' | 'curated' | 'eafo' | 'ocm'
priceKwh?: number; // cheapest currently-applicable €/kWh at this location
freightKind?: FreightKind;
freightReason?: string;
}
export interface BoundaryProperties {
@@ -119,6 +124,8 @@ export interface EnrichedLocation {
lastUpdated: string;
layer: ChargeLayer;
maxPowerKw: number;
freightKind?: FreightKind;
freightReason?: string;
evses: EnrichedEVSE[];
}
@@ -130,6 +137,7 @@ export interface Filters {
showBoundary: boolean;
minPowerKw: number;
colorByPrice: boolean; // color charge points by €/kWh instead of status
dedicatedFreightOnly: boolean; // hide 'hpc' freight (power-only truck-capable sites)
}
export const DEFAULT_FILTERS: Filters = {
@@ -138,4 +146,5 @@ export const DEFAULT_FILTERS: Filters = {
showBoundary: true,
minPowerKw: 0,
colorByPrice: false,
dedicatedFreightOnly: false,
};