Mercurial Hosting > traffic-intelligence
changeset 1101:e23828659a66
bug fixes
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 22 Feb 2019 17:22:04 -0500 |
parents | 1e833fd8490d |
children | cdf1773ba89e |
files | trafficintelligence/ubc_utils.py |
diffstat | 1 files changed, 25 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
diff -r 1e833fd8490d -r e23828659a66 trafficintelligence/ubc_utils.py --- a/trafficintelligence/ubc_utils.py Wed Feb 20 16:16:19 2019 -0500 +++ b/trafficintelligence/ubc_utils.py Fri Feb 22 17:22:04 2019 -0500 @@ -1,7 +1,7 @@ #! /usr/bin/env python '''Various utilities to load data saved by the UBC tool(s)''' -from trafficintelligence import utils, events, storage +from trafficintelligence import utils, events, storage, indicators from trafficintelligence.moving import MovingObject, TimeInterval, Trajectory @@ -60,10 +60,10 @@ infile = utils.openCheck(inFilename) outfile = utils.openCheck(outFilename,'w') - if (inFilename.find('features') >= 0) or (not infile) or (not outfile): + if (inFilename.find('features') >= 0) or infile is None or outfile is None: return - lines = storage.getLines(infile) + lines = utils.getLines(infile) objNum = 0 # in inFilename while lines != []: # find object in objects (index i) @@ -80,7 +80,7 @@ outfile.write(utils.delimiterChar+'\n') # next object objNum += 1 - lines = storage.getLines(infile) + lines = utils.getLines(infile) print('read {0} objects'.format(objNum)) @@ -89,7 +89,7 @@ fileIn = utils.openCheck(filenameIn, 'r', True) fileOut = utils.openCheck(filenameOut, "w", True) - lines = storage.getLines(fileIn) + lines = utils.getLines(fileIn) trajNum = 0 while (lines != []): modifiedLines = modifyLines(trajNum, lines) @@ -97,7 +97,7 @@ for l in modifiedLines: fileOut.write(l+"\n") fileOut.write(utils.delimiterChar+"\n") - lines = storage.getLines(fileIn) + lines = utils.getLines(fileIn) trajNum += 1 fileIn.close() @@ -109,14 +109,14 @@ fileIn = utils.openCheck(filenameIn, 'r', True) fileOut = utils.openCheck(filenameOut, "w", True) - lines = storage.getLines(fileIn) + lines = utils.getLines(fileIn) trajNum = 0 while (lines != []): if keepTrajectory(trajNum, lines): for l in lines: fileOut.write(l+"\n") fileOut.write(utils.delimiterChar+"\n") - lines = storage.getLines(fileIn) + lines = utils.getLines(fileIn) trajNum += 1 fileIn.close() @@ -125,14 +125,14 @@ def loadTrajectories(filename, nObjects = -1): '''Loads trajectories''' - file = utils.openCheck(filename) - if (not file): + f = utils.openCheck(filename) + if f is None: return [] objects = [] objNum = 0 objectType = getFileType(filename) - lines = storage.getLines(file) + lines = utils.getLines(f) while (lines != []) and ((nObjects<0) or (objNum<nObjects)): l = lines[0].split(' ') parsedLine = [int(n) for n in l[:4]] @@ -162,9 +162,9 @@ else: print("Error two lines of data for feature {}".format(f.num)) - lines = storage.getLines(file) + lines = utils.getLines(f) - file.close() + f.close() return objects def getFeatureNumbers(objects): @@ -175,18 +175,16 @@ def loadInteractions(filename, nInteractions = -1): 'Loads interactions from the old UBC traffic event format' - from events import Interaction - from indicators import SeverityIndicator - file = utils.openCheck(filename) - if (not file): + f = utils.openCheck(filename) + if f is None: return [] interactions = [] interactionNum = 0 - lines = storage.getLines(file) + lines = utils.getLines(f) while (lines != []) and ((nInteractions<0) or (interactionNum<nInteractions)): parsedLine = [int(n) for n in lines[0].split(' ')] - inter = Interaction(interactionNum, TimeInterval(parsedLine[1],parsedLine[2]), parsedLine[3], parsedLine[4], categoryNum = parsedLine[5]) + inter = events.Interaction(interactionNum, TimeInterval(parsedLine[1],parsedLine[2]), parsedLine[3], parsedLine[4], categoryNum = parsedLine[5]) indicatorFrameNums = [int(n) for n in lines[1].split(' ')] for indicatorNum,line in enumerate(lines[2:]): @@ -194,25 +192,25 @@ for i,v in enumerate([float(n) for n in line.split(' ')]): if not ignoredValue[indicatorNum] or v != ignoredValue[indicatorNum]: values[indicatorFrameNums[i]] = v - inter.addIndicator(SeverityIndicator(severityIndicatorNames[indicatorNum], values, None, mostSevereIsMax[indicatorNum])) + inter.addIndicator(indicators.SeverityIndicator(severityIndicatorNames[indicatorNum], values, None, mostSevereIsMax[indicatorNum])) interactions.append(inter) interactionNum+=1 - lines = storage.getLines(file) + lines = utils.getLines(f) - file.close() + f.close() return interactions def loadCollisionPoints(filename, nPoints = -1): '''Loads collision points and returns a dict with keys as a pair of the numbers of the two interacting objects''' - file = utils.openCheck(filename) - if (not file): + f = utils.openCheck(filename) + if f is None: return [] points = {} num = 0 - lines = storage.getLines(file) + lines = utils.getLines(f) while (lines != []) and ((nPoints<0) or (num<nPoints)): parsedLine = [int(n) for n in lines[0].split(' ')] protagonistNums = (parsedLine[0], parsedLine[1]) @@ -220,7 +218,7 @@ [float(n) for n in lines[2].split(' ')]] num+=1 - lines = storage.getLines(file) + lines = utils.getLines(f) - file.close() + f.close() return points