The analytics package

get_stops_and_requests(*, events, space)[source]

Prepare two DataFrames, containing stops and requests.

# NOTE: This assumes occupancy delta of +1/-1, i.e. only single-customer requests. # If the simulator should allow for multi-customer requests in the future, # this must be changed. # See also [issue #45](https://github.com/PhysicsOfMobility/ridepy/issues/45)

The stops DataFrame returned has the following schema:

Column                                       Dtype
------                                       -----
vehicle_id                                 float64
stop_id                                      int64
timestamp                                  float64
delta_occupancy                            float64
request_id                                   int64
state_duration                             float64
occupancy                                  float64
location                                    object
dist_to_next                               float64
time_to_next                               float64
timestamp_submitted                        float64
insertion_index                            float64
leg_1_dist_service_time                    float64
leg_2_dist_service_time                    float64
leg_direct_dist_service_time               float64
detour_dist_service_time                   float64
leg_1_dist_submission_time                 float64
leg_2_dist_submission_time                 float64
leg_direct_dist_submission_time            float64
detour_dist_submission_time                float64
stoplist_length_submission_time            float64
stoplist_length_service_time               float64
avg_segment_dist_submission_time           float64
avg_segment_time_submission_time           float64
avg_segment_dist_service_time              float64
avg_segment_time_service_time              float64
system_stoplist_length_submission_time     float64
system_stoplist_length_service_time        float64
avg_system_segment_dist_submission_time    float64
avg_system_segment_time_submission_time    float64
avg_system_segment_dist_service_time       float64
avg_system_segment_time_service_time       float64
relative_insertion_position                float6

The requests DataFrame returned has the following schema:

Column                               Dtype
------                               -----
(submitted, timestamp)                float64
(submitted, origin)                   Union[float64, int, Tuple[float64]]
(submitted, destination)              Union[float64, int, Tuple[float64]]
(submitted, pickup_timewindow_min)    float64
(submitted, pickup_timewindow_max)    float64
(submitted, delivery_timewindow_min)  float64
(submitted, delivery_timewindow_max)  float64
(submitted, direct_travel_distance)   float64
(submitted, direct_travel_time)       float64
(accepted, timestamp)                 float64
(accepted, origin)                    Union[float64, int, Tuple[float64]]
(accepted, destination)               Union[float64, int, Tuple[float64]]
(accepted, pickup_timewindow_min)     float64
(accepted, pickup_timewindow_max)     float64
(accepted, delivery_timewindow_min)   float64
(accepted, delivery_timewindow_max)   float64
(rejected, timestamp)                 float64
(inferred, relative_travel_time)      float64
(inferred, travel_time)               float64
(inferred, waiting_time)              float64
(serviced, timestamp_dropoff)         float64
(serviced, timestamp_pickup)          float64
(serviced, vehicle_id)                float64
Parameters:
  • events (List[dict]) – list of all the events returned by the simulation

  • space (TransportSpace) – transportation space that was used for the simulations

Returns:

  • stops – dataframe indexed by [vehicle_id, timestamp] containing all stops

  • requests – dataframe indexed by request_id containing all requests

Return type:

tuple[DataFrame, DataFrame]

get_stops_and_requests_from_events_dataframe(*, events_df, space)[source]

Prepare stops and requests dataframes from an events dataframe. For details on the returned dataframes see doc on outside-facing get_stops_and_requests.

Parameters:
Returns:

  • stops – dataframe indexed by [vehicle_id, timestamp] containing all stops

  • requests – dataframe indexed by request_id containing all requests

Return type:

tuple[DataFrame, DataFrame]

get_vehicle_quantities(stops, requests)[source]

Compute various quantities aggregated per vehicle.

Currently, the following observables are returned:

  • avg_occupancy

  • avg_segment_dist

  • avg_segment_time

  • total_dist_driven

  • total_time_driven

  • avg_direct_dist

  • avg_direct_time

  • total_direct_dist

  • total_direct_time

  • efficiency_dist

  • efficiency_time

  • avg_system_stoplist_length_service_time

  • avg_system_stoplist_length_submission_time

  • avg_stoplist_length_service_time

  • avg_stoplist_length_submission_time

Parameters:
  • stops (DataFrame) – Stops dataframe

  • requests (DataFrame) – Requests dataframe

Returns:

pd.DataFrame containing the aforementioned observables as columns, indexed by vehicle_id

Return type:

DataFrame

get_system_quantities(stops, requests, params=None)[source]

Compute various quantities aggregated for the entire simulation.

Currently, the following observables are returned (quantities in parentheses may not be returned if params is not given/stops does not contain the respective quantities):

  • (n_vehicles) – number of vehicles (simulation parameter)

  • (request_rate) – request rate (simulation parameter)

  • (velocity) – vehicle velocity (simulation parameter)

  • (load_requested) – load requested (derived from request rate, velocity, and number of vehicles as input parameters and the spaces’ average distance)

  • (load_serviced) – load requested (derived from request rate times (1-rejection ratio), velocity, and number of vehicles as input parameters and the spaces’ average distance)

  • (avg_direct_dist_space) – average direct distance in space, computed by taking 1e5 random samples

  • avg_occupancy

  • avg_segment_dist

  • avg_segment_time

  • total_dist_driven

  • total_time_driven

  • avg_direct_dist

  • avg_direct_time

  • total_direct_dist

  • total_direct_time

  • efficiency_dist

  • efficiency_time

  • avg_waiting_time

  • rejection_ratio

  • median_stoplist_length – median per-vehicle stoplist length, taken over all “stoplist states” (vehicles x time)

  • median_stoplist_length – median per-vehicle stoplist length, taken over all “stoplist states” (vehicles x time)

  • mean_system_stoplist_length – arithmetic mean system-wide stoplist length, taken over all “stoplist states” (time)

  • mean_system_stoplist_length – arithmetic mean system-wide stoplist length, taken over all “stoplist states” (time)

  • avg_detour

  • (avg_system_stoplist_length_service_time)

  • (avg_system_stoplist_length_submission_time)

  • (avg_stoplist_length_service_time)

  • (avg_stoplist_length_submission_time)

Parameters:
  • stops (DataFrame) – Stops dataframe

  • requests (DataFrame) – Requests dataframe

  • params (dict[str, dict[str, Any]] | None) – Optional, adds more data (the fields in parentheses) to the result for convenience purposes

Returns:

system_quantities – dict containing the aforementioned observables

Return type:

dict[str, int | float]