Skip to content

Service Ridership Dashboard Ridership

This page documents ridership functions in the Service Ridership Dashboard module.

ingestor.chalicelib.service_ridership_dashboard.ridership

ridership_by_line_id(start_date, end_date, line_ids)

Fetch ridership data for multiple lines and organize by line ID and date.

Parameters:

Name Type Description Default
start_date date

The start date of the ridership query range.

required
end_date date

The end date of the ridership query range.

required
line_ids list[str]

A list of MBTA line identifiers to query ridership for.

required

Returns:

Type Description
RidershipByLineId

A dictionary mapping line IDs to their respective ridership-by-date dictionaries.

Source code in ingestor/chalicelib/service_ridership_dashboard/ridership.py
def ridership_by_line_id(start_date: date, end_date: date, line_ids: list[str]) -> RidershipByLineId:
    """Fetch ridership data for multiple lines and organize by line ID and date.

    Args:
        start_date: The start date of the ridership query range.
        end_date: The end date of the ridership query range.
        line_ids: A list of MBTA line identifiers to query ridership for.

    Returns:
        A dictionary mapping line IDs to their respective ridership-by-date dictionaries.
    """
    ridership_by_line_id: RidershipByLineId = {}
    for line_id in (progress := tqdm(line_ids)):
        progress.set_description(f"Loading ridership for {line_id}")
        entries_for_line_id = _get_ridership_for_line_id(
            start_date=start_date,
            end_date=end_date,
            line_id=line_id,
        )
        ridership_by_line_id[line_id] = entries_for_line_id
    return ridership_by_line_id