Kuntauudistus

Tue, 29 Aug 2017 21:01:57 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 29 Aug 2017 21:01:57 +0300
changeset 52
cab8d38fe5c6
parent 51
145b453ba8f2
child 53
1c934953c3e6

Kuntauudistus

busroute.py file | annotate | diff | comparison | revisions
compute-regions.py file | annotate | diff | comparison | revisions
regions.gmp file | annotate | diff | comparison | revisions
--- a/busroute.py	Tue Aug 29 17:34:09 2017 +0300
+++ b/busroute.py	Tue Aug 29 21:01:57 2017 +0300
@@ -1,30 +1,43 @@
 #!/usr/bin/env python3
 
+from configparser import ConfigParser
+
 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',
-	'Pernon telakka': 'Perno',
+	"ylioppilaskylä-itä": "ylioppilaskylä",
+	"ylioppilaskylä-länsi": "ylioppilaskylä",
+	"jokila": "lieto",
+	"piispala": "lieto",
+	'saaro': 'ruissalo',
+	'silvola': 'vahto',
+	'hemmola': 'vahto',
+	'paasniittu': 'ruskon keskusta',
+	'kahari': 'ruskon keskusta',
+	'kemiö': 'kemiönsaari',
+	'kasnäs': 'kemiönsaari',
+	'pernon telakka': 'perno',
 }
 
 # nimiä joista voidaan joustaa tarvittaessa
 abbreviations = {
-	'Raision keskusta': 'Raisio',
-	'Ruskon keskusta': 'Rusko',
-	'Naantalin keskusta': 'Naantali',
-	'Kaarinan keskusta': 'Kaarina',
-	'Kauppakeskus Mylly': 'Mylly',
+	'raision keskusta': 'raisio',
+	'ruskon keskusta': 'rusko',
+	'naantalin keskusta': 'naantali',
+	'kaarinan keskusta': 'kaarina',
+	'kauppakeskus mylly': 'mylly',
 }
 
+region_info = ConfigParser()
+region_info.read('regions.ini')
+municipalities = set(region_info.sections())
+municipalities_per_region = {}
+
+for municipality in municipalities:
+	for region in region_info[municipality].keys():
+		municipalities_per_region[region] = municipality
+
+for place_from, place_to in replacements.items():
+	municipalities_per_region[place_to] = municipalities_per_region[place_from]
+
 def simplify_name(name):
 	name = replacements.get(name, name)
 	name = abbreviations.get(name, name)
@@ -34,10 +47,6 @@
 	length = ((trip_length / 600) + len(reitti)) / 2
 	if not reitti:
 		return ''
-	eksoalueet = {
-		'Turku', 'Naantali', 'Lieto', 'Aura', 'Kaarina', 'Pargas', 'Marttila', 'Somero', 'Koski Tl', 'Tarvasjoki',
-		'Kaivopuisto',
-	}
 	have_already = set()
 	i = 0
 	while i < len(reitti):
