Fri, 04 May 2018 21:32:16 +0300
fixes, updates, new regions + priorities
#!/usr/bin/env python3 import sys, json from misc import * from geometry import * from zipfile import ZipFile from configparser import ConfigParser from regions import parse_regions representatives = {} regions = parse_regions(sys.argv[2]) bus_stops = {} with ZipFile(sys.argv[1]) as archive: with archive.open('stops.txt') as file: for row in read_csv(map(bytes.decode, file)): location = Location(float(row['stop_lat']), float(row['stop_lon'])) reference = row['stop_id'] bus_stops[reference] = location region_shapes = [] districts = {} bus_stop_regions = {} for stop_id, stop_position in bus_stops.items(): for region in regions.values(): if region['shape'].contains_point(stop_position): bus_stop_regions[stop_id] = region['name'] break else: bus_stop_regions[stop_id] = None covered = sum(1 if value else 0 for value in bus_stop_regions.values()) total = len(bus_stops) print('%.1f%% bus stops covered.' % (covered * 100 / total), file = sys.stderr) json.dump(bus_stop_regions, sys.stdout, indent = 2)