27 try: |
27 try: |
28 return self.service in services_for_day[day] |
28 return self.service in services_for_day[day] |
29 except KeyError: |
29 except KeyError: |
30 return False |
30 return False |
31 def concise_schedule(self, starting_stop = None): |
31 def concise_schedule(self, starting_stop = None): |
|
32 if starting_stop and starting_stop in self.schedule: |
|
33 schedule = copy(self.schedule) |
|
34 schedule = schedule[schedule.index(starting_stop):] |
|
35 else: |
|
36 schedule = self.schedule |
32 if profile['regions']['use-regions']: |
37 if profile['regions']['use-regions']: |
33 if starting_stop and starting_stop in self.schedule: |
|
34 schedule = copy(self.schedule) |
|
35 schedule = schedule[schedule.index(starting_stop):] |
|
36 else: |
|
37 schedule = self.schedule |
|
38 used_areas = set() |
38 used_areas = set() |
39 result = [] |
39 result = [] |
40 for halt in schedule: |
40 for halt in schedule: |
41 stop = halt.stop |
41 stop = halt.stop |
42 if stop.region and stop.region not in used_areas: |
42 if stop.region and stop.region not in used_areas: |
43 used_areas.add(stop.region) |
43 used_areas.add(stop.region) |
44 result.append(stop.region) |
44 result.append(stop.region) |
45 return result |
45 return result |
46 else: |
46 else: |
47 return [halt.stop.name for halt in self.schedule] |
47 return [halt.stop.name for halt in schedule] |
48 |
48 |
49 class BusRoute: |
49 class BusRoute: |
50 def __init__(self, entry): |
50 def __init__(self, entry): |
51 self.id = entry['route_id'] |
51 self.id = entry['route_id'] |
52 self.reference = entry['route_short_name'] |
52 self.reference = entry['route_short_name'] |
476 route.description = simplify_name(most_common_route[0]) + ' - ' + simplify_name(most_common_route[-1]) |
476 route.description = simplify_name(most_common_route[0]) + ' - ' + simplify_name(most_common_route[-1]) |
477 except: |
477 except: |
478 route.description = '' |
478 route.description = '' |
479 route.trips = sorted(route.trips, key = lambda trip: trip.schedule and trip.schedule[0].departure_time or timedelta()) |
479 route.trips = sorted(route.trips, key = lambda trip: trip.schedule and trip.schedule[0].departure_time or timedelta()) |
480 |
480 |
481 # Fölin datassa on jotain tosi kummaa. Ilmeisesti ajovuoron viimeisen pysähdyksen saapumisaika on ihan täysin |
481 if 'compatibility' in profile and profile['compatibility'].get('fix-destination-times', False): |
482 # väärin. Arvaan että se on seuraavan lähdön aika, mutta joka tapauksessa se on väärin. |
482 # Fölin datassa on jotain tosi kummaa. Ilmeisesti ajovuoron viimeisen pysähdyksen saapumisaika on ihan täysin |
483 # Arvataan mikä se todellinen saapumisaika on. Se ei voi mennä kauhean paljon pahemmin vikaan kuin alkuperäinen |
483 # väärin. Arvaan että se on seuraavan lähdön aika, mutta joka tapauksessa se on väärin. |
484 # väärin oleva data. |
484 # Arvataan mikä se todellinen saapumisaika on. Se ei voi mennä kauhean paljon pahemmin vikaan kuin alkuperäinen |
485 for trip in all_trips.values(): |
485 # väärin oleva data. |
486 if len(trip.schedule) >= 2: |
486 for trip in all_trips.values(): |
487 bus_speed_coefficient = 750 # metriä minuutissa |
487 if len(trip.schedule) >= 2: |
488 last_leg_distance = trip.schedule[-1].traveled_distance - trip.schedule[-2].traveled_distance |
488 bus_speed_coefficient = 750 # metriä minuutissa |
489 trip.schedule[-1].arrival_time = trip.schedule[-2].departure_time + timedelta(minutes = last_leg_distance / bus_speed_coefficient) |
489 last_leg_distance = trip.schedule[-1].traveled_distance - trip.schedule[-2].traveled_distance |
|
490 trip.schedule[-1].arrival_time = trip.schedule[-2].departure_time + timedelta(minutes = last_leg_distance / bus_speed_coefficient) |
490 |
491 |
491 global trips_by_vehicle_info |
492 global trips_by_vehicle_info |
492 trips_by_vehicle_info = {} |
493 trips_by_vehicle_info = {} |
493 for trip in all_trips.values(): |
494 for trip in all_trips.values(): |
494 trips_by_vehicle_info[(trip.block_id, trip.schedule[0].arrival_time)] = trip |
495 trips_by_vehicle_info[(trip.block_id, trip.schedule[0].arrival_time)] = trip |