# HG changeset patch # User Teemu Piippo # Date 1538129344 -10800 # Node ID 9c68fa498050cec4e63218d5caf2d922b4236e6f # Parent f5ba81a7d86e2b725e04807fc91c1e7e6ffe7c8b refactor diff -r f5ba81a7d86e -r 9c68fa498050 Makefile --- a/Makefile Wed Sep 26 13:17:22 2018 +0300 +++ b/Makefile Fri Sep 28 13:09:04 2018 +0300 @@ -1,7 +1,7 @@ all: gtfs.zip regions-per-stop.json regions-per-stop.json: föli.osm gtfs.zip - ./compute-regions.py gtfs.zip föli.osm > regions-per-stop.json || rm -f regions-per-stop.json + ./compute-regions.py gtfs.zip profiles/föli.ini > regions-per-stop.json || rm -f regions-per-stop.json gtfs.zip: wget http://data.foli.fi/gtfs/gtfs.zip diff -r f5ba81a7d86e -r 9c68fa498050 compute-regions.py --- a/compute-regions.py Wed Sep 26 13:17:22 2018 +0300 +++ b/compute-regions.py Fri Sep 28 13:09:04 2018 +0300 @@ -85,7 +85,7 @@ from argparse import ArgumentParser parser = ArgumentParser() parser.add_argument('gtfs_zip') - parser.add_argument('mapfile') + parser.add_argument('profile') return parser.parse_args() def compute_bus_stop_regions(regions, bus_stops): @@ -105,10 +105,16 @@ def percentage(a): return '%.1f%%' % (a * 100) +def compute_route_models(gtfs_path): + from buses import load_buses + load_buses(gtfs_path) + def main(): from regions import parse_regions + from misc import profile args = get_args() - regions = parse_regions(args.mapfile) + profile.read(args.profile) + regions = parse_regions(profile['regions']['osm-path']) bus_stops = read_bus_stops(args.gtfs_zip) bus_stop_regions = compute_bus_stop_regions(regions, bus_stops) covered = sum(1 if value else 0 for value in bus_stop_regions.values()) @@ -116,6 +122,8 @@ print('%s bus stops covered.' % percentage(covered / total), file = sys.stderr) json.dump(bus_stop_regions, sys.stdout, indent = 2) + return 0 if __name__ == '__main__': - main() + from sys import exit + exit(main())