stop_description ja muuta roinaa

Fri, 24 Nov 2017 22:41:48 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 24 Nov 2017 22:41:48 +0200
changeset 73
c56b0ef96514
parent 72
65408ed066b3
child 74
3bd33720f1e3

stop_description ja muuta roinaa

compute-regions.py file | annotate | diff | comparison | revisions
profiles/föli.ini file | annotate | diff | comparison | revisions
regions.gmp file | annotate | diff | comparison | revisions
regions.ini file | annotate | diff | comparison | revisions
service.py file | annotate | diff | comparison | revisions
--- a/compute-regions.py	Thu Oct 26 18:02:27 2017 +0300
+++ b/compute-regions.py	Fri Nov 24 22:41:48 2017 +0200
@@ -27,6 +27,8 @@
 			bus_stops[reference] = location
 
 district_shapes = []
+districts = {}
+
 for polygon in data[1].splitlines():
 	polygon = polygon.split('^')
 	coordinates = []
@@ -34,8 +36,9 @@
 		x, y = point.split(',')
 		coordinates.append(Sijainti(float(x), float(y)))
 	district_shapes.append(Monikulmio(*coordinates))
+	if polygon[0] != 'undefined':
+		districts[polygon[0]] = district_shapes[-1]
 
-districts = {}
 bus_stop_districts = {}
 
 for name, stop_id in representatives.items():
--- a/profiles/föli.ini	Thu Oct 26 18:02:27 2017 +0300
+++ b/profiles/föli.ini	Fri Nov 24 22:41:48 2017 +0200
@@ -11,7 +11,7 @@
 ihala = 150
 mylly = 200
 kuninkoja = 150
-moikoinen = 100
+moikoinen = 150
 raisio = 150
 kukola = 50
 kaistarniemi = 75
@@ -32,7 +32,7 @@
 kohmo = 80
 kupittaa = 70
 kupittaa as = 120
-kauppatori = inf
+kauppatori = 1e6
 lentoasema = 50
 runosmäki = 50
 lieto = 100
@@ -65,11 +65,11 @@
 raunistula = 50
 pääskyvuori = 100
 logomo = 100
-rymättylä = 50
+rymättylä = 100
 sauvo = 500
 kemiönsaari = 500
 suovuori = 300
-eerikvalla = 50
+erikvalla = 50
 petäsmäki = 50
 tortinmäki = 50
 aura = 100
@@ -106,6 +106,10 @@
 särkilahti = 25
 urusvuori = 25
 port arthur = 25
+brinkhall = 100
+myllykylä = 100
+harjattula = 200
+kansanpuisto = 100
 
 [replacements]
 ylioppilaskylä-itä = ylioppilaskylä
@@ -139,6 +143,7 @@
 [tr:fi:suffix-places]
 naantalin pikatie = pikatietä
 helsingin valtatie = moottoritietä
+kansanpuisto = Kansanpuistoon
 
 [tr:en:places]
 satama = Harbor
@@ -158,10 +163,10 @@
 [tr:en:suffix-places]
 naantalin pikatie = by expressway
 helsingin valtatie = by motorway
+kansanpuisto = to Kansanpuisto
 
 [tr:sv:places]
 artukainen = Artukais
-eerikvalla = Erikvalla
 haarla = Harlax
 halinen = Hallis
 härkämäki = Oxbacka
@@ -256,7 +261,10 @@
 sauvo = Sagu
 turkuhalli = Åbohallen
 naantalin pikatie = Nådendal snabbvägen
+tammivalkama = Ekvalla
+kansanpuisto = Folkparken
 
 [tr:sv:suffix-places]
 naantalin pikatie = på snabbvägen
 helsingin valtatie = på motorvägen
