depot.api.private.results_to_database¶
Exceptions¶
Common base class for all non-exit exceptions. |
|
Common base class for all non-exit exceptions. |
Functions¶
|
This function completes the following tasks: |
|
This function generates and ordered dictionary storing the data related to an event. |
|
This function completes the standby departure events by adding an end time to each standby departure event. |
|
This function completes the soc of each event by looking up the battery log. |
|
This function generates |
|
This function updates the vehicle id assigned to the rotations and deletes the events that are not depot events. |
|
This function evaluates the capacity of waiting area and assigns the waiting events to corresponding slots in the. |
Module Contents¶
- exception depot.api.private.results_to_database.DelayedTripException¶
Bases:
ExceptionCommon base class for all non-exit exceptions.
- _delayed_trips = []¶
- raise_later(simple_trip)¶
- property has_errors¶
- __str__()¶
Return str(self).
- exception depot.api.private.results_to_database.UnstableSimulationException¶
Bases:
ExceptionCommon base class for all non-exit exceptions.
- _unstable_trips = []¶
- raise_later(simple_trip)¶
- property has_errors¶
- __str__()¶
Return str(self).
- depot.api.private.results_to_database.get_finished_schedules_per_vehicle(dict_of_events, list_of_finished_trips, db_vehicle_id, unstable_exp, delay_exp)¶
This function completes the following tasks:
1. It gets the finished non-copy schedules of the current vehicle, which will be used in
_update_vehicle_in_rotation().It fills the dictionary of events with the trip_ids of the current vehicle.
3. It returns an earliest and a latest time according to this vehicle’s schedules. Only processes happening within this time window will be handled later.
Usually the earliest time is the departure time of the last copy trip in the “early-shifted” copy schedules and the lastest time is the departure time of the first copy trip in the “late-shifted” copy schedules.
# If the vehicle’s first trip is a non-copy trip, the earliest time is the departure time of the first trip. If the # vehicle’s last trip is a non-copy trip, the latest time is the departure time of the last trip.
- Parameters:
dict_of_events – An ordered dictionary storing the data related to an event. The keys are the start times of the events.
list_of_finished_trips (List) – A list of finished trips of a vehicle directly from
eflips.depot.simple_vehicle.SimpleVehicleobject.db_vehicle_id (int) – The vehicle id in the database.
unstable_exp (UnstableSimulationException)
delay_exp (DelayedTripException)
- Returns:
A tuple of three elements. The first element is a list of finished schedules of the vehicle. The second and third elements are the earliest and latest time of the vehicle’s schedules.
- depot.api.private.results_to_database.generate_vehicle_events(dict_of_events, current_vehicle, virtual_waiting_area_id, earliest_time, latest_time)¶
This function generates and ordered dictionary storing the data related to an event.
It returns a dictionary. The keys are the start times of the events. The values are also dictionaries containing: - type: The type of the event. - end: The end time of the event. - area: The area id of the event. - slot: The slot id of the event. - id: The id of the event-related process.
For trips, only the type is stored.
For waiting events, the slot is not stored for now.
- Parameters:
current_vehicle (eflips.depot.SimpleVehicle) – a
eflips.depot.simple_vehicle.SimpleVehicleobject.virtual_waiting_area_id (int) – the id of the virtual waiting area. Vehicles waiting for the first process will park here.
earliest_time (datetime.datetime) – the earliest relevant time of the current vehicle. Any events earlier than this will not be handled.
latest_time (datetime.datetime) – the latest relevant time of the current vehicle. Any events later than this will not be handled.
- Returns:
None. The results are added to the dictionary.
- Return type:
None
- depot.api.private.results_to_database.complete_standby_departure_events(dict_of_events, latest_time)¶
This function completes the standby departure events by adding an end time to each standby departure event.
- Parameters:
dict_of_events (Dict) – a dictionary containing the events of a vehicle. The keys are the start times of the events.
latest_time (datetime.datetime) – the latest relevant time of the current vehicle. Any events later than this will not be handled.
- Returns:
None. The results are added to the dictionary.
- Return type:
None
- depot.api.private.results_to_database.add_soc_to_events(dict_of_events, battery_log)¶
This function completes the soc of each event by looking up the battery log.
- Parameters:
dict_of_events – a dictionary containing the events of a vehicle. The keys are the start times of the events.
battery_log – a list of battery logs of a vehicle.
- Returns:
None. The results are added to the dictionary.
- Return type:
None
- depot.api.private.results_to_database.add_events_into_database(db_vehicle, dict_of_events, session, scenario, simulation_start_time, area_cache)¶
This function generates
eflips.model.Eventobjects from the dictionary of events and adds them into the.database.
- Parameters:
db_vehicle – vehicle object in the database
dict_of_events – dictionary containing the events of a vehicle. The keys are the start times of the events.
session – a
sqlalchemy.orm.Sessionobject for database connection.scenario – the current simulated scenario
simulation_start_time – simulation start time in
datetime.datetimeformatarea_cache – a dict mapping area_id to the corresponding
eflips.model.Areaobject, pre-fetched with depot eagerly loaded.
- Returns:
None. The results are added to the database.
- Return type:
None
- depot.api.private.results_to_database.update_vehicle_in_rotation(session, scenario, list_of_assigned_rotations)¶
This function updates the vehicle id assigned to the rotations and deletes the events that are not depot events.
- Parameters:
session – a
sqlalchemy.orm.Sessionobject for database connection.scenario – the current simulated scenario
list_of_assigned_rotations – a list of tuples containing the rotation id and the vehicle id.
- Returns:
None. The results are added to the database.
- Return type:
None
- depot.api.private.results_to_database.update_waiting_events(session, scenario, waiting_area_id)¶
This function evaluates the capacity of waiting area and assigns the waiting events to corresponding slots in the.
waiting area.
- Parameters:
session – a
sqlalchemy.orm.Sessionobject for database connection.scenario – the current simulated scenario.
waiting_area_id – id of the waiting area.
- Raises:
ValueError – if the waiting area capacity is less than the peak waiting occupancy.
- Returns:
None. The results are added to the database.
- Return type:
None