@@ -49,77 +58,78 @@
 			have_already.add(reitti[i])
 			i += 1
 	priorities = {
-		'Ihala': 150,
-		'Kauppakeskus Mylly': 200,
-		'Kuninkoja': 80,
-		'Moikoinen': 80,
-		'Raision keskusta': 150,
-		'Kukola': 50,
-		'Kaistarniemi': 50,
-		'Papinsaari': 50,
-		'Oriniemi': 50,
-		'Pikisaari': 50,
-		'Häppilä': 20,
-		'Haarla': 80,
-		'Ylioppilaskylä': 50,
-		'Halinen': 70,
-		'Kakskerta': 200,
-		'Pansio': 50,
-		'Räntämäki': 10,
-		'Verkahovi': 20,
-		'Skanssi': 200,
-		'Vaala': 20,
-		'Varissuo': 60,
-		'Kohmo': 80,
-		'Kupittaa': 70,
-		'Kauppatori': 1e15,
-		'Lentoasema': 50,
-		'Runosmäki': 50,
-		'Lieto': 100,
-		'Lieto as': 200,
-		'Ilmarinen': 50,
-		'Vahto': 50,
-		'Ruskon keskusta': 200,
-		'Oriketo': 50,
-		'Harittu': 40,
-		'Jäkärlä': 50,
-		'Paattinen': 100,
-		'Kaarinan keskusta': 200,
-		'Naantalin keskusta': 200,
-		'Uittamo': 50,
-		'Piikkiö': 100,
-		'Paimio': 100,
-		'Pargas': 100,
-		'Nagu': 100,
-		'Yli-Maaria': 70,
-		'Saramäki': 50,
-		'Tarvasjoki': 100,
-		'Marttila': 100,
-		'Koski Tl': 100,
-		'Katariina': 50,
-		'Länsikeskus': 50,
-		'Kaanaa': 100,
-		'Satava': 50,
-		'Suikkila': 50,
-		'Raunistula': 50,
-		'Räntämäki': 50,
-		'Moisio': 25,
-		'Pääskyvuori': 100,
-		'Rautatieasema': 50,
-		'Logomo': 100,
-		'Rymättylä': 50,
-		"Sauvo": 500,
-		"Kemiönsaari": 500,
-		'Suovuori': 300,
-		'Eerikvalla': 50,
-		'Petäsmäki': 50,
-		'Tortinmäki': 50,
-		'Aura': 100,
-		'Friskala': -1,
+		'ihala': 150,
+		'kauppakeskus mylly': 200,
+		'kuninkoja': 80,
+		'moikoinen': 80,
+		'raision keskusta': 150,
+		'kukola': 50,
+		'kaistarniemi': 50,
+		'papinsaari': 50,
+		'oriniemi': 50,
+		'pikisaari': 50,
+		'häppilä': 20,
+		'haarla': 80,
+		'ylioppilaskylä': 50,
+		'halinen': 70,
+		'kakskerta': 200,
+		'pansio': 50,
+		'räntämäki': 10,
+		'verkahovi': 20,
+		'skanssi': 200,
+		'vaala': 20,
+		'varissuo': 60,
+		'kohmo': 80,
+		'kupittaa': 70,
+		'kauppatori': 1e15,
+		'lentoasema': 50,
+		'runosmäki': 50,
+		'lieto': 100,
+		'lieto as': 200,
+		'ilmarinen': 50,
+		'vahto': 50,
+		'ruskon keskusta': 200,
+		'oriketo': 50,
+		'harittu': 40,
+		'jäkärlä': 50,
+		'paattinen': 100,
+		'kaarinan keskusta': 200,
+		'naantalin keskusta': 200,
+		'uittamo': 50,
+		'piikkiö': 100,
+		'paimio': 100,
+		'pargas': 100,
+		'nagu': 100,
+		'yli-maaria': 70,
+		'saramäki': 50,
+		'tarvasjoki': 100,
+		'marttila': 100,
+		'koski tl': 100,
+		'katariina': 50,
+		'länsikeskus': 50,
+		'kaanaa': 100,
+		'satava': 50,
+		'suikkila': 50,
+		'raunistula': 50,
+		'räntämäki': 50,
+		'moisio': 25,
+		'pääskyvuori': 100,
+		'rautatieasema': 50,
+		'logomo': 100,
+		'rymättylä': 50,
+		"sauvo": 500,
+		"kemiönsaari": 500,
+		'suovuori': 300,
+		'eerikvalla': 50,
+		'petäsmäki': 50,
+		'tortinmäki': 50,
+		'aura': 100,
+		'friskala': -1,
+		'merimasku': 50,
 	}
 
-	if 'Kauppatori' not in reitti:
-		priorities['Länsikeskus'] = priorities['Skanssi'] = priorities['Kauppatori']
+	if 'kauppatori' not in reitti:
+		priorities['länsikeskus'] = priorities['skanssi'] = priorities['kauppatori']
 
 	from_place = reitti[0]
 	destination = reitti[-1]
@@ -160,29 +170,31 @@
 	except IndexError:
 		pass
 	# lajitellaan painoarvot uudestaan reittijärjestykseen jotta sign tulee oikeinpäin
-	weights = sorted(weights, key = lambda paino: paino[2])
+	weights = sorted(weights, key = lambda weight_data: weight_data[2])
 	# muodostetaan sign..
 	sign = [paino[0] for paino in weights]
-	# supista nimet jos mahdollista
-	def finalise(sign, abbreviation_level = 0):
-		if abbreviation_level > 0:
-			sign = [abbreviations.get(paikka, paikka) for paikka in sign]
-		return sign
-	result = finalise(sign)
-	for i in range(len(sign) - 1):
-		if sign[i + 1].startswith(sign[i]):
-			del sign[i]
+	to_place = sign[-1]
+	if from_place != to_place:
+		municipality_from = municipalities_per_region.get(from_place)
+		municipality_to = municipalities_per_region.get(to_place)
+		if municipality_from and municipality_to and municipality_from not in ['Turku', municipality_to]:
+			def convert_region(region):
+				municipality = municipalities_per_region.get(region, region)
+				if municipality != municipality_from:
+					return municipality
+				else:
+					return region
+			sign = [convert_region(region) for region in sign]
+	# supista nimet tarvittaessa
 	if len(' - '.join(sign)) > 20:
