Skip to content

Service Ridership Dashboard Summary

This page documents summary in the Service Ridership Dashboard module.

ingestor.chalicelib.service_ridership_dashboard.summary

get_summary_data(line_data, start_date, end_date)

Compute aggregate summary statistics across all lines for the dashboard.

Parameters:

Name Type Description Default
line_data list[LineData]

A list of LineData dictionaries for all lines.

required
start_date date

The start date of the data range.

required
end_date date

The end date of the data range.

required

Returns:

Type Description
SummaryData

A SummaryData dict with totals for ridership, service, and route status counts.

Source code in ingestor/chalicelib/service_ridership_dashboard/summary.py
def get_summary_data(line_data: list[LineData], start_date: date, end_date: date) -> SummaryData:
    """Compute aggregate summary statistics across all lines for the dashboard.

    Args:
        line_data: A list of LineData dictionaries for all lines.
        start_date: The start date of the data range.
        end_date: The end date of the data range.

    Returns:
        A SummaryData dict with totals for ridership, service, and route status counts.
    """
    total_ridership_history = merge_weekly_median_time_series([line["ridershipHistory"] for line in line_data])
    total_service_history = merge_weekly_median_time_series([line["serviceHistory"] for line in line_data])
    total_passengers = get_latest_weekly_median_time_series_entry(total_ridership_history)
    total_trips = get_latest_weekly_median_time_series_entry(total_service_history)
    total_routes_cancelled = sum(_line_is_cancelled(line) for line in line_data)
    total_reduced_service = sum(_line_has_reduced_service(line) for line in line_data)
    total_increased_service = sum(_line_has_increased_service(line) for line in line_data)
    return {
        "totalRidershipHistory": total_ridership_history,
        "totalServiceHistory": total_service_history,
        "totalRidershipPercentage": 0,  # From CRD, remove
        "totalServicePercentage": 0,  # From CRD, remove
        "totalPassengers": total_passengers or 0,
        "totalTrips": total_trips or 0,
        "totalRoutesCancelled": total_routes_cancelled,
        "totalReducedService": total_reduced_service,
        "totalIncreasedService": total_increased_service,
        "startDate": date_to_string(start_date),
        "endDate": date_to_string(end_date),
    }