Sales and revenue by passenger segment¶
Track cumulative bookings and realized revenue by passenger segment at each data collection point (DCP). The tracer reads fare counters directly, so it also works when the simulation database is disabled.
Collect the data¶
Load the 3MKT demo and attach the tracer before running it:
import passengersim as pax
from passengersim.tracers import SegmentationTracer
cfg = pax.Config.from_yaml(pax.demo_network("3MKT"))
cfg.simulation_controls.num_trials = 1
cfg.simulation_controls.num_samples = 800
cfg.simulation_controls.burn_samples = 50
cfg.simulation_controls.show_progress_bar = False
cfg.db = None
cfg.outputs.reports.clear()
cfg.outputs._write_no_files()
with pax.Simulation(cfg) as sim:
SegmentationTracer(markets=["BOS-LAX", "BOS-ORD"]).attach(sim)
summary = sim.run()
table = summary.callback_data["segmentation_detail"]
To enable the same tracer in YAML:
callbacks:
segmentation_detail:
parameters:
markets: [BOS-LAX, BOS-ORD]
Read the results¶
The table contains average cumulative sold and revenue per retained sample by carrier, origin,
destination, booking class, segment, and days before departure. You can also read it as
summary.segmentation_detail_traced. Markets are directional. Omit markets for all markets, or
narrow the selection further with carriers and segments. The optional daily priority defaults
to 1.
table.head()
| sold | revenue | ||||||
|---|---|---|---|---|---|---|---|
| carrier | orig | dest | booking_class | segment | days_prior | ||
| AL1 | BOS | LAX | Y0 | business | 0 | 20.645333 | 15484.0 |
| 1 | 19.905333 | 14929.0 | |||||
| 3 | 16.621333 | 12466.0 | |||||
| 5 | 14.830667 | 11123.0 | |||||
| 7 | 13.178667 | 9884.0 |
from passengersim.tracers.segmentation import segmentation_detail_traced
segmentation_detail_traced(summary, timeframe=True, wide=True).head()
| sold | revenue | sold_business | sold_leisure | revenue_business | revenue_leisure | |||||
|---|---|---|---|---|---|---|---|---|---|---|
| carrier | orig | dest | booking_class | days_prior | ||||||
| AL1 | BOS | LAX | Y0 | 1 | 0.742667 | 557.0 | 0.740000 | 0.002667 | 555.0 | 2.0 |
| 3 | 3.286667 | 2465.0 | 3.284000 | 0.002667 | 2463.0 | 2.0 | ||||
| 5 | 1.794667 | 1346.0 | 1.790667 | 0.004000 | 1343.0 | 3.0 | ||||
| 7 | 1.653333 | 1240.0 | 1.652000 | 0.001333 | 1239.0 | 1.0 | ||||
| 10 | 2.605333 | 1954.0 | 2.605333 | 0.000000 | 1954.0 | 0.0 |
summary.fig_segmentation_detail(metric="revenue", orig="BOS", dest="LAX")
timeframe=True gives sales and revenue within each timeframe. wide=True puts segments in
columns. Use segment_metric_table(summary, metric="revenue") from the same module for a cumulative
table of a single metric. For a filtered tracer, request a figure covering a market and carrier you
collected. Broader booking requests fall back to the database; revenue figures require tracer
coverage. See the segmentation summary table.