Defer stop distances calculation until city is validated

This commit is contained in:
Alexey Zakharenkov 2023-05-27 21:08:16 +03:00 committed by Alexey Zakharenkov
parent a08947bc4d
commit 0df4213267
2 changed files with 7 additions and 2 deletions

View file

@ -263,6 +263,7 @@ def validate_cities(cities: list[City]) -> list[City]:
else:
c.validate()
if c.is_good:
c.calculate_distances()
good_cities.append(c)
return good_cities

View file

@ -1040,7 +1040,7 @@ class Route:
)
return stop_position_elements
def process_tracks(self, stop_position_elements):
def process_tracks(self, stop_position_elements: list[dict]) -> None:
tracks, line_nodes = self.build_longest_line()
for stop_el in stop_position_elements:
@ -1084,7 +1084,6 @@ class Route:
projected_stops_data = self.project_stops_on_line()
self.check_and_recover_stops_order(projected_stops_data)
self.apply_projected_stops_data(projected_stops_data)
self.calculate_distances()
def apply_projected_stops_data(self, projected_stops_data: dict) -> None:
"""Store better stop coordinates and indexes of first/last stops
@ -2074,6 +2073,11 @@ class City:
self.validate_called = True
def calculate_distances(self) -> None:
for route_master in self:
for route in route_master:
route.calculate_distances()
def find_transfers(elements, cities):
transfers = []