service.py

changeset 98
c07a77c8a070
parent 94
e27c18f080d1
child 99
0726eb9bc9d1
--- a/service.py	Tue May 01 13:24:33 2018 +0300
+++ b/service.py	Fri May 04 21:32:16 2018 +0300
@@ -161,11 +161,11 @@
 	entries = [trip.from_place]
 	old_places = None
 	starting_halt = None
-	while True:
+	while len(entries) < 3:
 		remaining_length = trip.length
 		if starting_halt:
 			remaining_length -= starting_halt.traveled_distance
-		places = reduce_schedule(trip.concise_schedule(starting_stop = starting_halt), trip_length = remaining_length, format = 'medium')
+		places = reduce_schedule(trip.concise_schedule(starting_stop = starting_halt), trip_length = remaining_length, format = 'short')
 		new_places = set(places) - set(entries)
 		if not new_places or places == old_places:
 			break
@@ -769,20 +769,27 @@
 @app.route('/route/<name>')
 def route_page(name):
 	from buses import routes
+	from collections import defaultdict
+	from busroute import greatly_simplify_name
 	route = routes[name.upper()]
-	schedule = []
+	schedules = defaultdict(list)
 	for trip in route.trips:
-		if trip.is_served_at(today()) and datetime.combine(today(), time()) + trip.schedule[-1].arrival_time < now():
-			schedule.append({
+		if trip.is_served_at(today()):
+			schedules[trip.schedule[0].stop].append({
 				'name': trip.reference,
 				'from': trip.from_place,
 				'to': trip.to_place,
+				'description': ' - '.join(
+					greatly_simplify_name(place)
+					for place in trip_description(trip)
+				),
+				'gone': datetime.combine(today(), time()) + trip.schedule[-1].arrival_time < now(),
 				'time': time_representation(datetime.combine(today(), time()) + trip.schedule[0].departure_time),
 			})
 	return render_template('route.html',
 		name = route.reference + ' ' + route.description,
 		tr = tr,
-		schedule = schedule,
+		schedules = schedules,
 	)
 
 @app.route('/interesting')

mercurial