Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/ubc_utils.py @ 1030:aafbc0bab925
moved method around to avoid cross-dependencies
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 19 Jun 2018 10:04:52 -0400 |
| parents | cc5cb04b04b0 |
| children | e23828659a66 |
comparison
equal
deleted
inserted
replaced
| 1029:c6cf75a2ed08 | 1030:aafbc0bab925 |
|---|---|
| 55 def saveTrajectoryUserTypes(inFilename, outFilename, objects): | 55 def saveTrajectoryUserTypes(inFilename, outFilename, objects): |
| 56 '''The program saves the objects, | 56 '''The program saves the objects, |
| 57 by just copying the corresponding trajectory and velocity data | 57 by just copying the corresponding trajectory and velocity data |
| 58 from the inFilename, and saving the characteristics in objects (first line) | 58 from the inFilename, and saving the characteristics in objects (first line) |
| 59 into outFilename''' | 59 into outFilename''' |
| 60 infile = storage.openCheck(inFilename) | 60 infile = utils.openCheck(inFilename) |
| 61 outfile = storage.openCheck(outFilename,'w') | 61 outfile = utils.openCheck(outFilename,'w') |
| 62 | 62 |
| 63 if (inFilename.find('features') >= 0) or (not infile) or (not outfile): | 63 if (inFilename.find('features') >= 0) or (not infile) or (not outfile): |
| 64 return | 64 return |
| 65 | 65 |
| 66 lines = storage.getLines(infile) | 66 lines = storage.getLines(infile) |
| 84 | 84 |
| 85 print('read {0} objects'.format(objNum)) | 85 print('read {0} objects'.format(objNum)) |
| 86 | 86 |
| 87 def modifyTrajectoryFile(modifyLines, filenameIn, filenameOut): | 87 def modifyTrajectoryFile(modifyLines, filenameIn, filenameOut): |
| 88 '''Reads filenameIn, replaces the lines with the result of modifyLines and writes the result in filenameOut''' | 88 '''Reads filenameIn, replaces the lines with the result of modifyLines and writes the result in filenameOut''' |
| 89 fileIn = storage.openCheck(filenameIn, 'r', True) | 89 fileIn = utils.openCheck(filenameIn, 'r', True) |
| 90 fileOut = storage.openCheck(filenameOut, "w", True) | 90 fileOut = utils.openCheck(filenameOut, "w", True) |
| 91 | 91 |
| 92 lines = storage.getLines(fileIn) | 92 lines = storage.getLines(fileIn) |
| 93 trajNum = 0 | 93 trajNum = 0 |
| 94 while (lines != []): | 94 while (lines != []): |
| 95 modifiedLines = modifyLines(trajNum, lines) | 95 modifiedLines = modifyLines(trajNum, lines) |
| 104 fileOut.close() | 104 fileOut.close() |
| 105 | 105 |
| 106 def copyTrajectoryFile(keepTrajectory, filenameIn, filenameOut): | 106 def copyTrajectoryFile(keepTrajectory, filenameIn, filenameOut): |
| 107 '''Reads filenameIn, keeps the trajectories for which the function keepTrajectory(trajNum, lines) is True | 107 '''Reads filenameIn, keeps the trajectories for which the function keepTrajectory(trajNum, lines) is True |
| 108 and writes the result in filenameOut''' | 108 and writes the result in filenameOut''' |
| 109 fileIn = storage.openCheck(filenameIn, 'r', True) | 109 fileIn = utils.openCheck(filenameIn, 'r', True) |
| 110 fileOut = storage.openCheck(filenameOut, "w", True) | 110 fileOut = utils.openCheck(filenameOut, "w", True) |
| 111 | 111 |
| 112 lines = storage.getLines(fileIn) | 112 lines = storage.getLines(fileIn) |
| 113 trajNum = 0 | 113 trajNum = 0 |
| 114 while (lines != []): | 114 while (lines != []): |
| 115 if keepTrajectory(trajNum, lines): | 115 if keepTrajectory(trajNum, lines): |
| 123 fileOut.close() | 123 fileOut.close() |
| 124 | 124 |
| 125 def loadTrajectories(filename, nObjects = -1): | 125 def loadTrajectories(filename, nObjects = -1): |
| 126 '''Loads trajectories''' | 126 '''Loads trajectories''' |
| 127 | 127 |
| 128 file = storage.openCheck(filename) | 128 file = utils.openCheck(filename) |
| 129 if (not file): | 129 if (not file): |
| 130 return [] | 130 return [] |
| 131 | 131 |
| 132 objects = [] | 132 objects = [] |
| 133 objNum = 0 | 133 objNum = 0 |
| 175 | 175 |
| 176 def loadInteractions(filename, nInteractions = -1): | 176 def loadInteractions(filename, nInteractions = -1): |
| 177 'Loads interactions from the old UBC traffic event format' | 177 'Loads interactions from the old UBC traffic event format' |
| 178 from events import Interaction | 178 from events import Interaction |
| 179 from indicators import SeverityIndicator | 179 from indicators import SeverityIndicator |
| 180 file = storage.openCheck(filename) | 180 file = utils.openCheck(filename) |
| 181 if (not file): | 181 if (not file): |
| 182 return [] | 182 return [] |
| 183 | 183 |
| 184 interactions = [] | 184 interactions = [] |
| 185 interactionNum = 0 | 185 interactionNum = 0 |
| 204 return interactions | 204 return interactions |
| 205 | 205 |
| 206 def loadCollisionPoints(filename, nPoints = -1): | 206 def loadCollisionPoints(filename, nPoints = -1): |
| 207 '''Loads collision points and returns a dict | 207 '''Loads collision points and returns a dict |
| 208 with keys as a pair of the numbers of the two interacting objects''' | 208 with keys as a pair of the numbers of the two interacting objects''' |
| 209 file = storage.openCheck(filename) | 209 file = utils.openCheck(filename) |
| 210 if (not file): | 210 if (not file): |
| 211 return [] | 211 return [] |
| 212 | 212 |
| 213 points = {} | 213 points = {} |
| 214 num = 0 | 214 num = 0 |
