Mercurial > hg > nsaunier > traffic-intelligence
comparison python/sumo.py @ 966:40af0f20ee2d
reworking the functions
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 05 Dec 2017 16:11:49 -0500 |
| parents | eec549e9ff2e |
| children | 32a34a143c27 |
comparison
equal
deleted
inserted
replaced
| 965:eec549e9ff2e | 966:40af0f20ee2d |
|---|---|
| 3 http://sumo.dlr.de | 3 http://sumo.dlr.de |
| 4 ''' | 4 ''' |
| 5 | 5 |
| 6 import csv | 6 import csv |
| 7 | 7 |
| 8 def convertTazEdges(inFilename, outFilename): | 8 def loadTazEdges(inFilename): |
| 9 '''Converts list of OSM edges per OSM edge and groups per TAZ''' | 9 '''Converts list of OSM edges per OSM edge and groups per TAZ''' |
| 10 data = [] | 10 data = [] |
| 11 tazs = {} | 11 tazs = {} |
| 12 with open(inFilename,'r') as f: | 12 with open(inFilename,'r') as f: |
| 13 csv_reader = csv.reader(f, delimiter=",") | 13 csv_reader = csv.reader(f, delimiter=",") |
| 24 if tazID in tazs: | 24 if tazID in tazs: |
| 25 if edge not in tazs[tazID]: | 25 if edge not in tazs[tazID]: |
| 26 tazs[tazID].append(edge) | 26 tazs[tazID].append(edge) |
| 27 else: | 27 else: |
| 28 tazs[tazID] = [edge] | 28 tazs[tazID] = [edge] |
| 29 | 29 return tazs |
| 30 | |
| 31 def saveTazEdges(outFilename, tazs): | |
| 30 with open(outFilename,'w') as out: | 32 with open(outFilename,'w') as out: |
| 31 out.write('<tazs>\n') | 33 out.write('<tazs>\n') |
| 32 for tazID in tazs: | 34 for tazID in tazs: |
| 33 out.write('<taz id="{}" edges="'.format(tazID)+' '.join(tazs[tazID])+'"/>\n') | 35 out.write('<taz id="{}" edges="'.format(tazID)+' '.join(tazs[tazID])+'"/>\n') |
| 34 out.write('</tazs>\n') | 36 out.write('</tazs>\n') |
| 35 | 37 |
| 36 # TODO add utils from process-cyber.py? | 38 # TODO add utils from process-cyber.py? |
| 37 | 39 |
| 38 # if __name__ == "__main__": | 40 # if __name__ == "__main__": |
| 39 # import doctest | 41 # import doctest |
| 40 # import unittest | 42 # import unittest |
