Mercurial > hg > nsaunier > traffic-intelligence
comparison python/storage.py @ 829:0ddcc41663f5
renaming
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 29 Jun 2016 13:50:21 -0400 |
| parents | ef8795dba5ed |
| children | 2a5856961933 |
comparison
equal
deleted
inserted
replaced
| 828:14e4ad7c7420 | 829:0ddcc41663f5 |
|---|---|
| 281 objects[objNum].curvilinearPositions.addPositionSYL(row[2],row[3],row[4]) | 281 objects[objNum].curvilinearPositions.addPositionSYL(row[2],row[3],row[4]) |
| 282 if len(missingObjectNumbers) > 0: | 282 if len(missingObjectNumbers) > 0: |
| 283 print('List of missing objects to attach corresponding curvilinear trajectories: {}'.format(missingObjectNumbers)) | 283 print('List of missing objects to attach corresponding curvilinear trajectories: {}'.format(missingObjectNumbers)) |
| 284 | 284 |
| 285 def saveTrajectoriesToSqlite(outputFilename, objects, trajectoryType, withFeatures = False): | 285 def saveTrajectoriesToSqlite(outputFilename, objects, trajectoryType, withFeatures = False): |
| 286 '''Writes features, ie the trajectories positions (and velocities if exist) | 286 '''Writes features, ie the trajectory positions (and velocities if exist) |
| 287 with their instants to a specified sqlite file | 287 with their instants to a specified sqlite file |
| 288 Either feature positions (and velocities if they exist) | 288 Either feature positions (and velocities if they exist) |
| 289 or curvilinear positions will be saved at a time | 289 or curvilinear positions will be saved at a time |
| 290 | 290 |
| 291 TODO: Not implemented for trajectoryType MovingObject with features | 291 TODO: Not implemented for trajectoryType MovingObject with features |
| 791 while len(s) > 0 and s[0] != delimiterChar: | 791 while len(s) > 0 and s[0] != delimiterChar: |
| 792 dataStrings += [s.strip()] | 792 dataStrings += [s.strip()] |
| 793 s = readline(f, commentCharacters) | 793 s = readline(f, commentCharacters) |
| 794 return dataStrings | 794 return dataStrings |
| 795 | 795 |
| 796 def writeList(filename, l): | 796 def saveList(filename, l): |
| 797 f = openCheck(filename, 'w') | 797 f = openCheck(filename, 'w') |
| 798 for x in l: | 798 for x in l: |
| 799 f.write('{}\n'.format(x)) | 799 f.write('{}\n'.format(x)) |
| 800 f.close() | 800 f.close() |
| 801 | 801 |
| 1106 | 1106 |
| 1107 print nObjectsPerType | 1107 print nObjectsPerType |
| 1108 | 1108 |
| 1109 out.close() | 1109 out.close() |
| 1110 | 1110 |
| 1111 def writePositionsToCsv(f, obj): | 1111 def savePositionsToCsv(f, obj): |
| 1112 timeInterval = obj.getTimeInterval() | 1112 timeInterval = obj.getTimeInterval() |
| 1113 positions = obj.getPositions() | 1113 positions = obj.getPositions() |
| 1114 curvilinearPositions = obj.getCurvilinearPositions() | 1114 curvilinearPositions = obj.getCurvilinearPositions() |
| 1115 for i in xrange(int(obj.length())): | 1115 for i in xrange(int(obj.length())): |
| 1116 p1 = positions[i] | 1116 p1 = positions[i] |
| 1118 if curvilinearPositions is not None: | 1118 if curvilinearPositions is not None: |
| 1119 p2 = curvilinearPositions[i] | 1119 p2 = curvilinearPositions[i] |
| 1120 s += ',{},{}'.format(p2[0],p2[1]) | 1120 s += ',{},{}'.format(p2[0],p2[1]) |
| 1121 f.write(s+'\n') | 1121 f.write(s+'\n') |
| 1122 | 1122 |
| 1123 def writeTrajectoriesToCsv(filename, objects): | 1123 def saveTrajectoriesToCsv(filename, objects): |
| 1124 f = openCheck(filename, 'w') | 1124 f = openCheck(filename, 'w') |
| 1125 for i,obj in enumerate(objects): | 1125 for i,obj in enumerate(objects): |
| 1126 writePositionsToCsv(f, obj) | 1126 savePositionsToCsv(f, obj) |
| 1127 f.close() | 1127 f.close() |
| 1128 | 1128 |
| 1129 | 1129 |
| 1130 ######################### | 1130 ######################### |
| 1131 # Utils to read .ini type text files for configuration, meta data... | 1131 # Utils to read .ini type text files for configuration, meta data... |
