64 def sign(schedule_entry, long = False): |
67 def sign(schedule_entry, long = False): |
65 from math import ceil |
68 from math import ceil |
66 trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance |
69 trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance |
67 sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length, long = long) |
70 sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length, long = long) |
68 if sign: |
71 if sign: |
69 sign_representation = ' - '.join(tr(place, 'paikat') for place in sign if place not in suffix_regions) |
72 sign_representation = ' - '.join(tr(place, 'places') for place in sign if place not in suffix_regions) |
70 sign_representation += ''.join(' ' + tr(place, 'suffix-places') for place in sign if place in suffix_regions) |
73 sign_representation += ''.join(' ' + tr(place, 'suffix-places') for place in sign if place in suffix_regions) |
71 return sign_representation |
74 return sign_representation |
72 else: |
75 else: |
73 return schedule_entry['trip'].schedule[-1].stop.name |
76 return schedule_entry['trip'].schedule[-1].stop.name |
74 |
77 |
76 from math import ceil |
79 from math import ceil |
77 trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance |
80 trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance |
78 sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length, long = True) |
81 sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length, long = True) |
79 if sign: |
82 if sign: |
80 return { |
83 return { |
81 'destination': tr(sign[-1], 'paikat'), |
84 'destination': tr(sign[-1], 'places'), |
82 'via': [tr(place, 'paikat') for place in sign[:-1]], |
85 'via': [tr(place, 'places') for place in sign[:-1]], |
83 } |
86 } |
84 else: |
87 else: |
85 return { |
88 return { |
86 'destination': schedule_entry['trip'].schedule[-1].stop.name, |
89 'destination': schedule_entry['trip'].schedule[-1].stop.name, |
87 'via': [], |
90 'via': [], |
147 'imminent': imminent(schedule_entry), |
150 'imminent': imminent(schedule_entry), |
148 }) |
151 }) |
149 return render_template( |
152 return render_template( |
150 'stop.html', |
153 'stop.html', |
151 schedule = schedule, |
154 schedule = schedule, |
152 name = bus_stop.code + ' ' + tr(bus_stop.name, 'bus-stops'), |
155 name = bus_stop.code + ' ' + tr(bus_stop.name, 'bus-stops', 'places'), |
153 link_to_map = bus_stop.location.link_to_map, |
156 link_to_map = bus_stop.location.link_to_map, |
154 region = bus_stop.region, |
157 region = hasattr(bus_stop, 'region') and bus_stop.region or None, |
155 location = bus_stop.location, |
158 location = bus_stop.location, |
156 cluster = bus_stop.cluster.url_name if len(bus_stop.cluster.stops) > 1 else None, |
159 cluster = bus_stop.cluster.url_name if len(bus_stop.cluster.stops) > 1 else None, |
157 tr = tr, |
160 tr = tr, |
158 ) |
161 ) |
159 |
162 |
313 'sign': sign(schedule_entry), |
316 'sign': sign(schedule_entry), |
314 'trip': schedule_entry['stop'].trip.name, |
317 'trip': schedule_entry['stop'].trip.name, |
315 'night': is_night_time(schedule_entry['time']), |
318 'night': is_night_time(schedule_entry['time']), |
316 'stop_id': schedule_entry['stop'].stop.reference, |
319 'stop_id': schedule_entry['stop'].stop.reference, |
317 'stop_code': schedule_entry['stop'].stop.code, |
320 'stop_code': schedule_entry['stop'].stop.code, |
318 'stop_name': tr(schedule_entry['stop'].stop.name, 'bus-stops'), |
321 'stop_name': tr(schedule_entry['stop'].stop.name, 'bus-stops', 'places'), |
319 'imminent': imminent(schedule_entry), |
322 'imminent': imminent(schedule_entry), |
320 }) |
323 }) |
321 stops_in_cluster = sorted( |
324 stops_in_cluster = sorted( |
322 ({ |
325 ({ |
323 'id': stop.reference, |
326 'id': stop.reference, |
327 key = lambda stop: (len(stop['id']), stop['id']) |
330 key = lambda stop: (len(stop['id']), stop['id']) |
328 ) |
331 ) |
329 return render_template( |
332 return render_template( |
330 'cluster.html', |
333 'cluster.html', |
331 schedule = schedule, |
334 schedule = schedule, |
332 name = tr(cluster.name, 'paikat', 'pysäkkiryhmät', 'bus-stops'), |
335 name = tr(cluster.name, 'places', 'place-clusters', 'bus-stops'), |
333 link_to_map = cluster.center.link_to_map, |
336 link_to_map = cluster.center.link_to_map, |
334 location = cluster.center, |
337 location = cluster.center, |
335 stops_in_cluster = stops_in_cluster, |
338 stops_in_cluster = stops_in_cluster, |
336 amount_of_stops_in_cluster = len(stops_in_cluster), |
339 amount_of_stops_in_cluster = len(stops_in_cluster), |
337 tr = tr, |
340 tr = tr, |
352 stop_time = datetime.combine(today(), time()) + halt.arrival_time |
355 stop_time = datetime.combine(today(), time()) + halt.arrival_time |
353 formatted_time = time_representation(stop_time) |
356 formatted_time = time_representation(stop_time) |
354 if profile['regions']['use-regions']: |
357 if profile['regions']['use-regions']: |
355 if halt.stop.region != region and not (region and not halt.stop.region): |
358 if halt.stop.region != region and not (region and not halt.stop.region): |
356 if len(schedule) and not schedule[-1]['name']: |
359 if len(schedule) and not schedule[-1]['name']: |
357 schedule[-1]['name'] = tr(halt.stop.region or '', 'paikat') |
360 schedule[-1]['name'] = tr(halt.stop.region or '', 'places') |
358 else: |
361 else: |
359 schedule.append({ |
362 schedule.append({ |
360 'name': tr(halt.stop.region or '', 'paikat'), |
363 'name': tr(halt.stop.region or '', 'places'), |
361 'time': formatted_time, |
364 'time': formatted_time, |
362 'stops': [], |
365 'stops': [], |
363 'index': len(schedule), |
366 'index': len(schedule), |
364 }) |
367 }) |
365 region = halt.stop.region |
368 region = halt.stop.region |
366 else: |
369 else: |
367 schedule.append({ |
370 schedule.append({ |
368 'name': tr(halt.stop.name or '', 'bus-stops'), |
371 'name': tr(halt.stop.name or '', 'bus-stops', 'places'), |
369 'time': formatted_time, |
372 'time': formatted_time, |
370 'stops': [], |
373 'stops': [], |
371 'index': len(schedule), |
374 'index': len(schedule), |
372 }) |
375 }) |
373 schedule[-1]['stops'].append({ |
376 schedule[-1]['stops'].append({ |
374 'time': formatted_time, |
377 'time': formatted_time, |
375 'id': halt.stop.reference, |
378 'id': halt.stop.reference, |
376 'code': halt.stop.code, |
379 'code': halt.stop.code, |
377 'name': tr(halt.stop.name, 'bus-stops'), |
380 'name': tr(halt.stop.name, 'bus-stops', 'places'), |
378 }) |
381 }) |
379 sign = trip.concise_schedule() |
382 sign = trip.concise_schedule() |
380 try: |
383 try: |
381 sign = [simplify_name(sign[0]), simplify_name(sign[-1])] |
384 sign = [simplify_name(sign[0]), simplify_name(sign[-1])] |
382 except IndexError: |
385 except IndexError: |
383 sign = [trip.schedule[0].stop.name, trip.schedule[-1].stop.name] |
386 sign = [trip.schedule[0].stop.name, trip.schedule[-1].stop.name] |
384 return render_template('trip.html', |
387 return render_template('trip.html', |
385 schedule = schedule, |
388 schedule = schedule, |
386 trip_reference = trip_reference, |
389 trip_reference = trip_reference, |
387 route = trip.route.reference, |
390 route = trip.route.reference, |
388 description = ' - '.join(tr(place, 'paikat') for place in sign), |
391 description = ' - '.join(tr(place, 'places') for place in sign), |
389 night = is_night_time(datetime.combine(today(), time()) + trip.schedule[-1].arrival_time), |
392 night = is_night_time(datetime.combine(today(), time()) + trip.schedule[-1].arrival_time), |
390 tr = tr, |
393 tr = tr, |
391 length = trip.length / 1000, |
394 length = trip.length / 1000, |
392 ) |
395 ) |
393 |
396 |