eflips-depot 4.12.0__py3-none-any.whl → 4.12.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of eflips-depot might be problematic. Click here for more details.

@@ -1106,7 +1106,7 @@ def add_evaluation_to_database(
1106
1106
 
1107
1107
 
1108
1108
  def generate_depot_optimal_size(
1109
- scenario: Scenario,
1109
+ scenario: Union[Scenario, int, Any],
1110
1110
  standard_block_length: int = 6,
1111
1111
  charging_power: float = 90,
1112
1112
  database_url: Optional[str] = None,
@@ -1117,7 +1117,9 @@ def generate_depot_optimal_size(
1117
1117
  Generates an optimal depot layout with the smallest possible size for each depot in the scenario. Line charging areas
1118
1118
  with given block length area preferred. The existing depot will be deleted if `delete_existing_depot` is set to True.
1119
1119
 
1120
- :param scenario: A :class:`eflips.model.Scenario` object containing the input data for the simulation.
1120
+ :param scenario: Either a :class:`eflips.model.Scenario` object containing the input data for the simulation. Or
1121
+ an integer specifying the ID of a scenario in the database. Or any other object that has an attribute "id" containing
1122
+ an integer pointing to a unique scenario id.
1121
1123
  :param standard_block_length: The standard block length for the depot layout in meters. Default is 6.
1122
1124
  :param charging_power: The charging power of the charging area in kW. Default is 90.
1123
1125
  :param database_url: An optional database URL. Used if no database url is given by the environment variable.
@@ -1133,6 +1135,20 @@ def generate_depot_optimal_size(
1133
1135
  logger = logging.getLogger(__name__)
1134
1136
 
1135
1137
  with create_session(scenario, database_url) as (session, scenario):
1138
+ # Delete all depot events
1139
+ session.query(Event).filter(
1140
+ Event.scenario_id == scenario.id, Event.area_id.isnot(None)
1141
+ ).delete()
1142
+
1143
+ if session.query(Depot).filter(Depot.scenario_id == scenario.id).count() != 0:
1144
+ if delete_existing_depot is False:
1145
+ raise ValueError(
1146
+ "Depot already exists. Set delete_existing_depot to True to delete it."
1147
+ )
1148
+
1149
+ delete_depots(scenario, session)
1150
+
1151
+ outer_savepoint = session.begin_nested()
1136
1152
  # Delete all vehicles and events, also disconnect the vehicles from the rotations
1137
1153
  rotation_q = session.query(Rotation).filter(Rotation.scenario_id == scenario.id)
1138
1154
  rotation_q.update({"vehicle_id": None})
@@ -1140,11 +1156,6 @@ def generate_depot_optimal_size(
1140
1156
  session.query(Vehicle).filter(Vehicle.scenario_id == scenario.id).delete()
1141
1157
 
1142
1158
  # Handles existing depot
1143
- if session.query(Depot).filter(Depot.scenario_id == scenario.id).count() != 0:
1144
- if delete_existing_depot is False:
1145
- raise ValueError("Depot already exists.")
1146
-
1147
- delete_depots(scenario, session)
1148
1159
 
1149
1160
  ##### Step 0: Consumption Simulation #####
1150
1161
  # Run the consumption simulation for all depots
@@ -1185,7 +1196,7 @@ def generate_depot_optimal_size(
1185
1196
  len(rotations) for vehicle_type, rotations in vehicle_type_dict.items()
1186
1197
  )
1187
1198
 
1188
- savepoint = session.begin_nested()
1199
+ inner_savepoint = session.begin_nested()
1189
1200
  try:
1190
1201
  # (Temporarily) Delete all rotations not starting or ending at the station
1191
1202
  logger.debug(
@@ -1224,11 +1235,11 @@ def generate_depot_optimal_size(
1224
1235
  depot_capacities_for_scenario[station] = vt_capacities_for_station
1225
1236
  num_rotations_for_scenario[station] = rotation_count_depot
1226
1237
  finally:
1227
- savepoint.rollback()
1238
+ inner_savepoint.rollback()
1228
1239
 
1229
- # create depot with the calculated area sizes
1240
+ outer_savepoint.rollback()
1230
1241
 
1231
- with create_session(scenario, database_url) as (session, scenario):
1242
+ # Create depot using the calculated capacities
1232
1243
  for depot_station, capacities in depot_capacities_for_scenario.items():
1233
1244
  generate_depot(
1234
1245
  capacities,
@@ -1240,10 +1251,3 @@ def generate_depot_optimal_size(
1240
1251
  num_shunting_slots=num_rotations_for_scenario[depot_station] // 10,
1241
1252
  num_cleaning_slots=num_rotations_for_scenario[depot_station] // 10,
1242
1253
  )
1243
-
1244
- # Delete all vehicles and events again. Only depot layout is kept
1245
-
1246
- rotation_q = session.query(Rotation).filter(Rotation.scenario_id == scenario.id)
1247
- rotation_q.update({"vehicle_id": None})
1248
- session.query(Event).filter(Event.scenario_id == scenario.id).delete()
1249
- session.query(Vehicle).filter(Vehicle.scenario_id == scenario.id).delete()
@@ -28,6 +28,10 @@ from sqlalchemy import or_
28
28
  from sqlalchemy.orm import Session
29
29
 
30
30
 
31
+ class MissingVehicleDimensionError(ValueError):
32
+ pass
33
+
34
+
31
35
  def delete_depots(scenario: Scenario, session: Session) -> None:
32
36
  """This function deletes all depot-related data from the database for a given scenario.
33
37
 
@@ -676,7 +680,10 @@ def area_needed_for_vehicle_parking(
676
680
  width = vehicle_type.width
677
681
 
678
682
  if length is None or width is None:
679
- raise ValueError(f"No length or width found for VehicleType {vehicle_type}")
683
+ raise MissingVehicleDimensionError(
684
+ f"No length or width found for VehicleType {vehicle_type}. VehicleType dimensions are required to "
685
+ f"calculate the area needed for parking."
686
+ )
680
687
 
681
688
  # This is the angle the vehicles are parked at in direct areas
682
689
  # zero is equivalent to the direction they would be parked in a line area
@@ -1070,6 +1077,9 @@ def depot_smallest_possible_size(
1070
1077
  logger.debug(
1071
1078
  f"Vehicle count for {vt.name} in {amount_of_line_areas} line areas configuration: {vehicle_count_q}. This is > than the all-direct configuration ({vehicle_counts_all_direct[vt]})."
1072
1079
  )
1080
+
1081
+ except MissingVehicleDimensionError as e:
1082
+ raise e
1073
1083
  except Exception as e:
1074
1084
  # This change is made after Unstable exception and delay exceptions are introduced
1075
1085
  if (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: eflips-depot
3
- Version: 4.12.0
3
+ Version: 4.12.2
4
4
  Summary: Depot Simulation for eFLIPS
5
5
  License: AGPL-3.0-or-later
6
6
  Author: Enrico Lauth
@@ -1,9 +1,9 @@
1
1
  eflips/depot/__init__.py,sha256=06GUem0JIEunIyJ0_P_MLAGfibGEnNqcPPY0OBpO2NQ,1662
2
- eflips/depot/api/__init__.py,sha256=t153i_ZJA82O5w7GSY3-NAz8sSDI4mLZdjKrroFu_-M,54945
2
+ eflips/depot/api/__init__.py,sha256=bxxRaknhMc_9xxBATFe_bcGzZQI9sYDhYwRF5Z74B1E,55055
3
3
  eflips/depot/api/defaults/default_settings.json,sha256=0eUDTw_rtLQFvthP8oJL93iRXlmAOravAg-4qqGMQAY,5375
4
4
  eflips/depot/api/private/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  eflips/depot/api/private/consumption.py,sha256=nImegyhKrZlEwKTNdmAmDxjTQCvwfPgxA588e0M_F9o,27282
6
- eflips/depot/api/private/depot.py,sha256=-LpLeEi3ctjsLzWbBGDBTic_aKrb6S35ii5wt-7QTmI,43359
6
+ eflips/depot/api/private/depot.py,sha256=YyC_jMDGkg8yOAiYkKzb5HboFM1P4x-GTJSfD8srdvE,43640
7
7
  eflips/depot/api/private/results_to_database.py,sha256=_qXB9046dWHek4ys669J3IojJt4xlZRkW1HxT7OTLFo,25524
8
8
  eflips/depot/api/private/util.py,sha256=rDqVuB4sllFZmNvXuDktIsFRoR9l-AWc4QM00e1Quvw,17966
9
9
  eflips/depot/configuration.py,sha256=Op3hlir-dEN7yHr0kTqbYANoCBKFWK6uKOv3NJl8w_w,35678
@@ -36,7 +36,7 @@ eflips/depot/simulation.py,sha256=ee0qTzOzG-8ybN36ie_NJallXfC7jUaS9JZvaYFziLs,10
36
36
  eflips/depot/smart_charging.py,sha256=C3BYqzn2-OYY4ipXm0ETtavbAM9QXZMYULBpVoChf0E,54311
37
37
  eflips/depot/standalone.py,sha256=8O01zEXghFG9zZBu0fUD0sXvbHQ-AXw6RB5M750a_sM,22419
38
38
  eflips/depot/validation.py,sha256=TIuY7cQtEJI4H2VVMSuY5IIVkacEEZ67weeMuY3NSAM,7097
39
- eflips_depot-4.12.0.dist-info/LICENSE.md,sha256=KB4XTk1fPHjtZCYDyPyreu6h1LVJVZXYg-5vePcWZAc,34143
40
- eflips_depot-4.12.0.dist-info/METADATA,sha256=IhvhXaJwVlfImiFwOdf4RTAH7rTmMnpabfsogv18mO8,5985
41
- eflips_depot-4.12.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
42
- eflips_depot-4.12.0.dist-info/RECORD,,
39
+ eflips_depot-4.12.2.dist-info/LICENSE.md,sha256=KB4XTk1fPHjtZCYDyPyreu6h1LVJVZXYg-5vePcWZAc,34143
40
+ eflips_depot-4.12.2.dist-info/METADATA,sha256=stky1qkggwYTAaplInWyVQCBDmm-bakDwex3bNXe7Kc,5985
41
+ eflips_depot-4.12.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
42
+ eflips_depot-4.12.2.dist-info/RECORD,,