# HG changeset patch # User Teemu Piippo # Date 1498058674 -10800 # Node ID f8950428594526dd05ee623e013b6a47725296a4 # Parent 69cc75506d4fa2547908c8da23be3bc4c54652a5 Lisää aluejuttuja diff -r 69cc75506d4f -r f89504285945 busroute.py --- a/busroute.py Tue Jun 20 10:32:50 2017 +0300 +++ b/busroute.py Wed Jun 21 18:24:34 2017 +0300 @@ -1,53 +1,42 @@ #!/usr/bin/env python3 + +replacements = { + "Ylioppilaskylä-Itä": "Ylioppilaskylä", + "Ylioppilaskylä-Länsi": "Ylioppilaskylä", + "Caribia": "Ylioppilaskylä", + "Jokila": "Lieto", + "Piispala": "Lieto", + 'Saaro': 'Ruissalo', + 'Silvola': 'Vahto', + 'Hemmola': 'Vahto', + 'Paasniittu': 'Ruskon keskusta', + 'Kahari': 'Ruskon keskusta', + 'Kemiö': 'Kemiönsaari', + 'Kasnäs': 'Kemiönsaari', +} + +# nimiä joista voidaan joustaa tarvittaessa +abbreviations = { + 'Raision keskusta': 'Raisio', + 'Ruskon keskusta': 'Rusko', + 'Naantalin keskusta': 'Naantali', + 'Kaarinan keskusta': 'Kaarina', + 'Kauppakeskus Mylly': 'Mylly', +} + +def simplify_name(name): + name = replacements.get(name, name) + name = abbreviations.get(name, name) + return name + def reduce_schedule(reitti, trip_length, whole = False): length = ((trip_length / 600) + len(reitti)) / 2 - def abstract_sign(sign): - abstractions = { - 'Moikoinen': 'Hirvensalo', - 'Maanpää': 'Hirvensalo', - 'Papinsaari': 'Hirvensalo', - 'Häppilä': 'Hirvensalo', - 'Friskala': 'Hirvensalo', - 'Kukola': 'Hirvensalo', - 'Oriniemi': 'Hirvensalo', - 'Haarla': 'Hirvensalo', - 'Lauttasaari': 'Hirvensalo', - 'Pikisaari': 'Hirvensalo', - 'Pernon telakka': 'Perno', - } - try: - start = sign.index('Kauppatori') - except ValueError: - return sign - result = [] - for i, place in enumerate(sign): - if i >= start: - abstract_place = abstractions.get(place, place) - if abstract_place not in result: - result.append(abstract_place) - else: - result.append(place) - return result if not reitti: return '' eksoalueet = { 'Turku', 'Naantali', 'Lieto', 'Aura', 'Kaarina', 'Pargas', 'Marttila', 'Somero', 'Koski Tl', 'Tarvasjoki', 'Kaivopuisto', } - replacements = { - "Ylioppilaskylä-Itä": "Ylioppilaskylä", - "Ylioppilaskylä-Länsi": "Ylioppilaskylä", - "Caribia": "Ylioppilaskylä", - "Jokila": "Lieto", - "Piispala": "Lieto", - 'Saaro': 'Ruissalo', - 'Silvola': 'Vahto', - 'Hemmola': 'Vahto', - 'Paasniittu': 'Ruskon keskusta', - 'Kahari': 'Ruskon keskusta', - 'Kemiö': 'Kemiönsaari', - 'Kasnäs': 'Kemiönsaari', - } have_already = set() i = 0 while i < len(reitti): @@ -91,7 +80,7 @@ 'Ilmarinen': 50, 'Vahto': 50, 'Ruskon keskusta': 200, - 'Oriketo': 30, + 'Oriketo': 50, 'Harittu': 40, 'Jäkärlä': 50, 'Paattinen': 100, @@ -101,7 +90,7 @@ 'Piikkiö': 100, 'Paimio': 100, 'Pargas': 50, - 'Yli-Maaria': 50, + 'Yli-Maaria': 70, 'Saramäki': 50, 'Tarvasjoki': 100, 'Marttila': 100, @@ -124,15 +113,6 @@ if 'Kauppatori' not in reitti: priorities['Länsikeskus'] = priorities['Skanssi'] = priorities['Kauppatori'] - # nimiä joista voidaan joustaa tarvittaessa - abbreviations = { - 'Raision keskusta': 'Raisio', - 'Ruskon keskusta': 'Rusko', - 'Naantalin keskusta': 'Naantali', - 'Kaarinan keskusta': 'Kaarina', - 'Kauppakeskus Mylly': 'Mylly', - } - from_place = reitti[0] destination = reitti[-1] reitti_arvot = {} @@ -159,7 +139,7 @@ weights = weights[:3] # jos kolmas kylttiarvo ei ole tarpeeksi merkittävä suhteessa reitin pituuteen niin otetaan se pois try: - if weights[2][0] != destination and weights[2][1] < (1000 / length ** 1.15): + if weights[2][0] != destination and weights[2][1] < (1200 / length ** 0.9): del weights[2] except IndexError: pass @@ -172,7 +152,6 @@ weights = sorted(weights, key = lambda paino: paino[2]) # muodostetaan sign.. sign = [paino[0] for paino in weights] - #sign = abstract_sign(sign) # supista nimet jos mahdollista def finalise(sign, abbreviation_level = 0): if abbreviation_level > 0: diff -r 69cc75506d4f -r f89504285945 compute-regions.py --- a/compute-regions.py Tue Jun 20 10:32:50 2017 +0300 +++ b/compute-regions.py Wed Jun 21 18:24:34 2017 +0300 @@ -12,10 +12,10 @@ bus_stops = {} with open('gtfs/stops.txt') as file: - for rivi in lue_csv(file): - sijainti = Sijainti(float(rivi['stop_lat']), float(rivi['stop_lon'])) - tunniste = rivi['stop_id'] - bus_stops[tunniste] = sijainti + for row in read_csv(file): + location = Sijainti(float(row['stop_lat']), float(row['stop_lon'])) + reference = row['stop_id'] + bus_stops[reference] = location district_shapes = [] for polygon in data[1].splitlines(): diff -r 69cc75506d4f -r f89504285945 region-representatives.json --- a/region-representatives.json Tue Jun 20 10:32:50 2017 +0300 +++ b/region-representatives.json Wed Jun 21 18:24:34 2017 +0300 @@ -7,6 +7,7 @@ "Tuorla": "6149", "Raadelma": "6153", "Sipilänmäki": "6227", + "Piispanlähde": "6015", "Paimio": "6619", "Paimion sairaala": "6664", @@ -88,7 +89,7 @@ "Kaivola": "3229", "Kakskerta": "1764", "Kastu": "627", - "Katariina": "1708", + "Katariina": "516", "Kauppatori": "T1", "Kerttuli": "867", "Kultaranta": "3027", diff -r 69cc75506d4f -r f89504285945 regions.gmp --- a/regions.gmp Tue Jun 20 10:32:50 2017 +0300 +++ b/regions.gmp Wed Jun 21 18:24:34 2017 +0300 @@ -1,13 +1,13 @@ -roadmap^60.47037672221607, 22.021348696270596^16@undefined^#FF0000,5,1,#ff8800,0.4^^60.39482,22.2577~60.40037,22.27521~60.39147,22.28456~60.38851,22.27179 +roadmap^60.407187649046506, 22.331562262097012^16@undefined^#FF0000,5,1,#ff8800,0.4^^60.39482,22.2577~60.40037,22.27521~60.39147,22.28456~60.38851,22.27179 polygon^#FF0000,5,1,#ff8800,0.4^^60.3977,22.24465~60.40772,22.24046~60.40792,22.26057~60.40076,22.27409~60.3952,22.25642 polygon^#FF0000,5,1,#ff8800,0.4^^60.3977,22.22706~60.38719,22.23676~60.38341,22.22466~60.38518,22.21205~60.39359,22.20706~60.39816,22.21341 -polygon^#FF0000,5,1,#ff8800,0.4^^60.39868,22.21599~60.39804,22.22852~60.38876,22.23916~60.38952,22.24843~60.39329,22.25135~60.40217,22.23474~60.4019,22.21689 -polygon^#FF0000,5,1,#ff8800,0.4^^60.38871,22.16432~60.39236,22.18483~60.39972,22.188~60.40171,22.1823~60.39919,22.15413~60.39151,22.15633 -polygon^#FF0000,5,1,#ff8800,0.4^^60.42123,22.17264~60.41472,22.15422~60.40622,22.14277~60.40003,22.15599~60.40577,22.17143~60.41357,22.18174 -polygon^#FF0000,5,1,#ff8800,0.4^^60.43275,22.20869~60.4239,22.21632~60.41889,22.19831~60.42495,22.19216~60.43033,22.19648 -polygon^#FF0000,5,1,#ff8800,0.4^^60.42148,22.17333~60.42584,22.18964~60.41902,22.1971~60.41534,22.18056 -polygon^#FF0000,5,1,#ff8800,0.4^^60.49702,22.21496~60.49936,22.22028~60.50048,22.23744~60.49676,22.2392~60.49373,22.23435~60.49306,22.23554~60.49178,22.23402~60.48872,22.22903~60.48729,22.2221~60.49085,22.21505 -polygon^#FF0000,5,1,#ff8800,0.4^^60.45775,22.29049~60.4599,22.29787~60.45951,22.29945~60.45688,22.3026~60.45537,22.29751~60.45501,22.29585~60.45465,22.29285~60.45619,22.29141 +undefined^#FF0000,5,1,#ff8800,0.4^^60.39868,22.21599~60.39804,22.22852~60.38876,22.23916~60.38952,22.24843~60.39329,22.25135~60.40217,22.23474~60.4019,22.21689 +undefined^#FF0000,5,1,#ff8800,0.4^^60.38871,22.16432~60.39236,22.18483~60.39972,22.188~60.40171,22.1823~60.39919,22.15413~60.39151,22.15633 +undefined^#FF0000,5,1,#ff8800,0.4^^60.42123,22.17264~60.41472,22.15422~60.40622,22.14277~60.40003,22.15599~60.40577,22.17143~60.41357,22.18174 +undefined^#FF0000,5,1,#ff8800,0.4^^60.43275,22.20869~60.4239,22.21632~60.41889,22.19831~60.42495,22.19216~60.43033,22.19648 +undefined^#FF0000,5,1,#ff8800,0.4^^60.42148,22.17333~60.42584,22.18964~60.41902,22.1971~60.41534,22.18056 +undefined^#FF0000,5,1,#ff8800,0.4^^60.49702,22.21496~60.49936,22.22028~60.50048,22.23744~60.49676,22.2392~60.49373,22.23435~60.49306,22.23554~60.49178,22.23402~60.48872,22.22903~60.48729,22.2221~60.49085,22.21505 +undefined^#FF0000,5,1,#ff8800,0.4^^60.45775,22.29049~60.4599,22.29787~60.45951,22.29945~60.45688,22.3026~60.45537,22.29751~60.45501,22.29585~60.45465,22.29285~60.45619,22.29141 undefined^#FF0000,5,1,#ff8800,0.4^^60.45331,22.2865~60.45033,22.29068~60.45113,22.29322~60.45198,22.29413~60.45225,22.29741~60.45399,22.29853~60.45529,22.2975~60.45495,22.29585~60.45446,22.2915~60.45386,22.28832~60.45369,22.28748 undefined^#FF0000,5,1,#ff8800,0.4^^60.4445,22.25538~60.44359,22.25256~60.44121,22.24824~60.43617,22.25517~60.43897,22.26358 undefined^#FF0000,5,1,#ff8800,0.4^^60.4537,22.25043~60.45203,22.25283~60.45345,22.25685~60.45493,22.25432 @@ -69,7 +69,6 @@ undefined^#FF0000,5,1,#ff8800,0.4^^60.42961,22.26392~60.4343,22.28456~60.43499,22.29225~60.43245,22.29564~60.42894,22.29349~60.42506,22.27929~60.42531,22.26699 undefined^#FF0000,5,1,#ff8800,0.4^^60.42521,22.26577~60.42195,22.26877~60.41579,22.26733~60.41625,22.27877~60.42052,22.2783~60.42469,22.2762 undefined^#FF0000,5,1,#ff8800,0.4^^60.42288,22.24603~60.42536,22.26349~60.4219,22.26787~60.4157,22.26641~60.41536,22.2713~60.40943,22.26612~60.41382,22.25849 -undefined^#FF0000,5,1,#ff8800,0.4^^60.40898,22.26645~60.41573,22.27229~60.4162,22.27959~60.41694,22.28892~60.41809,22.29195~60.41392,22.29396~60.40429,22.28059~60.40683,22.26871 undefined^#FF0000,5,1,#ff8800,0.4^^60.41536,22.18092~60.41875,22.19766~60.4136,22.20165~60.41187,22.18124~60.41382,22.18224 undefined^#FF0000,5,1,#ff8800,0.4^^60.41156,22.18045~60.41307,22.20002~60.40765,22.19821~60.40864,22.17655 undefined^#FF0000,5,1,#ff8800,0.4^^60.40834,22.17552~60.40773,22.19004~60.40054,22.18878~60.40212,22.18257~60.40071,22.1682~60.40567,22.17207 @@ -227,4 +226,6 @@ undefined^#FF0000,5,1,#ff8800,0.4^^60.36619,22.69037~60.35583,22.75114~60.30695,22.70246~60.32315,22.59175~60.359,22.64749 undefined^#FF0000,5,1,#ff8800,0.4^^60.46456,22.29205~60.4637,22.29341~60.46181,22.29109~60.46104,22.29223~60.45895,22.28907~60.4601,22.2872~60.46092,22.28459~60.46213,22.28363~60.46398,22.28696 undefined^#FF0000,5,1,#ff8800,0.4^^60.47333,22.01433~60.47077,22.02031~60.46786,22.01456~60.47116,22.00777 +undefined^#FF0000,5,1,#ff8800,0.4^^60.41684,22.28808~60.41429,22.28833~60.41165,22.288~60.40885,22.28525~60.40811,22.2759~60.40868,22.27027~60.41208,22.2701~60.4155,22.27276 +undefined^#FF0000,5,1,#ff8800,0.4^^60.40938,22.31293~60.40543,22.32123~60.4055,22.33379~60.40597,22.34177~60.40995,22.3419~60.41107,22.32617 @@@@@@ diff -r 69cc75506d4f -r f89504285945 service.py --- a/service.py Tue Jun 20 10:32:50 2017 +0300 +++ b/service.py Wed Jun 21 18:24:34 2017 +0300 @@ -127,19 +127,21 @@ 'stop_id': schedule_entry['stop'].stop.reference, 'stop_name': tr(schedule_entry['stop'].stop.name, 'bus_stops'), }) + stops_in_cluster = sorted( + ({ + 'id': stop.reference, + 'name': tr(stop.name, 'bus_stops'), + } for stop in cluster.stops), + key = lambda stop: (len(stop['id']), stop['id']) + ) return render_template( 'cluster.html', schedule = schedule, name = cluster.name, link_to_map = cluster.center.link_to_map, location = cluster.center, - stops_in_cluster = sorted( - ({ - 'id': stop.reference, - 'name': tr(stop.name, 'bus_stops'), - } for stop in cluster.stops), - key = lambda stop: (len(stop['id']), stop['id']) - ), + stops_in_cluster = stops_in_cluster, + amount_of_stops_in_cluster = len(stops_in_cluster), tr = tr, ) @@ -183,7 +185,26 @@ description = ' - '.join(tr(place, 'paikat') for place in sign), night = is_night_time(datetime.combine(today(), time()) + trip.schedule[-1].arrival_time), tr = tr, - length = trip.length / 1000 + length = trip.length / 1000, + ) + +@app.route('/linja/') +def route_page(name): + from buses import routes + route = routes[name.upper()] + schedule = [] + for trip in route.trips: + if trip.is_served_at(today()) and datetime.combine(today(), time()) + trip.schedule[-1].arrival_time < now(): + schedule.append({ + 'name': trip.reference, + 'from': trip.from_place, + 'to': trip.to_place, + '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, ) @app.route('/static/') diff -r 69cc75506d4f -r f89504285945 templates/cluster.html --- a/templates/cluster.html Tue Jun 20 10:32:50 2017 +0300 +++ b/templates/cluster.html Wed Jun 21 18:24:34 2017 +0300 @@ -4,6 +4,7 @@ {{name}} + {% if amount_of_stops_in_cluster >= 5 %} + {% endif %} +