Mercurial > hg > nsaunier > traffic-intelligence
comparison python/sumo.py @ 964:e3ec6caab984
utilities for SUMO traffic simulation
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 27 Nov 2017 17:23:30 -0500 |
| parents | |
| children | eec549e9ff2e |
comparison
equal
deleted
inserted
replaced
| 963:2757efeabbb4 | 964:e3ec6caab984 |
|---|---|
| 1 #! /usr/bin/env python | |
| 2 '''Libraries for the SUMO traffic simulation software | |
| 3 http://sumo.dlr.de | |
| 4 ''' | |
| 5 | |
| 6 import csv | |
| 7 | |
| 8 def convertTazEdges(inFilename, outFilename): | |
| 9 '''Converts list of OSM edges per OSM edge and groups per TAZ''' | |
| 10 data = [] | |
| 11 tazs = {} | |
| 12 with open(inFilename,'r') as f: | |
| 13 csv_reader = csv.reader(f, delimiter=",") | |
| 14 next(csv_reader, None) # skip the headers | |
| 15 for row in csv_reader: | |
| 16 data.append(row) | |
| 17 | |
| 18 for datum in data: | |
| 19 if len(datum) > 5 and datum[5] is not None: | |
| 20 tazID = datum[3] | |
| 21 for edge in datum[15:]: | |
| 22 if len(edge) > 0: | |
| 23 if edge is not None: | |
| 24 tazs.setdefault(tazID, [edge]).append(edge) | |
| 25 | |
| 26 with open(outFilename,'w') as out: | |
| 27 out.write('<tazs>\n') | |
| 28 for tazID in tazs: | |
| 29 out.write('<taz id="{}" edges="'.format(tazID)+' '.join(tazs[tazID])+'"/>\n') | |
| 30 out.write('</tazs>\n') | |
| 31 | |
| 32 # TODO add utils from process-cyber.py? | |
| 33 | |
| 34 # if __name__ == "__main__": | |
| 35 # import doctest | |
| 36 # import unittest | |
| 37 # suite = doctest.DocFileSuite('tests/sumo.txt') | |
| 38 # #suite = doctest.DocTestSuite() | |
| 39 # unittest.TextTestRunner().run(suite) |
