def is_bus_on_the_route(self, route_name: str, bus_position: CdsBusPosition): if not bus_position.is_valid_coords(): return False route_stops = self.bus_routes.get(route_name, []) if not route_stops or len(route_stops) < 2: return False result = self.get_k_nearest_by_route(route_name, bus_position.lat, bus_position.lon, 1) return bus_position.distance_km(result[0]) < 1
def test_closest_bus_stop_checked(self): route_name = '5А' pos_1 = CdsBusPosition(51.705497, 39.149543, self.date_time) # у-м Молодёжный pos_2 = CdsBusPosition(51.705763, 39.155278, self.date_time) # 60 лет ВЛКСМ with self.subTest('From city center '): result = self.cds.get_closest_bus_stop_checked(route_name, (pos_2, pos_1)) self.assertTrue(result.NAME_ == 'у-м Молодежный (ул. Лизюкова из центра)') self.assertEqual(result.NUMBER_, 62) with self.subTest('To city center '): result = self.cds.get_closest_bus_stop_checked(route_name, (pos_1, pos_2)) self.assertEqual(result.NUMBER_, 5)
def test_closest_bus_stop_same_stations(self): positions = [CdsBusPosition(51.667033, 39.193648, self.date_time), CdsBusPosition(51.672135, 39.187541, self.date_time), CdsBusPosition(51.675065, 39.185286, self.date_time), CdsBusPosition(51.677922, 39.184953, self.date_time), CdsBusPosition(51.677922, 39.184953, self.date_time), CdsBusPosition(51.680843, 39.184798, self.date_time)] result = self.cds.get_closest_bus_stop_checked("90", positions) self.assertTrue(result.NUMBER_ == 40) self.assertTrue(result.NAME_ == 'Проспект Труда (Московский проспект из центра)')