+kansanpuisto = till Folkparken
--- a/regions.gmp	Thu Oct 26 18:02:27 2017 +0300
+++ b/regions.gmp	Fri Nov 24 22:41:48 2017 +0200
@@ -1,8 +1,8 @@
-roadmap^60.49188497444462, 22.100055437603604^14@undefined^#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
+roadmap^60.43146535467294, 22.155968766728055^14@undefined^#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
+Haarla^#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
+Friskala^#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
+Oriniemi^#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
+Maanpää^#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
@@ -11,9 +11,7 @@
 undefined^#FF0000,5,1,#ff8800,0.4^^60.4537,22.25043~60.45203,22.25283~60.45345,22.25685~60.45493,22.25432
 undefined^#FF0000,5,1,#ff8800,0.4^^60.45224,22.29757~60.4499,22.32448~60.4569,22.32432~60.4621,22.31703~60.45992,22.29862~60.45961,22.29964~60.45684,22.30304~60.45528,22.29775~60.45402,22.29882
 undefined^#FF0000,5,1,#ff8800,0.4^^60.45206,22.29738~60.45137,22.2971~60.44687,22.30439~60.44232,22.3131~60.43895,22.31757~60.44625,22.3267~60.44913,22.32902
-undefined^#FF0000,5,1,#ff8800,0.4^^60.35447,22.12646~60.34122,22.13676~60.33714,22.17865~60.35634,22.30671~60.36475,22.31056~60.38221,22.2982~60.37208,22.22194~60.3631,22.16082
-undefined^#FF0000,5,1,#ff8800,0.4^^60.36483,22.11222~60.35498,22.12595~60.34539,22.09816~60.35061,22.08758
-undefined^#FF0000,5,1,#ff8800,0.4^^60.35557,22.12732~60.36614,22.11211~60.37617,22.11563~60.38197,22.13505~60.38392,22.1608~60.38367,22.21058~60.38265,22.23049~60.37467,22.23427~60.36377,22.15899
+Erikvalla^#FF0000,5,1,#ff8800,0.4^^60.36483,22.11222~60.35498,22.12595~60.34539,22.09816~60.35061,22.08758
 undefined^#FF0000,5,1,#ff8800,0.4^^60.45658,22.33769~60.46067,22.33863~60.46369,22.34413~60.46361,22.35091~60.46069,22.35683~60.45802,22.35761~60.45549,22.34853~60.45532,22.34116
 undefined^#FF0000,5,1,#ff8800,0.4^^60.4623,22.31774~60.46502,22.33262~60.46094,22.33791~60.4565,22.33709~60.45315,22.33619~60.45112,22.33105~60.45135,22.32557~60.45712,22.32505
 undefined^#FF0000,5,1,#ff8800,0.4^^60.42408,22.21672~60.43288,22.20943~60.43357,22.21448~60.43179,22.225~60.42963,22.22912~60.42589,22.23131~60.42324,22.2362~60.42237,22.23158~60.41794,22.22753
@@ -34,7 +32,7 @@
 undefined^#FF0000,5,1,#ff8800,0.4^^60.45066,22.24616~60.44458,22.25495~60.44369,22.25247~60.43624,22.23858~60.4444,22.23654~60.44471,22.23537~60.4478,22.2407
 undefined^#FF0000,5,1,#ff8800,0.4^^60.48504,22.23244~60.48575,22.24697~60.49033,22.24506~60.49114,22.24283~60.49107,22.24098~60.49086,22.24005~60.49023,22.23753~60.49002,22.23558~60.48981,22.23345~60.491,22.23294~60.48865,22.22914~60.48714,22.22952~60.48611,22.23257
 undefined^#FF0000,5,1,#ff8800,0.4^^60.48987,22.23356~60.49103,22.23309~60.49175,22.23427~60.49312,22.23579~60.49373,22.2346~60.49673,22.23947~60.49728,22.2393~60.49751,22.24406~60.49696,22.24764~60.49359,22.24392~60.49128,22.24289~60.49117,22.24067~60.49032,22.23748
-undefined^#FF0000,5,1,#ff8800,0.4^^60.42207,22.10793~60.43171,22.10878~60.43629,22.11982~60.43677,22.12916~60.43279,22.1408~60.43745,22.15093~60.4402,22.1662~60.44177,22.18809~60.43334,22.19685~60.42639,22.18912~60.42142,22.17058~60.42463,22.15582~60.42085,22.14449
+Ruissalo^#FF0000,5,1,#ff8800,0.4^^60.42207,22.10793~60.43171,22.10878~60.43629,22.11982~60.43677,22.12916~60.43279,22.1408~60.43745,22.15093~60.43702,22.16208~60.43487,22.16517~60.42944,22.16861~60.4291,22.16723~60.4282,22.16354~60.42463,22.15582~60.42085,22.14449
 undefined^#FF0000,5,1,#ff8800,0.4^^60.43186,22.10827~60.4223,22.10735~60.42254,22.10205~60.41546,22.0972~60.41587,22.09045~60.42412,22.0846~60.42765,22.08646
 undefined^#FF0000,5,1,#ff8800,0.4^^60.44991,22.24738~60.45435,22.25976~60.448,22.2675~60.4447,22.25516
 undefined^#FF0000,5,1,#ff8800,0.4^^60.45217,22.26268~60.45381,22.26794~60.45108,22.27178~60.4493,22.26616
@@ -63,10 +61,10 @@
 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
-undefined^#FF0000,5,1,#ff8800,0.4^^60.38922,22.16942~60.39234,22.18616~60.38439,22.1926~60.38445,22.16751
-undefined^#FF0000,5,1,#ff8800,0.4^^60.39291,22.18552~60.39257,22.19483~60.39348,22.20569~60.39844,22.21229~60.3995,22.18893
+Tammisto^#FF0000,5,1,#ff8800,0.4^^60.38922,22.16942~60.39234,22.18616~60.38439,22.1926~60.38445,22.16751
+Majamäki^#FF0000,5,1,#ff8800,0.4^^60.39291,22.18552~60.39257,22.19483~60.39348,22.20569~60.39844,22.21229~60.3995,22.18893
 undefined^#FF0000,5,1,#ff8800,0.4^^60.40769,22.19037~60.40056,22.18946~60.40044,22.19775~60.40256,22.19895~60.40733,22.19792
-undefined^#FF0000,5,1,#ff8800,0.4^^60.41343,22.21989~60.40506,22.22324~60.40398,22.20494~60.4127,22.2044
+Toijainen^#FF0000,5,1,#ff8800,0.4^^60.41343,22.21989~60.40506,22.22324~60.40398,22.20494~60.4127,22.2044
 undefined^#FF0000,5,1,#ff8800,0.4^^60.44634,22.22058~60.44405,22.22474~60.44395,22.23328~60.44604,22.23667~60.44797,22.23457~60.44768,22.22393
 undefined^#FF0000,5,1,#ff8800,0.4^^60.44594,22.19951~60.4478,22.19877~60.44824,22.21556~60.44775,22.22051~60.44611,22.22006~60.44378,22.22384~60.44355,22.23234~60.44448,22.23491~60.44422,22.23603~60.43618,22.23813~60.43201,22.22567~60.43402,22.21505~60.43541,22.20654~60.44264,22.2068
 undefined^#FF0000,5,1,#ff8800,0.4^^60.44896,22.2171~60.44767,22.22204~60.44837,22.22394~60.44827,22.23472~60.4463,22.2371~60.45119,22.24507~60.45133,22.24013~60.45296,22.23209~60.45315,22.22472
@@ -154,7 +152,7 @@
 undefined^#FF0000,5,1,#ff8800,0.4^^60.35167,22.34817~60.34309,22.34877~60.34296,22.37713~60.34534,22.39574~60.35086,22.39134~60.35266,22.37124~60.35292,22.35754
 undefined^#FF0000,5,1,#ff8800,0.4^^60.32516,22.33495~60.3187,22.36885~60.32113,22.38284~60.32541,22.38764~60.33406,22.35426~60.33033,22.34112
 undefined^#FF0000,5,1,#ff8800,0.4^^60.36324,22.34812~60.35388,22.34658~60.35574,22.37044~60.36562,22.36825
-undefined^#FF0000,5,1,#ff8800,0.4^^60.41358,22.22011~60.40495,22.22367~60.40406,22.2398~60.40792,22.23734~60.41234,22.23324~60.41464,22.22954~60.41648,22.22409
+Kukola^#FF0000,5,1,#ff8800,0.4^^60.41358,22.22011~60.40495,22.22367~60.40406,22.2398~60.40792,22.23734~60.41234,22.23324~60.41464,22.22954~60.41648,22.22409
 undefined^#FF0000,5,1,#ff8800,0.4^^60.50787,22.44893~60.50853,22.45912~60.50819,22.46699~60.50497,22.46741~60.50317,22.4648~60.50189,22.45962~60.50153,22.45521~60.50215,22.45004~60.50255,22.44831~60.50485,22.44773
 undefined^#FF0000,5,1,#ff8800,0.4^^60.42716,22.51605~60.42152,22.51764~60.42273,22.53824~60.42689,22.53533~60.42836,22.52668
 undefined^#FF0000,5,1,#ff8800,0.4^^60.42815,22.51498~60.42365,22.51652~60.42286,22.50405~60.42545,22.50265~60.42893,22.50496~60.4312,22.51206
@@ -192,7 +190,7 @@
 undefined^#FF0000,5,1,#ff8800,0.4^^60.46405,22.09132~60.4627,22.11106~60.47455,22.11768~60.4849,22.11197~60.48188,22.09514~60.47191,22.09863
 undefined^#FF0000,5,1,#ff8800,0.4^^60.46224,22.29508~60.46122,22.29679~60.4604,22.29517~60.46062,22.29415~60.46164,22.29403~60.46233,22.29434
 undefined^#FF0000,5,1,#ff8800,0.4^^60.6386,23.48019~60.64036,23.54104~60.61247,23.55108~60.60559,23.51006~60.61444,23.45856~60.62842,23.45907
-undefined^#FF0000,5,1,#ff8800,0.4^^60.4222,22.23671~60.41807,22.23096~60.41564,22.23169~60.4083,22.23886~60.40847,22.26201~60.42222,22.24487
+Moikoinen^#FF0000,5,1,#ff8800,0.4^^60.4222,22.23671~60.41807,22.23096~60.41564,22.23169~60.4083,22.23886~60.40847,22.26201~60.42222,22.24487
 undefined^#FF0000,5,1,#ff8800,0.4^^60.46904,22.2353~60.46183,22.25873~60.45824,22.24483~60.46736,22.23274
 undefined^#FF0000,5,1,#ff8800,0.4^^60.46354,22.21109~60.46532,22.23178~60.45828,22.24375~60.45807,22.22897~60.46028,22.21318
 undefined^#FF0000,5,1,#ff8800,0.4^^60.48002,22.29883~60.47485,22.29218~60.47239,22.29136~60.47177,22.30714~60.47418,22.31576~60.47621,22.31538~60.48083,22.3011
@@ -254,4 +252,18 @@
 undefined^#FF0000,5,1,#ff8800,0.4^^60.54736,22.38027~60.54874,22.392~60.548,22.40833~60.53136,22.40816~60.53035,22.38348~60.53702,22.37821~60.53801,22.38301
 undefined^#FF0000,5,1,#ff8800,0.4^^60.49674,22.09445~60.48685,22.09827~60.4864,22.10774~60.48819,22.11851~60.4976,22.11124~60.49871,22.1029
 undefined^#FF0000,5,1,#ff8800,0.4^^60.48594,22.07831~60.49205,22.08089~60.49691,22.08612~60.4966,22.09404~60.4867,22.09783~60.48591,22.09568~60.48578,22.09098
