Source code for passengersim.summaries.paths
from __future__ import annotations
from typing import TYPE_CHECKING
import pandas as pd
from .generic import GenericSimulationTables, SimulationTableItem
from .tools import aggregate_by_summing_dataframe
if TYPE_CHECKING:
from passengersim import Simulation
[docs]
class SimTabPaths(GenericSimulationTables):
"""Container for summary tables and figures extracted from a Simulation.
This class is a subclass of GenericSimulationTables, which is defined in
the generic module. It lists the items that are available in the
SimulationTables class, and provides type hints and (optionally, but
ideally) documentation for the data that is stored in each item.
"""
paths: pd.DataFrame = SimulationTableItem(
aggregation_func=aggregate_by_summing_dataframe(
"paths",
[
"carrier",
"orig",
"dest",
"num_legs",
"hhi",
"max_hhi",
"path_quality_index",
"minimum_connect_time",
],
),
extraction_func=extract_paths,
doc="Path-level summary data.",
)
[docs]
def path_identifier(self, path_id: int) -> str:
"""
Get a human-readable identifying string for a path.
Parameters
----------
path_id : int
The path_id to look up.
Returns
-------
str
"""
def q(attribute):
return self.paths.loc[path_id, attribute]
s = f"Path {path_id}: {q('orig')}~{q('dest')},"
leg_ids = self.path_legs.query("path_id == @path_id")["leg_id"]
legs = self.legs.query("leg_id in @leg_ids")
for i in leg_ids:
s += f" ({legs.loc[i, 'carrier']}:{legs.loc[i, 'flt_no']} {legs.loc[i, 'orig']}-{legs.loc[i, 'dest']})"
return s