--- a/service.py Sun Apr 15 13:51:39 2018 +0300 +++ b/service.py Thu Apr 19 14:44:54 2018 +0300 @@ -9,6 +9,7 @@ from misc import * from busroute import reduce_schedule +from busroute import simplify_name import buses regions = {} @@ -54,7 +55,7 @@ for key, value in region.items(): if ':' in key: name_type, language = key.split(':', 1) - if name_type.endswith('name') and language: + if (name_type.endswith('name') or name_type == 'genitive') and language: section = 'region_' + name_type if section not in self.languages[language]: self.languages[language][section] = {} @@ -84,7 +85,7 @@ trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance regions = schedule_entry['trip'].concise_schedule(schedule_entry['stop']) return [ - simplify_name(name) + name for name in reduce_schedule( regions, trip_length = trip_length, @@ -92,13 +93,32 @@ ) ] +def genitive(name): + from busroute import regions + region = regions.get(name) + if region: + return region.get('genitive:fi', simplify_name(name) + 'n') + else: + return simplify_name(name) + 'n' + +def via_fi(via): + if len(via) > 1: + return ', '.join(via[:-1]) + ' ja ' + via[-1] + else: + return via[0] + def sign(schedule_entry, format = 'medium'): sign = sign_elements(schedule_entry, format = format) if sign: + #if language_for_page() == 'fi': + # if len(sign) > 1: + # return simplify_name(sign[-1]) + ' ' + via_fi([genitive(place) for place in sign[:-1]]) + ' kautta' + # else: + # return simplify_name(sign[0]) # sign_representation = ' - '.join(tr(place, 'region_short_name') for place in sign if place not in suffix_regions) # sign_representation += ''.join(' ' + tr(place, 'suffix-places') for place in sign if place in suffix_regions) # return sign_representation - return ' - '.join(tr(place, 'region_short_name') for place in sign) + return ' - '.join(tr(simplify_name(place), 'region_short_name') for place in sign) else: return schedule_entry['trip'].schedule[-1].stop.name @@ -193,11 +213,16 @@ location = bus_stop.location, cluster = bus_stop.cluster.url_name if len(bus_stop.cluster.stops) > 1 else None, tr = tr, + typename = bus_stop.typename, ) def week_schedule(bus_stop, **kwargs): for i in range(-1, 7): - yield from bus_stop.schedule_for_day(today() + timedelta(i), **kwargs) + try: + yield from bus_stop.schedule_for_day(today() + timedelta(i), **kwargs) + except ValueError: + # went outside bounds + return def route_key(route): match = re.search(r'^([a-zA-Z]*)(\d+)(.*)$', route) @@ -500,6 +525,7 @@ 'stop_code': schedule_entry['stop'].stop.code, 'stop_name': tr(schedule_entry['stop'].stop.name, 'bus-stops', 'places'), 'imminent': imminent(schedule_entry), + 'typename': schedule_entry['stop'].stop.typename, }) stops_in_cluster = sorted( ({ @@ -610,6 +636,7 @@ tr = tr, week = week_model, description = describe(bus_stop), + typename = bus_stop.typename, ) @app.route('/trip/<trip_reference>') @@ -650,6 +677,7 @@ 'id': halt.stop.reference, 'code': halt.stop.code, 'name': tr(halt.stop.name, 'bus-stops'), + 'typename': halt.stop.typename, }) sign = trip.concise_schedule() try: