Fri, 07 Sep 2018 00:38:18 +0300
removed replacement
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | import sys, json |
3 | from misc import * | |
7
f3791dccfd03
Käännetty tiedostojen nimet englanniksi
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
4 | from geometry import * |
31
60045b362d71
- Ajovuoroa ei enää esitetä kahdessa välilehdessä vaan puukuvaimessa
Teemu Piippo <teemu@hecknology.net>
parents:
27
diff
changeset
|
5 | from zipfile import ZipFile |
52 | 6 | from configparser import ConfigParser |
88
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
7 | from regions import parse_regions |
52 | 8 | |
9 | representatives = {} | |
10 | ||
89 | 11 | regions = parse_regions(sys.argv[2]) |
7
f3791dccfd03
Käännetty tiedostojen nimet englanniksi
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
12 | bus_stops = {} |
2 | 13 | |
89 | 14 | with ZipFile(sys.argv[1]) as archive: |
31
60045b362d71
- Ajovuoroa ei enää esitetä kahdessa välilehdessä vaan puukuvaimessa
Teemu Piippo <teemu@hecknology.net>
parents:
27
diff
changeset
|
15 | with archive.open('stops.txt') as file: |
60045b362d71
- Ajovuoroa ei enää esitetä kahdessa välilehdessä vaan puukuvaimessa
Teemu Piippo <teemu@hecknology.net>
parents:
27
diff
changeset
|
16 | for row in read_csv(map(bytes.decode, file)): |
88
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
17 | location = Location(float(row['stop_lat']), float(row['stop_lon'])) |
31
60045b362d71
- Ajovuoroa ei enää esitetä kahdessa välilehdessä vaan puukuvaimessa
Teemu Piippo <teemu@hecknology.net>
parents:
27
diff
changeset
|
18 | reference = row['stop_id'] |
60045b362d71
- Ajovuoroa ei enää esitetä kahdessa välilehdessä vaan puukuvaimessa
Teemu Piippo <teemu@hecknology.net>
parents:
27
diff
changeset
|
19 | bus_stops[reference] = location |
2 | 20 | |
88
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
21 | region_shapes = [] |
73
c56b0ef96514
stop_description ja muuta roinaa
Teemu Piippo <teemu@hecknology.net>
parents:
52
diff
changeset
|
22 | districts = {} |
88
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
23 | bus_stop_regions = {} |
2 | 24 | |
7
f3791dccfd03
Käännetty tiedostojen nimet englanniksi
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
25 | for stop_id, stop_position in bus_stops.items(): |
88
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
26 | for region in regions.values(): |
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
27 | if region['shape'].contains_point(stop_position): |
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
28 | bus_stop_regions[stop_id] = region['name'] |
2 | 29 | break |
30 | else: | |
88
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
31 | bus_stop_regions[stop_id] = None |
2 | 32 | |
88
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
33 | covered = sum(1 if value else 0 for value in bus_stop_regions.values()) |
7
f3791dccfd03
Käännetty tiedostojen nimet englanniksi
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
34 | total = len(bus_stops) |
2 | 35 | print('%.1f%% bus stops covered.' % (covered * 100 / total), file = sys.stderr) |
88
3b86597c5a88
major update, moved the map to an osm patch
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
36 | json.dump(bus_stop_regions, sys.stdout, indent = 2) |