Move mapsme code to mapsme script

This commit is contained in:
Ilya Zverev 2017-10-17 20:29:04 +03:00
parent 829ca49678
commit 0c87795c76
2 changed files with 18 additions and 14 deletions

View file

@ -141,10 +141,22 @@ def load_xml(f):
return elements
def merge_mapsme_networks(networks):
def mapsme_network(city):
routes = []
network = [{'network': 'TODO', 'agency_id': 12345, 'routes': routes}]
return network
def prepare_mapsme_data(transfers, networks):
stops = set()
# TODO: prepare a set of all stations
result = {}
for k in ('stops', 'transfers', 'networks'):
result[k] = sum([n[k] for n in networks], [])
result['stops'] = list(stops)
result['transfers'] = []
for t in transfers:
# TODO: decouple transfers and add travel time
pass
result['networks'] = sum(networks, [])
return result
@ -233,6 +245,6 @@ if __name__ == '__main__':
# Finally, prepare a JSON file for MAPS.ME
if options.output:
networks = [c.for_mapsme() for c in good_cities]
networks = [mapsme_network(c) for c in good_cities]
with open(options.output, 'w') as f:
json.dump(merge_mapsme_networks(networks), f)
json.dump(prepare_mapsme_data(transfers, networks), f)

View file

@ -108,8 +108,8 @@ class Station:
center, d_center) <= MAX_DISTANCE_NEARBY:
self.elements.add(el_id(d))
# TODO: Set name, colour etc.
self.name = el['tags'].get('name', 'Unknown')
self.int_name = el['tags'].get('int_name', el['tags'].get('name:en', None))
self.colour = el['tags'].get('colour', None)
def contains(self, el):
@ -466,14 +466,6 @@ class City:
n_str = '; '.join(['{} ({})'.format(k, v) for k, v in networks.items()])
self.warn('More than one network: {}'.format(n_str))
def for_mapsme(self):
stops = []
transfers = []
routes = []
network = {'network': 'TODO', 'agency_id': 12345, 'routes': routes}
result = {'stops': stops, 'transfers': transfers, 'networks': [network]}
return result
def find_transfers(elements, cities):
global transfers