Mercurial > hg > nsaunier > traffic-intelligence
comparison python/storage.py @ 335:3950bfe22768
added functions to export trajectories to csv
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 14 Jun 2013 11:47:24 -0400 |
| parents | 00800ebae698 |
| children | 1046b7346886 |
comparison
equal
deleted
inserted
replaced
| 334:1d90e9080cb2 | 335:3950bfe22768 |
|---|---|
| 288 | 288 |
| 289 print nObjectsPerType | 289 print nObjectsPerType |
| 290 | 290 |
| 291 out.close() | 291 out.close() |
| 292 | 292 |
| 293 def writePositionsToCsv(f, obj): | |
| 294 timeInterval = obj.getTimeInterval() | |
| 295 positions = obj.getPositions() | |
| 296 curvilinearPositions = obj.getCurvilinearPositions() | |
| 297 for i in xrange(int(obj.length())): | |
| 298 p1 = positions[i] | |
| 299 s = '{},{},{},{}'.format(obj.num,timeInterval[i],p1.x,p1.y) | |
| 300 if curvilinearPositions != None: | |
| 301 p2 = curvilinearPositions[i] | |
| 302 s += ',{},{}'.format(p2[0],p2[1]) | |
| 303 f.write(s+'\n') | |
| 304 | |
| 305 def writeTrajectoriesToCsv(filename, objects): | |
| 306 f = open(filename, 'w') | |
| 307 for i,obj in enumerate(objects): | |
| 308 writePositionsToCsv(f, obj) | |
| 309 f.close() | |
| 310 | |
| 293 if __name__ == "__main__": | 311 if __name__ == "__main__": |
| 294 import doctest | 312 import doctest |
| 295 import unittest | 313 import unittest |
| 296 suite = doctest.DocFileSuite('tests/storage.txt') | 314 suite = doctest.DocFileSuite('tests/storage.txt') |
| 297 unittest.TextTestRunner().run(suite) | 315 unittest.TextTestRunner().run(suite) |
