Parse vehicle_types.json into a canonical catalogue.
Resolves VehicleStatus.vehicle_type_id to a form factor / propulsion, so
"where are the e-bikes?" becomes a join. Returns
VEHICLE_TYPE_COLUMNS.
See Also
to_canonical_vehicles : The vehicles these types describe.
Source code in src/gbfs_toolkit/io/normalize.py
| def to_canonical_vehicle_types(raw: dict, *, system_id: str) -> pd.DataFrame:
"""Parse ``vehicle_types.json`` into a canonical catalogue.
Resolves ``VehicleStatus.vehicle_type_id`` to a form factor / propulsion, so
"where are the e-bikes?" becomes a join. Returns
`VEHICLE_TYPE_COLUMNS`.
See Also
--------
[`to_canonical_vehicles`][gbfs_toolkit.to_canonical_vehicles] : The vehicles these types describe.
"""
data = raw.get("data", raw)
types = _records(data, "vehicle_types")
rows = [
{
"system_id": system_id,
"vehicle_type_id": str(t.get("vehicle_type_id")),
"form_factor": t.get("form_factor"),
"propulsion_type": t.get("propulsion_type"),
"max_range_meters": t.get("max_range_meters"),
}
for t in types
]
df = pd.DataFrame(rows, columns=VEHICLE_TYPE_COLUMNS)
df["max_range_meters"] = pd.to_numeric(df["max_range_meters"], errors="coerce")
df["vehicle_type_id"] = df["vehicle_type_id"].astype(
"string"
) # join key, see to_canonical_vehicles
return df
|