iduedu.TransportRegistry

class iduedu.TransportRegistry(specs=None)[source]

Registry of public-transport specifications for modes and service variants.

The registry stores TransportSpec objects under lowercase mode names and optional "<mode>:<service>" keys. list_types() returns both kinds of keys, and list_modes() returns the names that can be requested when building an OSM graph.

The registry is used throughout graph construction to compute per-edge travel times consistently across different transport modes.

Methods

add

Add a transport specification to the registry.

ensure

Return an existing spec or create one from defaults.

get

Return a transport specification by name.

list_modes

Return registered mode names that can be requested as OSM route types.

list_types

Return registered mode and service variant keys.

remove

Remove a transport specification by name.

try_get

Return a transport specification, or None if it is unknown.

update

Update fields of an existing transport specification.

Parameters:

specs (dict[str, TransportSpec] | None)

get(name)[source]

Return a transport specification by name.

Parameters:

name (str) – Mode or service variant key. Matching is case-insensitive and ignores surrounding whitespace.

Raises:

KeyError – If the transport type is unknown.

Return type:

TransportSpec

try_get(name)[source]

Return a transport specification, or None if it is unknown.

Return type:

TransportSpec | None

Parameters:

name (str)

add(spec, *, overwrite=False)[source]

Add a transport specification to the registry.

Parameters:
  • spec (TransportSpec) – Specification to add.

  • overwrite (bool) – If true, replace an existing specification with the same normalized name.

Raises:

ValueError – If spec is invalid or already exists.

Return type:

None

update(transport_type, **fields)[source]

Update fields of an existing transport specification.

Parameters:
  • transport_type (str) – Existing mode or service variant key.

  • **fields – Dataclass fields to update.

Return type:

TransportSpec

Returns:

Updated transport specification.

Raises:
  • KeyError – If transport_type is unknown.

  • ValueError – If updated fields are invalid or rename conflicts.

remove(name)[source]

Remove a transport specification by name.

Return type:

None

Parameters:

name (str)

ensure(name, *, defaults=None)[source]

Return an existing spec or create one from defaults.

Parameters:
  • name (str) – Mode or service variant key.

  • defaults (TransportSpec | None) – Optional specification used when the name is missing.

Return type:

TransportSpec

Returns:

Existing or newly registered transport specification.

list_types()[source]

Return registered mode and service variant keys.

Return type:

list[str]

list_modes()[source]

Return registered mode names that can be requested as OSM route types.

Return type:

list[str]