From 3a2d2d9d4dda7fd20fa9f6985582d9a60845db55 Mon Sep 17 00:00:00 2001 From: Alexey Zakharenkov Date: Thu, 30 Jul 2020 21:59:38 +0300 Subject: [PATCH] Take into account that two route itineraries may have the same stop sequence and differ only by interval --- checkers/common.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/checkers/common.py b/checkers/common.py index bc8b809..b760b62 100644 --- a/checkers/common.py +++ b/checkers/common.py @@ -1,7 +1,6 @@ import logging import math import functools -from itertools import chain """A coordinate of a station precision of which we must take into account @@ -22,6 +21,11 @@ def osm_id_comparator(el): return (el['osm_type'], el['osm_id']) +def itinerary_comparator(itinerary): + "This function is used as key for sorting itineraries in a route""" + return (itinerary['stops'], itinerary['interval']) + + def compare_stops(stop0, stop1): """Compares json of two stops in route""" stop_keys = ('name', 'int_name', 'id', 'osm_id', 'osm_type') @@ -119,10 +123,8 @@ def compare_networks(network0, network1): route0['route_id'], route0_props, route1_props) return False - itineraries0 = sorted(route0['itineraries'], - key=lambda x: tuple(chain(*x['stops']))) - itineraries1 = sorted(route1['itineraries'], - key=lambda x: tuple(chain(*x['stops']))) + itineraries0 = sorted(route0['itineraries'], key=itinerary_comparator) + itineraries1 = sorted(route1['itineraries'], key=itinerary_comparator) for itin0, itin1 in zip(itineraries0, itineraries1): if itin0['interval'] != itin1['interval']: