Skip to content

transitlos.scoring.mrc

MRC: the combined mode / reliability / comfort axis.

Mode, reliability and comfort are one axis, not three separately weighted terms:

(a) MR_mode(mode)        categorical default from the GTFS route_type (the path the pipeline uses)
(b) MR_CV(headway_cv)    optional, used instead of (a) when the scheduled-headway CV is known: 1 / (1 + CV^2)
(c) C(occupancy_status)  optional comfort factor on top of (a) / (b) from GTFS-realtime OccupancyStatus (not used by default)

MRC = MR_component * C_component

Defaults: parameters.RegionParameters (mr_mode, comfort_scores).

mode_category(route_type)

Classify a GTFS route_type into "rail", "tram", or "bus".

Parameters:

Name Type Description Default
route_type Optional[int]

Standard GTFS route_type code (0-7), or None/NaN for a route with no usable route_type -- falls back to "bus".

required

Returns:

Type Description
str

"rail", "tram", or "bus".

MR_mode(mode, region='global')

Compute the mode-based categorical default MR_mode(mode).

Rail / subway / metro / commuter rail = 1.000; tram / light rail / BRT = 0.894 (geometric mean of rail and bus); local bus = 0.800.

Parameters:

Name Type Description Default
mode str

One of "rail", "tram", "bus" (see mode_category).

required
region str

Region key into parameters.REGIONS. Kept for backward compatibility -- every region shares identical, universal values.

'global'

Returns:

Type Description
float

A float in (0, 1].

Raises:

Type Description
ValueError

If mode is not one of "rail", "tram", "bus".

mode_score(route_type, region='global')

Compute MR_mode(mode_category(route_type)) directly from a GTFS route_type.

Convenience wrapper combining mode_category + MR_mode.

Parameters:

Name Type Description Default
route_type Optional[int]

GTFS route type.

required
region str

Scoring region.

'global'

Returns:

Type Description
float

The mode value.

MR_CV(headway_cv)

Compute the optional CV-of-scheduled-headway reliability refinement.

MR_CV(CV) = 1 / (1 + CV^2), the inverse of the average-wait inflation factor (1 + CV^2). MR_CV(0)=1.0, MR_CV(1)=0.5, MR_CV(2)~=0.2. Mode-agnostic by construction; preferred over MR_mode whenever scheduled-headway CV data exists, since it reflects the stop's own actual pattern.

Parameters:

Name Type Description Default
headway_cv float

Coefficient of variation of scheduled headways (stddev / mean), a unitless non-negative number.

required

Returns:

Type Description
float

A float in (0, 1].

Raises:

Type Description
ValueError

If headway_cv is negative.

comfort_score(occupancy_status, region='global')

Compute the optional comfort/crowding refinement C(occupancy_status).

A categorical lookup keyed to the standardized GTFS-realtime VehiclePosition.OccupancyStatus enum. Defaults to 1.0 (comfort-neutral) when occupancy data is unavailable -- the common case, since this refinement needs GTFS-realtime data this project's pipeline typically does not have.

Parameters:

Name Type Description Default
occupancy_status Optional[str]

One of the GTFS-realtime OccupancyStatus enum string values ("EMPTY", "MANY_SEATS_AVAILABLE", "FEW_SEATS_AVAILABLE", "STANDING_ROOM_ONLY", "CRUSHED_STANDING_ROOM_ONLY", "FULL", "NOT_ACCEPTING_PASSENGERS"), or None if unavailable.

required
region str

Region key into parameters.REGIONS. Kept for backward compatibility -- every region shares identical, universal values.

'global'

Returns:

Type Description
float

A float in [0, 1]. Exactly 1.0 if occupancy_status is None.

Raises:

Type Description
ValueError

If occupancy_status is a string not in the known enum.

mrc_score(route_type=None, headway_cv=None, occupancy_status=None, region='global')

Compute the combined MRC(mode/reliability/comfort) sub-score.

MRC = MR_component * C_component, where MR_component is MR_CV(headway_cv) if headway_cv is supplied (preferred, richer data), else MR_mode(mode_category(route_type)) (the primary, load-bearing GTFS-static-only default); C_component is comfort_score(occupancy_status), defaulting to 1.0 (comfort-neutral) when occupancy_status is None -- the common case, so mrc_score(route_type) == MR_mode(mode_category(route_type)) exactly when no other data is supplied.

Parameters:

Name Type Description Default
route_type Optional[int]

Standard GTFS route_type code, or None. Used only if headway_cv is not supplied.

None
headway_cv Optional[float]

Coefficient of variation of scheduled headways, or None if unavailable. When supplied, takes precedence over route_type for the mode/reliability component.

None
occupancy_status Optional[str]

GTFS-realtime OccupancyStatus enum value, or None if unavailable (the common case; defaults to comfort-neutral).

None
region str

Region key into parameters.REGIONS. Kept for backward compatibility -- every region shares identical, universal values.

'global'

Returns:

Type Description
float

A float in [0, 1] (or up to (0, 1] * (0, 1] -- always <= 1.0 since

float

both components are individually <= 1.0).