-@@@@@@
+Brinkhall^#FF0000,5,1,#ff8800,0.4^^60.37361,22.24577~60.36725,22.25298~60.36402,22.23474~60.358,22.21557~60.36972,22.20759~60.37255,22.22792
+Armonlaakso^#FF0000,5,1,#ff8800,0.4^^60.3765,22.26126~60.36863,22.26452~60.36882,22.28371~60.37694,22.28319
+Harjattula^#FF0000,5,1,#ff8800,0.4^^60.36886,22.28379~60.37707,22.28371~60.3772,22.29585~60.37223,22.30456~60.36846,22.30559
+Laalahti^#FF0000,5,1,#ff8800,0.4^^60.36296,22.28976~60.35483,22.29624~60.35212,22.27681~60.36107,22.2713
+Myllykylä^#FF0000,5,1,#ff8800,0.4^^60.36092,22.23165~60.34942,22.24148~60.34173,22.20708~60.3533,22.19969
+Hylkilahti^#FF0000,5,1,#ff8800,0.4^^60.36048,22.16539~60.36279,22.1841~60.35515,22.18886~60.35268,22.16932
+Samppa^#FF0000,5,1,#ff8800,0.4^^60.37781,22.1226~60.3714,22.13831~60.36179,22.12455~60.36735,22.1126
+Artukka^#FF0000,5,1,#ff8800,0.4^^60.37968,22.12423~60.37221,22.13994~60.37955,22.15932~60.38371,22.15342
+Uusikylä^#FF0000,5,1,#ff8800,0.4^^60.37427,22.18337~60.37548,22.19766~60.38304,22.1956~60.38242,22.18103
+Tammivalkama^#FF0000,5,1,#ff8800,0.4^^60.38364,22.21929~60.38265,22.23041~60.37697,22.22736~60.37883,22.21558
+Kakskerran koulu^#FF0000,5,1,#ff8800,0.4^^60.36961,22.17073~60.37027,22.17869~60.36624,22.18013~60.36522,22.17186
+Laukkavuori^#FF0000,5,1,#ff8800,0.4^^60.4453,22.32688~60.44323,22.33243~60.43775,22.33392~60.43999,22.32229
+Itäkeskus^#FF0000,5,1,#ff8800,0.4^^60.44346,22.35808~60.44244,22.35827~60.44249,22.36081~60.44351,22.36066
+Kansanpuisto^#FF0000,5,1,#ff8800,0.4^^60.43241,22.18311~60.42627,22.18908~60.42303,22.17673~60.42923,22.16934
+@@@@@@V2
--- a/regions.ini	Thu Oct 26 18:02:27 2017 +0300
+++ b/regions.ini	Fri Nov 24 22:41:48 2017 +0200
@@ -102,7 +102,6 @@
 Linnavuori = 3122
 Viiala = 3024
 Viluluoto = 3010
-Satava = 373
 Montola = 3157
 Airismaa = 3171
 Aaslaluoto = 3308
@@ -148,10 +147,8 @@
 [Turku]
 Artukainen = 1513
 auvaismäki = 1102
-Eerikvalla = 395
 Friskala = 394
 Jyrkkälä = 758
-Haarla = 364
 Halinen = 1628
 Harittu = 1489
 Hepokulta = 26
@@ -167,7 +164,6 @@
 Jäkärlä = 1366
 Jänessaari = 437
 Kaistarniemi = 1747
-Kakskerta = 1764
 Kastu = 627
 Kasarmialue = 1797
 Katariina = 516
@@ -177,7 +173,6 @@
 Koivula = 788
 Kohmo = 1651
 Konserttitalo = 18
-Kukola = 1732
 Kupittaa as = 870
 Kupittaa = 1046
 Kupittaanpuisto = 1972
@@ -196,14 +191,12 @@
 Luolavuori = 1721
 Luostarinmäki = 864
 Länsinummi = 818
-Maanpää = 1729
 Majakkaranta = 81
 Marjaniemi = 534
 Martti = 74
 Messukeskus = 1521
 Metsämäki = 256
 Mäntymäki = 1800
-Moikoinen = 91
 Moisio = 1066
 Muhkuri = 899
 Mälikkälä = 781
@@ -211,7 +204,6 @@
 Nummenmäki = 62
 Nummen koulu = 1826
 Nättinummi = 30
