Skip to content

Commit

Permalink
simplified: id generation to kick in only when string conversion fails
Browse files Browse the repository at this point in the history
  • Loading branch information
nagacharan-tangirala committed Dec 27, 2024
1 parent f3afca1 commit f5aaa7d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/prep_disolv/vehicle/sumo.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ def get_parquet_file(self) -> Path:

def get_vehicle_id_from_pool(self, vehicle_id_str: str) -> int:
"""Return a vehicle ID from the map."""
if vehicle_id_str in self.vehicle_id_pool.keys():
vehicle_id = self.vehicle_id_pool[vehicle_id_str]
else:
vehicle_id = self.vehicle_id_init
self.vehicle_id_pool[vehicle_id_str] = vehicle_id
self.vehicle_id_init = self.vehicle_id_init + 1
try:
vehicle_id = int(vehicle_id_str)
except ValueError:
if vehicle_id_str in self.vehicle_id_pool.keys():
vehicle_id = self.vehicle_id_pool[vehicle_id_str]
else:
vehicle_id = self.vehicle_id_init
self.vehicle_id_pool[vehicle_id_str] = vehicle_id
self.vehicle_id_init = self.vehicle_id_init + 1
return vehicle_id

def _convert_fcd_to_parquet(self) -> None:
Expand Down

0 comments on commit f5aaa7d

Please sign in to comment.