compute-regions.py

changeset 130
9c68fa498050
parent 129
f5ba81a7d86e
equal deleted inserted replaced
129:f5ba81a7d86e 130:9c68fa498050
83 83
84 def get_args(): 84 def get_args():
85 from argparse import ArgumentParser 85 from argparse import ArgumentParser
86 parser = ArgumentParser() 86 parser = ArgumentParser()
87 parser.add_argument('gtfs_zip') 87 parser.add_argument('gtfs_zip')
88 parser.add_argument('mapfile') 88 parser.add_argument('profile')
89 return parser.parse_args() 89 return parser.parse_args()
90 90
91 def compute_bus_stop_regions(regions, bus_stops): 91 def compute_bus_stop_regions(regions, bus_stops):
92 # Find the region every node is in 92 # Find the region every node is in
93 blockmap = create_blockmap(regions) 93 blockmap = create_blockmap(regions)
103 return bus_stop_regions 103 return bus_stop_regions
104 104
105 def percentage(a): 105 def percentage(a):
106 return '%.1f%%' % (a * 100) 106 return '%.1f%%' % (a * 100)
107 107
108 def compute_route_models(gtfs_path):
109 from buses import load_buses
110 load_buses(gtfs_path)
111
108 def main(): 112 def main():
109 from regions import parse_regions 113 from regions import parse_regions
114 from misc import profile
110 args = get_args() 115 args = get_args()
111 regions = parse_regions(args.mapfile) 116 profile.read(args.profile)
117 regions = parse_regions(profile['regions']['osm-path'])
112 bus_stops = read_bus_stops(args.gtfs_zip) 118 bus_stops = read_bus_stops(args.gtfs_zip)
113 bus_stop_regions = compute_bus_stop_regions(regions, bus_stops) 119 bus_stop_regions = compute_bus_stop_regions(regions, bus_stops)
114 covered = sum(1 if value else 0 for value in bus_stop_regions.values()) 120 covered = sum(1 if value else 0 for value in bus_stop_regions.values())
115 total = len(bus_stops) 121 total = len(bus_stops)
116 print('%s bus stops covered.' % percentage(covered / total), 122 print('%s bus stops covered.' % percentage(covered / total),
117 file = sys.stderr) 123 file = sys.stderr)
118 json.dump(bus_stop_regions, sys.stdout, indent = 2) 124 json.dump(bus_stop_regions, sys.stdout, indent = 2)
125 return 0
119 126
120 if __name__ == '__main__': 127 if __name__ == '__main__':
121 main() 128 from sys import exit
129 exit(main())

mercurial