service.py

changeset 55
0f1d046b3f78
parent 53
1c934953c3e6
child 61
0c9b09f694f3
equal deleted inserted replaced
54:0b1e263674e8 55:0f1d046b3f78
8 from misc import * 8 from misc import *
9 from busroute import reduce_schedule 9 from busroute import reduce_schedule
10 import buses 10 import buses
11 11
12 app = Flask(__name__) 12 app = Flask(__name__)
13 suffix_regions = {'naantalin pikatie', 'helsingin valtatie'}
13 14
14 # Varmista ettei järjestelmän kieliasetukset sotke muotoiluja 15 # Varmista ettei järjestelmän kieliasetukset sotke muotoiluja
15 def reset_locale(): 16 def reset_locale():
16 locale.setlocale(locale.LC_ALL, locale.getdefaultlocale()) 17 locale.setlocale(locale.LC_ALL, locale.getdefaultlocale())
17 18
63 def sign(schedule_entry): 64 def sign(schedule_entry):
64 from math import ceil 65 from math import ceil
65 trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance 66 trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance
66 sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length) 67 sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length)
67 if sign: 68 if sign:
68 sign = [tr(place, 'paikat') for place in sign] 69 sign_representation = ' - '.join(tr(place, 'paikat') for place in sign if place not in suffix_regions)
69 sign_representation = ' - '.join(sign) 70 sign_representation += ''.join(' ' + tr(place, 'suffix-places') for place in sign if place in suffix_regions)
70 #if len(sign_representation) > 25: 71 #if len(sign_representation) > 25:
71 # k = ceil(len(sign) / 2) 72 # k = ceil(len(sign) / 2)
72 # sign_representation = ' - '.join(sign[:k]) + '\n' + ' - '.join(sign[k:]) 73 # sign_representation = ' - '.join(sign[:k]) + '\n' + ' - '.join(sign[k:])
73 return sign_representation 74 return sign_representation
74 else: 75 else:

mercurial