--- a/compute-regions.py Wed Jun 28 12:20:05 2017 +0300 +++ b/compute-regions.py Wed Jun 28 13:11:37 2017 +0300 @@ -32,20 +32,19 @@ bus_stop_districts = {} for name, stop_id in representatives.items(): - if stop_id is None: - continue - if stop_id not in bus_stops: - print('Representative %r for region %r not found in schedule' % (stop_id, name), file = sys.stderr) - else: - for district_shape in district_shapes: - if district_shape.sisältää_pisteen(bus_stops[stop_id]): - assert name not in districts - districts[name] = district_shape - district_shapes.remove(district_shape) - bus_stop_districts[stop_id] = name - break + if stop_id: + if stop_id not in bus_stops: + print('Representative %r for region %r not found in schedule' % (stop_id, name), file = sys.stderr) else: - print('Cannot find a shape for %r' % name, file = sys.stderr) + for district_shape in district_shapes: + if district_shape.sisältää_pisteen(bus_stops[stop_id]): + assert name not in districts + districts[name] = district_shape + district_shapes.remove(district_shape) + bus_stop_districts[stop_id] = name + break + else: + print('Cannot find a shape for %r' % name, file = sys.stderr) for stop_id, stop_position in bus_stops.items(): for district, shape in districts.items(): @@ -55,7 +54,7 @@ else: bus_stop_districts[stop_id] = None -covered = sum(int(bool(k)) for k in bus_stop_districts.values()) +covered = sum(1 if value else 0 for value in bus_stop_districts.values()) total = len(bus_stops) print('%.1f%% bus stops covered.' % (covered * 100 / total), file = sys.stderr) json.dump(bus_stop_districts, sys.stdout, indent = 2)