159 |
159 |
160 def trip_description(trip): |
160 def trip_description(trip): |
161 entries = [trip.from_place] |
161 entries = [trip.from_place] |
162 old_places = None |
162 old_places = None |
163 starting_halt = None |
163 starting_halt = None |
164 while True: |
164 while len(entries) < 3: |
165 remaining_length = trip.length |
165 remaining_length = trip.length |
166 if starting_halt: |
166 if starting_halt: |
167 remaining_length -= starting_halt.traveled_distance |
167 remaining_length -= starting_halt.traveled_distance |
168 places = reduce_schedule(trip.concise_schedule(starting_stop = starting_halt), trip_length = remaining_length, format = 'medium') |
168 places = reduce_schedule(trip.concise_schedule(starting_stop = starting_halt), trip_length = remaining_length, format = 'short') |
169 new_places = set(places) - set(entries) |
169 new_places = set(places) - set(entries) |
170 if not new_places or places == old_places: |
170 if not new_places or places == old_places: |
171 break |
171 break |
172 for place in places: |
172 for place in places: |
173 if place in new_places: |
173 if place in new_places: |
767 ) |
767 ) |
768 |
768 |
769 @app.route('/route/<name>') |
769 @app.route('/route/<name>') |
770 def route_page(name): |
770 def route_page(name): |
771 from buses import routes |
771 from buses import routes |
|
772 from collections import defaultdict |
|
773 from busroute import greatly_simplify_name |
772 route = routes[name.upper()] |
774 route = routes[name.upper()] |
773 schedule = [] |
775 schedules = defaultdict(list) |
774 for trip in route.trips: |
776 for trip in route.trips: |
775 if trip.is_served_at(today()) and datetime.combine(today(), time()) + trip.schedule[-1].arrival_time < now(): |
777 if trip.is_served_at(today()): |
776 schedule.append({ |
778 schedules[trip.schedule[0].stop].append({ |
777 'name': trip.reference, |
779 'name': trip.reference, |
778 'from': trip.from_place, |
780 'from': trip.from_place, |
779 'to': trip.to_place, |
781 'to': trip.to_place, |
|
782 'description': ' - '.join( |
|
783 greatly_simplify_name(place) |
|
784 for place in trip_description(trip) |
|
785 ), |
|
786 'gone': datetime.combine(today(), time()) + trip.schedule[-1].arrival_time < now(), |
780 'time': time_representation(datetime.combine(today(), time()) + trip.schedule[0].departure_time), |
787 'time': time_representation(datetime.combine(today(), time()) + trip.schedule[0].departure_time), |
781 }) |
788 }) |
782 return render_template('route.html', |
789 return render_template('route.html', |
783 name = route.reference + ' ' + route.description, |
790 name = route.reference + ' ' + route.description, |
784 tr = tr, |
791 tr = tr, |
785 schedule = schedule, |
792 schedules = schedules, |
786 ) |
793 ) |
787 |
794 |
788 @app.route('/interesting') |
795 @app.route('/interesting') |
789 def interesting(): |
796 def interesting(): |
790 from buses import all_trips, services_for_day |
797 from buses import all_trips, services_for_day |