GenericSimulationTables¶
-
class passengersim.summaries.generic.GenericSimulationTables(data: dict[str, pd.DataFrame] =
None, *, config: Config | None =None, cnx: Database | None =None, sim: Simulation | None =None, n_total_samples: int =0, items: Collection[str] =(), callback_data: CallbackData | None =None)[source]¶ Bases:
objectMethods
__init__([data, config, cnx, sim, ...])aggregate(summaries)Aggregate multiple summary tables.
extract(sim[, items])Extract summary data from a Simulation.
fig_leg_bid_price_detail_rake(*, leg_id[, ...])fig_leg_bid_price_history(carrier, *, measure)fig_leg_booking_detail_rake(*, leg_id[, ...])Return information about the file store.
from_file(filename[, read_latest, lazy])Load the object from a file.
from_pickle(filename[, read_latest])Load the object from a pickle file.
metadata([key])Return a metadata value.
remove_data(keys)Remove data from the summary tables.
run_queries([cnx, items, scenario, burn_samples])Query summary data from a Database.
save(filename, *[, timestamp, make_dirs, ...])Save the object to a set of files.
Return a list of all concrete subclasses.
to_file(filename[, add_timestamp_ext, ...])Write simulation tables to a file.
to_html(filename, *[, cfg, make_dirs, ...])Write simulation tables report summary to html.
to_pickle(filename[, add_timestamp_ext, ...])Save to a pickle file.
to_xlsx(filename)Write simulation tables to excel.
Attributes
Data collected during callbacks.
Configuration for the Simulation run.
Database connection for the Simulation run.
Simulation object for the Simulation run.
Total number of sample departures simulated to create these summaries.
Summaries that were aggregated to create this summary.
- classmethod subclasses() list[type[GenericSimulationTables]][source]¶
Return a list of all concrete subclasses.
User defined subclasses (those not in the passengersim package) are at the front of the list, so they come first in MRO and thus can override native subclasses.
- cnx¶
Database connection for the Simulation run.
- sim¶
Simulation object for the Simulation run.
- n_total_samples¶
Total number of sample departures simulated to create these summaries.
This excludes any burn samples.
- meta_summaries¶
Summaries that were aggregated to create this summary.
-
classmethod extract(sim: Simulation, items: Collection[str] =
()) Self[source]¶ Extract summary data from a Simulation.
-
run_queries(cnx: Database =
None, items: Collection[str] | None =None, *, scenario: str =None, burn_samples: int | None =None) Self[source]¶ Query summary data from a Database.
The requested items will be queried from the database and stored in this summary object. If the item is not available, an exception will be raised.
- Parameters:
- cnx : Database, optional¶
Database connection to use for querying.
- items : Collection[str], optional¶
The items to query. If None, or if only “*” is given, then all available items will be queried.
- scenario : str, optional¶
The scenario to use for querying.
- burn_samples : int, optional¶
The number of burn samples to use for querying. If explicitly None, the burn_samples value from the configuration will be used if available, otherwise the default value of 100 will be used.
- classmethod aggregate(summaries: Collection[GenericSimulationTables]) Self[source]¶
Aggregate multiple summary tables.
-
fig_leg_bid_price_detail_rake(*, leg_id: int, raw_df: bool =
False, color: str ='#6a3d9a', mean_color: str | None ='#ff7f00')¶
-
fig_leg_bid_price_history(carrier: str, *, measure: 'mean' | 'q10' | 'q25' | 'q50' | 'q75' | 'q90' | 'median', haul_category_labels: tuple[str, ...] | None =
('a. Short: ', 'b. Medium: ', 'c. Long: ', 'd. Longest: '), opacity: float =0.25, max_rows: int =5000) alt.Chart¶
- property leg_bid_price_detail¶
- property leg_booking_detail¶
-
to_pickle(filename: str | Path, add_timestamp_ext: bool =
True, *, preserve_meta_summaries: bool =False, preserve_config: bool =True, make_dirs: True | False | 'git' =True) Path[source]¶ Save to a pickle file.
This method uses lz4 compression if the lz4.frame module is available.
- Parameters:
- filename : str or Path-like¶
The filename to save the object to. An extension map be added or modified, to optionally add a time stamp and/or compression flag.
- add_timestamp_ext : bool, default True¶
Add a timestamp extension to the filename.
- preserve_meta_summaries : bool, default False¶
Preserve the meta_summaries attribute in the saved object.
- preserve_config : bool, default False¶
Preserve the config attribute in the saved object. This includes the entire network, and can potentially be a lot of data.
- make_dirs : bool or "git", default True¶
If True, create the parent directory for the pickle file if it does not already exist. If the directory is created, it will be created with a .gitignore file to prevent accidental inclusion of pickled output in Git repositories, unless the value is “git”, in which case no .gitignore file is created and the results will be eligible for inclusion in Git.
- Returns:
Path-like – The resolved filename for the saved outputs.
-
classmethod from_pickle(filename: str | Path, read_latest: bool =
True)[source]¶ Load the object from a pickle file.
-
to_file(filename: str | Path, add_timestamp_ext: bool =
True, *, preserve_config: bool =True, make_dirs: True | False | 'git' =True) Path[source]¶ Write simulation tables to a file.
- Parameters:
- filename : Path-like¶
The file to write.
- add_timestamp_ext : bool, default True¶
Add a timestamp extension to the filename.
- preserve_config : bool, default True¶
Preserve the config attribute in the saved object. This includes the entire network, and can potentially be a lot of data.
- make_dirs : bool or "git", default True¶
If True, create the parent directory for the file if it does not already exist. If the directory is created, it will be created with a .gitignore file to prevent accidental inclusion of output in Git repositories, unless the value is “git”, in which case no .gitignore file is created and the results will be eligible for inclusion in Git.
- Returns:
Path-like – The resolved filename for the saved outputs.
-
classmethod from_file(filename: str | Path, read_latest: bool =
True, lazy: bool =True)[source]¶ Load the object from a file.
- remove_data(keys: Collection[str] | str) Self[source]¶
Remove data from the summary tables.
This can be used to reduce the size of the summary tables when saving to a file, or to remove sensitive data before sharing the summary tables.
- Parameters:
- keys : Collection[str] or str¶
The key(s) of the data to remove.
- Returns:
Self – The summary tables object, with the specified data removed.
- to_xlsx(filename: str | Path) None[source]¶
Write simulation tables to excel.
- Parameters:
- filename : Path-like¶
The excel file to write.
-
to_html(filename: str | Path, *, cfg: Config | None =
None, make_dirs: bool =True, extra: tuple =(), add_timestamp: bool =True) Path[source]¶ Write simulation tables report summary to html.
- Parameters:
- filename : Path-like, optional¶
The html file to write.
- cfg : Config, optional¶
The configuration to use for the report. If None, the configuration from the simulation object will be used.
- make_dirs : bool, default True¶
If True, create any necessary directories.
- extra : tuple, optional¶
Additional data to include in the report. Each item in the tuple should either a section or subsection title, or a tuple of (title, func), or just a function. If a function is provided, it should take the summary as its only argument and return a figure (altair.Chart or xmle.Elem) or table (pandas.DataFrame). The function will be called with the summary as its only argument. To use a function that requires other arguments, use functools.partial provide the other arguments.
- add_timestamp : bool, default True¶
If True, append a timestamp to the filename. This ensures that each report is unique and does not overwrite previous reports. If False, the filename will be used as-is. Set this to False if you want to overwrite previous reports with the same filename, or if you are already setting the timestamp yourself.
- Returns:
Path-like – The resolved filename for the saved outputs.
-
save(filename: str | Path, *, timestamp: float | struct_time | datetime | None =
None, make_dirs: True | False | 'git' =True, cfg: Config | None =None, extra_html: tuple =()) dict[str, Path][source]¶ Save the object to a set of files.
This method will write both an HTML report on this simulation tables object and a “.pxsim” file allowing the content to be restored.
- Parameters:
- filename : Path-like¶
The file stem to use for writing files.
- timestamp : float or time.struct_time or datetime, optional¶
The timestamp to use for the filenames. If not provided, the current time will be used.
- make_dirs : bool or "git", default True¶
If True, create the parent directory for the files if it does not already exist. If the directory is created, it will be created with a .gitignore file to prevent accidental inclusion of output in Git repositories, unless the value is “git”, in which case no .gitignore file is created and the results will be eligible for inclusion in Git.
- cfg : Config, optional¶
The configuration to use for the HTML report. If None, the configuration from the simulation object will be used if available.
- extra_html : tuple, optional¶
Additional data to include in the HTML report. This argument is passed to to_html, see that function for more details.
- Returns:
dict – A dictionary of filenames written, including the timestamp added.
- property config¶
Configuration for the Simulation run.
- property callback_data¶
Data collected during callbacks.