Mercurial > hg > nsaunier > traffic-intelligence
comparison python/ubc_utils.py @ 51:3aed17fc468d
utils to save object types
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Sat, 25 Sep 2010 11:38:42 -0400 |
| parents | 8aed225f71d8 |
| children | 441c8387f34f |
comparison
equal
deleted
inserted
replaced
| 50:7b06d649122b | 51:3aed17fc468d |
|---|---|
| 3 | 3 |
| 4 import utils | 4 import utils |
| 5 from moving import MovingObject, TimeInterval, Trajectory | 5 from moving import MovingObject, TimeInterval, Trajectory |
| 6 | 6 |
| 7 __metaclass__ = type | 7 __metaclass__ = type |
| 8 | |
| 9 userTypeNames = ['car', | |
| 10 'pedestrian', | |
| 11 'twowheels', | |
| 12 'bus' | |
| 13 'truck'] | |
| 8 | 14 |
| 9 def getFileType(s): | 15 def getFileType(s): |
| 10 filePrefix = utils.removeExtension(s) | 16 filePrefix = utils.removeExtension(s) |
| 11 i = filePrefix.rfind('-') | 17 i = filePrefix.rfind('-') |
| 12 if i>0: | 18 if i>0: |
| 18 '''The program saves the objects, | 24 '''The program saves the objects, |
| 19 by just copying the corresponding trajectory and velocity data | 25 by just copying the corresponding trajectory and velocity data |
| 20 from the inFilename, and saving the characteristics in objects (first line) | 26 from the inFilename, and saving the characteristics in objects (first line) |
| 21 into outFilename''' | 27 into outFilename''' |
| 22 infile = utils.openCheck(inFilename) | 28 infile = utils.openCheck(inFilename) |
| 23 outfile = utils.openCheck(outFilename) | 29 outfile = utils.openCheck(outFilename,'w') |
| 24 | 30 |
| 25 if (not infile) | (not outfile): | 31 if (inFilename.find('features') >= 0) or (not infile) or (not outfile): |
| 26 return | 32 return |
| 27 | 33 |
| 28 lines = utils.getLines(infile) | 34 lines = utils.getLines(infile) |
| 29 objNum = 0 | 35 objNum = 0 |
| 30 while lines != []: | 36 while lines != []: |
| 31 i = 0 | 37 i = 0 |
| 32 while (i<len(objects)) and (objects[i].num != objNum): | 38 while (i<len(objects)) and (objects[i].num != objNum): |
| 33 i+=1 | 39 i+=1 |
| 34 if i<len(objects): | 40 if i<len(objects): |
| 35 l = lines[0].split(' ') | 41 l = lines[0].split(' ') |
| 36 outfile.write() | 42 l[3] = str(objects[i].userType) |
| 43 outfile.write(' '.join(l)+'\n') | |
| 44 for l in lines[1:]: | |
| 45 outfile.write(l+'\n') | |
| 46 outfile.write(utils.delimiterChar+'\n') | |
| 37 # next object | 47 # next object |
| 38 objNum += 1 | 48 objNum += 1 |
| 39 lines = utils.getLines(infile) | 49 lines = utils.getLines(infile) |
| 50 | |
| 51 print('read {0} objects'.format(objNum)) | |
| 40 | 52 |
| 41 def loadTrajectories(filename, nObjects = -1): | 53 def loadTrajectories(filename, nObjects = -1): |
| 42 '''Loads trajectories''' | 54 '''Loads trajectories''' |
| 43 | 55 |
| 44 file = utils.openCheck(filename) | 56 file = utils.openCheck(filename) |
