LegDetailTracer¶
-
class passengersim.callbacks.booking_detail.LegDetailTracer(leg_ids: list[int], *, priority: int =
1, name: str | None =None)[source]¶ Bases:
GenericTracerBase for daily tracers keeping one value per leg, sample, and day.
Each call records one row, keyed by
(trial, sample, days_prior), with one column per selected leg. Unlike the summary-statistic tracers, every observation is kept, so quantiles can be computed afterwards. Subclasses setnameand implement_value().Initialize the tracer.
- Parameters:
- leg_ids : list[int]¶
The legs to record. IDs not found in the simulation are ignored.
- priority : int, default 1¶
Daily offset in seconds from the overnight trigger; positive values run after the RM systems and the simulation’s daily bookkeeping. Zero is not allowed.
- name : str, optional¶
Key for the results in
callback_data; defaults to the class name. The summary accessors read only the default name.
Methods
__init__(leg_ids, *[, priority, name])Initialize the tracer.
attach(sim)Attach a fresh copy of this tracer to a simulation, on all its hooks.
finalize()Convert the recorded rows into a table.
fresh()Return a fresh copy of this tracer, tracing the same targets but not sharing state.
on_begin_sample(sim)Observe a sample after its first DCP, before any customer arrives.
on_daily(sim, days_prior)Observe each day of a sample.
on_end_sample(sim)Observe the end of a sample, before counters are reset.
on_finalize_sample(sim)Observe a sample after its events and bookkeeping have finished.
on_initialize_sample(sim)Observe the start of a sample, before its demand is generated.
reset()Discard all recorded rows, and forget the selected legs.
setup(sim)Select the legs to record, in the simulation's leg order.
Attributes
Lifecycle hook shared by manual and configured attachment.
Result key in
callback_data.Pydantic model of the constructor's keyword options, for configured callbacks.
Configured-callback implementation version; bump when results change meaning.
Burn-in samples are not recorded.
IDs of the legs to record.
Daily callback priority, see
CallbackMixin.daily_callback().-
hook : ClassVar[Literal['begin_sample', 'daily', 'end_sample']] =
'daily'¶ Lifecycle hook shared by manual and configured attachment.
-
skip_burn : ClassVar[bool] =
True¶ Burn-in samples are not recorded.
-
__init__(leg_ids: list[int], *, priority: int =
1, name: str | None =None)[source]¶ Initialize the tracer.
- Parameters:
- leg_ids : list[int]¶
The legs to record. IDs not found in the simulation are ignored.
- priority : int, default 1¶
Daily offset in seconds from the overnight trigger; positive values run after the RM systems and the simulation’s daily bookkeeping. Zero is not allowed.
- name : str, optional¶
Key for the results in
callback_data; defaults to the class name. The summary accessors read only the default name.
- leg_ids¶
IDs of the legs to record.
- priority¶
Daily callback priority, see
CallbackMixin.daily_callback().
- setup(sim: Any) None[source]¶
Select the legs to record, in the simulation’s leg order.
- Parameters:
- sim : Simulation¶
The simulation about to run.
- finalize() DataFrame[source]¶
Convert the recorded rows into a table.
- Returns:
pd.DataFrame – Indexed by
(trial, sample, days_prior), with one column per leg (namedleg_id). Theaggregation_processattribute is"concat_rows", so results from several workers are stacked.
- attach(sim: Simulation) None¶
Attach a fresh copy of this tracer to a simulation, on all its hooks.
- Parameters:
- sim : Simulation or MultiSimulation or Experiments¶
The object to attach to. The simulation stores a copy made with
fresh(), so this tracer object itself is never modified by a run and can be attached to several simulations.
- Raises:
TypeError – If the tracer declares no hook and overrides no hook method.
- fresh() GenericTracer¶
Return a fresh copy of this tracer, tracing the same targets but not sharing state.
The default makes a deep copy of this tracer and then calls
reset()on the copy. Override it if a tracer holds something that cannot be deep-copied, or that is expensive to copy.- Returns:
GenericTracer – A new tracer of the same type and configuration, with no accumulated data.
-
name : str =
'generic_tracer'¶ Result key in
callback_data.The class value is the canonical name. An instance may set its own name, so that two tracers of one class can be attached to the same simulation without overwriting each other’s results.
- on_begin_sample(sim: Simulation) dict | None¶
Observe a sample after its first DCP, before any customer arrives.
Override this to attach the tracer to the
begin_samplehook. Its time is set by the tracer’spriorityattribute, if it has one, as for a plain begin-sample callback.- Parameters:
- sim : Simulation¶
The running simulation.
- on_daily(sim: Simulation, days_prior: int) dict | None¶
Observe each day of a sample.
Override this to attach the tracer to the
dailyhook. The time of day is set by the tracer’spriorityattribute, if it has one, as for a plain daily callback.- Parameters:
- sim : Simulation¶
The running simulation.
- days_prior : int¶
Days remaining before departure.
- on_end_sample(sim: Simulation) dict | None¶
Observe the end of a sample, before counters are reset.
Override this to attach the tracer to the
end_samplehook. Its time is set by the tracer’spriorityattribute, if it has one, as for a plain end-sample callback.- Parameters:
- sim : Simulation¶
The running simulation.
- on_finalize_sample(sim: Simulation) dict | None¶
Observe a sample after its events and bookkeeping have finished.
Override this to attach the tracer to the
finalize_samplehook.- Parameters:
- sim : Simulation¶
The running simulation.
- on_initialize_sample(sim: Simulation) dict | None¶
Observe the start of a sample, before its demand is generated.
Override this to attach the tracer to the
initialize_samplehook. A returned dictionary is stored undercallback_data.initialize_sample, as for a plain callback.- Parameters:
- sim : Simulation¶
The running simulation.
-
options_model : ClassVar[type[BaseModel] | None] =
None¶ Pydantic model of the constructor’s keyword options, for configured callbacks.
By default, registration derives the model from the annotated constructor.
-
options_version : ClassVar[str] =
'1'¶ Configured-callback implementation version; bump when results change meaning.