From 0df42132670f9b586a3a9ca8c6698176918e72e2 Mon Sep 17 00:00:00 2001 From: Alexey Zakharenkov Date: Sat, 27 May 2023 21:08:16 +0300 Subject: [PATCH] Defer stop distances calculation until city is validated --- process_subways.py | 1 + subway_structure.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/process_subways.py b/process_subways.py index c81a21c..6f7e846 100755 --- a/process_subways.py +++ b/process_subways.py @@ -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 diff --git a/subway_structure.py b/subway_structure.py index 86a0f30..823aea6 100644 --- a/subway_structure.py +++ b/subway_structure.py @@ -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 = []