-Oriniemi = 316
 Oriketo = 1435
 Paattinen = 1127
 Pansio = 1506
@@ -229,7 +221,6 @@
 Raunistula = 224
 Raunistulan puistotie = 177
 Rautatieasema = 144
-Ruissalo = 666
 Runosmäki = 1015
 Räntämäki = 1441
 Satakunnantie = 20
@@ -242,7 +233,6 @@
 Särkilahti = 404
 Länsikeskus = 476
 Takakirves = 621
-Toijainen = 424
 Tortinmäki = 1149
 Tuomiokirkkotori = 131
 Turkuhalli = 1516
--- a/service.py	Thu Oct 26 18:02:27 2017 +0300
+++ b/service.py	Fri Nov 24 22:41:48 2017 +0200
@@ -10,7 +10,7 @@
 import buses
 
 app = Flask(__name__)
-suffix_regions = {'naantalin pikatie', 'helsingin valtatie'}
+suffix_regions = {'naantalin pikatie', 'helsingin valtatie', 'kansanpuisto'}
 
 # Varmista ettei järjestelmän kieliasetukset sotke muotoiluja
 def reset_locale():
@@ -64,10 +64,16 @@
 		else:
 			return request.accept_languages.best_match(tr.languages)
 
-def sign(schedule_entry, long = False):
+def sign_elements(schedule_entry, long = False):
 	from math import ceil
 	trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance
-	sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length, long = long)
+	return reduce_schedule(
+		schedule_entry['trip'].concise_schedule(schedule_entry['stop']),
+		trip_length = trip_length,
+		long = long)
+
+def sign(schedule_entry, long = False):
+	sign = sign_elements(schedule_entry, long = long)
 	if sign:
 		sign_representation = ' - '.join(tr(place, 'places') 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)
@@ -160,6 +166,42 @@
 		tr = tr,
 	)
 
+@app.route('/stop_description/<reference>')
+def bus_stop_description(reference):
+	from buses import bus_stops
+	schedule = []
+	try:
+		bus_stop = bus_stops[reference]
+	except KeyError:
+		abort(404)
+	from collections import defaultdict, Counter
+	from busroute import simplify_name
+	destinations_per_route = defaultdict(Counter)
+	def route_key(route_ref):
+		from re import search
+		match = search(r'^([^0-9]*)([0-9]+)(.*)$', route_ref).groups()
+		if match:
+			return match[0], int(match[1]), match[2]
+		else:
+			return ()
+	def filter_names(names):
+		if len(names) == 1 and names[0] == (bus_stop.region and simplify_name(bus_stop.region)):
+			return type(names)()
+		else:
+			return names
+	for schedule_entry in bus_stop.schedule(max_amount = 100, arrivals = True):
+		sign_tuple = tuple(sign_elements(schedule_entry))
+		destinations_per_route[schedule_entry['trip'].route.reference][sign_tuple] += 1
+	routes_per_destination = defaultdict(set)
+	for route in destinations_per_route:
+		winner = filter_names(destinations_per_route[route].most_common()[0][0])
+		destinations_per_route[route] = winner and ' - '.join(winner) or ''
+		routes_per_destination[winner].add(route)
+	for key in routes_per_destination:
+		routes_per_destination[key] = sorted(routes_per_destination[key], key = route_key)
+	from pprint import pformat
+	return pformat(routes_per_destination)
+
 @app.route('/api/describe_destination/<trip_reference>/<stop_reference>/<int:index>')
 def describe_destination(trip_reference, stop_reference, index):
 	from buses import bus_stops, all_trips
@@ -196,7 +238,7 @@
 		bus_stop = bus_stops[reference]
 	except KeyError:
 		abort(404)
-	for i, schedule_entry in enumerate(bus_stop.schedule(max_amount = 6, arrivals = False)):
+	for i, schedule_entry in enumerate(bus_stop.schedule_for_day(today(), arrivals = False)[:6]):
 		schedule.append({
 			'time_data': schedule_entry['time'],
 			'time': time_representation(schedule_entry['time']),

mercurial