-		result = finalise(sign, abbreviation_level = 1)
+		sign = [abbreviations.get(place, place) for place in sign]
+	old_sign = sign.copy()
+	sign = []
+	for place in old_sign:
+		if place not in sign:
+			sign.append(place)
 	if whole:
-		result = [from_place] + result
-	if not result:
-		result = [destination]
-	short_from_place = replacements.get(from_place, from_place)
-	if (
-		short_from_place != result[-1]
-		and abbreviations.get(short_from_place, short_from_place) in eksoalueet | {'Kauppatori'}
-		and result[-1] in eksoalueet | {'Kauppatori'}
-	):
-		result = ['Turku' if k == 'Kauppatori' else k for k in result]
-	return result
+		sign = [from_place] + sign
+	if not sign:
+		sign = [destination]
+	return sign
--- a/compute-regions.py	Tue Aug 29 17:34:09 2017 +0300
+++ b/compute-regions.py	Tue Aug 29 21:01:57 2017 +0300
@@ -3,13 +3,20 @@
 from misc import *
 from geometry import *
 from zipfile import ZipFile
+from configparser import ConfigParser
+
+representatives = {}
+
+region_data = ConfigParser()
+region_data.read('regions.ini')
+
+for section in region_data.sections():
+	for key, value in region_data[section].items():
+		representatives[key] = value
 
 with open('regions.gmp') as file:
 	data = file.read().split('@')
 
-with open('region-representatives.json') as file:
-	representatives = json.load(file)
-
 bus_stops = {}
 
 with ZipFile('gtfs.zip') as archive:
--- a/regions.gmp	Tue Aug 29 17:34:09 2017 +0300
+++ b/regions.gmp	Tue Aug 29 21:01:57 2017 +0300
@@ -1,4 +1,4 @@
-roadmap^60.45568477029873, 22.16861806444229^16@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
+roadmap^60.49699199716986, 21.805157285252225^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
@@ -243,4 +243,8 @@
 undefined^#FF0000,5,1,#ff8800,0.4^^60.45732,22.24006~60.45442,22.24632~60.45666,22.25307~60.45759,22.25321~60.45928,22.25848~60.45959,22.26538~60.46236,22.26235~60.45799,22.24479
 undefined^#FF0000,5,1,#ff8800,0.4^^60.45757,22.25328~60.45645,22.25334~60.45614,22.25654~60.4572,22.26027~60.45916,22.25863
 undefined^#FF0000,5,1,#ff8800,0.4^^60.48146,22.18101~60.47916,22.18333~60.47609,22.18837~60.47351,22.19223~60.47222,22.19401~60.46783,22.20032~60.463,22.20689~60.46074,22.20953~60.4594,22.21127~60.45874,22.21588~60.4563,22.23555~60.4549,22.24193~60.4545,22.24388~60.45421,22.24468~60.4544,22.24516~60.45482,22.24415~60.45674,22.23579~60.4602,22.21273~60.4663,22.2036~60.47311,22.1943~60.47718,22.18974
+undefined^#FF0000,5,1,#ff8800,0.4^^60.51971,21.69817~60.5089,21.77742~60.48793,21.77971~60.46991,21.76529~60.43724,21.74709~60.39831,21.72447~60.38774,21.68358~60.39503,21.58333~60.42358,21.54535~60.45749,21.55515~60.49596,21.62521
+undefined^#FF0000,5,1,#ff8800,0.4^^60.4914,21.85867~60.47795,21.88854~60.46416,21.88168~60.46255,21.86331~60.47169,21.84992~60.48239,21.84906
+undefined^#FF0000,5,1,#ff8800,0.4^^60.51591,21.87249~60.50674,21.85773~60.50167,21.86408~60.50746,21.88889
+undefined^#FF0000,5,1,#ff8800,0.4^^60.50991,21.79688~60.50553,21.82198~60.49879,21.82486~60.48869,21.81559~60.48873,21.80606~60.50384,21.79046
 @@@@@@

mercurial