depot.api.private.results_to_database ===================================== .. py:module:: depot.api.private.results_to_database Exceptions ---------- .. autoapisummary:: depot.api.private.results_to_database.DelayedTripException depot.api.private.results_to_database.UnstableSimulationException Functions --------- .. autoapisummary:: depot.api.private.results_to_database.get_finished_schedules_per_vehicle depot.api.private.results_to_database.generate_vehicle_events depot.api.private.results_to_database.complete_standby_departure_events depot.api.private.results_to_database.add_soc_to_events depot.api.private.results_to_database.add_events_into_database depot.api.private.results_to_database.update_vehicle_in_rotation depot.api.private.results_to_database.update_waiting_events Module Contents --------------- .. py:exception:: DelayedTripException Bases: :py:obj:`Exception` Common base class for all non-exit exceptions. .. py:attribute:: _delayed_trips :value: [] .. py:method:: raise_later(simple_trip) .. py:property:: has_errors .. py:method:: __str__() Return str(self). .. py:exception:: UnstableSimulationException Bases: :py:obj:`Exception` Common base class for all non-exit exceptions. .. py:attribute:: _unstable_trips :value: [] .. py:method:: raise_later(simple_trip) .. py:property:: has_errors .. py:method:: __str__() Return str(self). .. py:function:: 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 :func:`_update_vehicle_in_rotation()`. 2. 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. :param dict_of_events: An ordered dictionary storing the data related to an event. The keys are the start times of the events. :param list_of_finished_trips: A list of finished trips of a vehicle directly from :class:`eflips.depot.simple_vehicle.SimpleVehicle` object. :param db_vehicle_id: The vehicle id in the database. :return: 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. .. py:function:: 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. :param current_vehicle: a :class:`eflips.depot.simple_vehicle.SimpleVehicle` object. :param virtual_waiting_area_id: the id of the virtual waiting area. Vehicles waiting for the first process will park here. :param earliest_time: the earliest relevant time of the current vehicle. Any events earlier than this will not be handled. :param latest_time: the latest relevant time of the current vehicle. Any events later than this will not be handled. :return: None. The results are added to the dictionary. .. py:function:: 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. :param dict_of_events: a dictionary containing the events of a vehicle. The keys are the start times of the events. :param latest_time: the latest relevant time of the current vehicle. Any events later than this will not be handled. :return: None. The results are added to the dictionary. .. py:function:: add_soc_to_events(dict_of_events, battery_log) This function completes the soc of each event by looking up the battery log. :param dict_of_events: a dictionary containing the events of a vehicle. The keys are the start times of the events. :param battery_log: a list of battery logs of a vehicle. :return: None. The results are added to the dictionary. .. py:function:: add_events_into_database(db_vehicle, dict_of_events, session, scenario, simulation_start_time, area_cache) This function generates :class:`eflips.model.Event` objects from the dictionary of events and adds them into the. database. :param db_vehicle: vehicle object in the database :param dict_of_events: dictionary containing the events of a vehicle. The keys are the start times of the events. :param session: a :class:`sqlalchemy.orm.Session` object for database connection. :param scenario: the current simulated scenario :param simulation_start_time: simulation start time in :class:`datetime.datetime` format :param area_cache: a dict mapping area_id to the corresponding :class:`eflips.model.Area` object, pre-fetched with depot eagerly loaded. :return: None. The results are added to the database. .. py:function:: 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. :param session: a :class:`sqlalchemy.orm.Session` object for database connection. :param scenario: the current simulated scenario :param list_of_assigned_rotations: a list of tuples containing the rotation id and the vehicle id. :return: None. The results are added to the database. .. py:function:: 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. :param session: a :class:`sqlalchemy.orm.Session` object for database connection. :param scenario: the current simulated scenario. :param waiting_area_id: id of the waiting area. :raise ValueError: if the waiting area capacity is less than the peak waiting occupancy. :return: None. The results are added to the database.