comparison python/sumo.py @ 998:933670761a57

updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 27 May 2018 23:22:48 -0400
parents 32a34a143c27
children
comparison
equal deleted inserted replaced
997:4f3387a242a1 998:933670761a57
14 tazs = {} 14 tazs = {}
15 with open(inFilename,'r') as f: 15 with open(inFilename,'r') as f:
16 f.readline() # skip the headers 16 f.readline() # skip the headers
17 for r in f: 17 for r in f:
18 tmp = r.strip().split(',') 18 tmp = r.strip().split(',')
19 tazID = tmp[1] 19 tazID = tmp[1]
20 for edge in tmp[2:]: 20 for edge in tmp[2:]:
21 if len(edge) > 0: 21 if len(edge) > 0:
22 if tazID in tazs: 22 if tazID in tazs:
23 if edge not in tazs[tazID]: 23 if edge not in tazs[tazID]:
24 tazs[tazID].append(edge) 24 tazs[tazID].append(edge)
27 return tazs 27 return tazs
28 28
29 def edge2Taz(tazs): 29 def edge2Taz(tazs):
30 '''Returns the associative array of the TAZ of each SUMO edge''' 30 '''Returns the associative array of the TAZ of each SUMO edge'''
31 edge2Tazs = {} 31 edge2Tazs = {}
32 for taz, edges in tazs.iteritems(): 32 for taz, edges in tazs.items():
33 for edge in edges: 33 for edge in edges:
34 if edge in edge2Tazs: 34 if edge in edge2Tazs:
35 print('error for edge: {} (taz {}/{})'.format(edge, edge2Tazs[edge], taz)) 35 print('error for edge: {} (taz {}/{})'.format(edge, edge2Tazs[edge], taz))
36 edge2Tazs[edge] = taz 36 edge2Tazs[edge] = taz
37 return edge2Tazs 37 return edge2Tazs
38 38
39 def saveTazEdges(outFilename, tazs): 39 def saveTazEdges(outFilename, tazs):
40 with open(outFilename,'w') as out: 40 with open(outFilename,'w') as out:
41 out.write('<tazs>\n') 41 out.write('<tazs>\n')
42 for tazID in tazs: 42 for tazID in tazs:
43 out.write('<taz id="{}" edges="'.format(tazID)+' '.join(tazs[tazID])+'"/>\n') 43 out.write('<taz id="{}" edges="'.format(tazID)+' '.join(tazs[tazID])+'"/>\n')
44 out.write('</tazs>\n') 44 out.write('</tazs>\n')
45 45
46 # TODO add utils from process-cyber.py? 46 # TODO add utils from process-cyber.py?
47 47
48 # if __name__ == "__main__": 48 # if __name__ == "__main__":
49 # import doctest 49 # import doctest
50 # import unittest 50 # import unittest