Mercurial Hosting > traffic-intelligence
diff python/storage.py @ 636:3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 24 Mar 2015 18:11:28 +0100 |
parents | 977407c9f815 |
children | 932f96c89212 |
line wrap: on
line diff
--- a/python/storage.py Tue Mar 24 14:17:12 2015 +0100 +++ b/python/storage.py Tue Mar 24 18:11:28 2015 +0100 @@ -345,18 +345,18 @@ for row in cursor: if row[0] != objId: objId = row[0] - if obj != None and obj.length() == obj.positions.length(): + if obj is not None and obj.length() == obj.positions.length(): objects.append(obj) - elif obj != None: + elif obj is not None: print('Object {} is missing {} positions'.format(obj.getNum(), int(obj.length())-obj.positions.length())) obj = moving.MovingObject(row[0], timeInterval = moving.TimeInterval(row[1], row[1]), positions = moving.Trajectory([[row[2]],[row[3]]])) else: obj.timeInterval.last = row[1] obj.positions.addPositionXY(row[2],row[3]) - if obj != None and obj.length() == obj.positions.length(): + if obj is not None and obj.length() == obj.positions.length(): objects.append(obj) - elif obj != None: + elif obj is not None: print('Object {} is missing {} positions'.format(obj.getNum(), int(obj.length())-obj.positions.length())) return objects @@ -498,7 +498,7 @@ saveInteraction(cursor, inter) for indicatorName in indicatorNames: indicator = inter.getIndicator(indicatorName) - if indicator != None: + if indicator is not None: saveIndicator(cursor, inter.getNum(), indicator) except sqlite3.OperationalError as error: printDBError(error) @@ -652,7 +652,7 @@ finally: self.sechead = None else: return self.fp.readline() -def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1, warmUpLastInstant = None): +def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1, warmUpLastInstant = None, usePandas = False): '''Reads data from VISSIM .fzp trajectory file simulationStepsPerTimeUnit is the number of simulation steps per unit of time used by VISSIM for example, there seems to be 5 simulation steps per simulated second in VISSIM, @@ -663,30 +663,36 @@ objects = {} # dictionary of objects index by their id firstInstants = {} - inputfile = openCheck(filename, quitting = True) + if usePandas: + from pandas import read_csv + data = read_csv(filename, delimiter=';', skiprows=16) + print('Work in progress') + return [] + else: + inputfile = openCheck(filename, quitting = True) - # data = pd.read_csv(filename, skiprows=15, delimiter=';') - # skip header: 15 lines + 1 - line = readline(inputfile, '*$') - while len(line) > 0:#for line in inputfile: - data = line.strip().split(';') - objNum = int(data[1]) - instant = int(float(data[0])*simulationStepsPerTimeUnit) - s = float(data[4]) - y = float(data[5]) - lane = data[2]+'_'+data[3] - if objNum not in firstInstants: - firstInstants[objNum] = instant - if warmUpLastInstant == None or firstInstants[objNum] >= warmUpLastInstant: - if nObjects < 0 or len(objects) < nObjects: - objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) - objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() - if (warmUpLastInstant == None or firstInstants[objNum] >= warmUpLastInstant) and objNum in objects: - objects[objNum].timeInterval.last = instant - objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) + # data = pd.read_csv(filename, skiprows=15, delimiter=';') + # skip header: 15 lines + 1 line = readline(inputfile, '*$') + while len(line) > 0:#for line in inputfile: + data = line.strip().split(';') + objNum = int(data[1]) + instant = int(float(data[0])*simulationStepsPerTimeUnit) + s = float(data[4]) + y = float(data[5]) + lane = data[2]+'_'+data[3] + if objNum not in firstInstants: + firstInstants[objNum] = instant + if warmUpLastInstant is None or firstInstants[objNum] >= warmUpLastInstant: + if nObjects < 0 or len(objects) < nObjects: + objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) + objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() + if (warmUpLastInstant is None or firstInstants[objNum] >= warmUpLastInstant) and objNum in objects: + objects[objNum].timeInterval.last = instant + objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) + line = readline(inputfile, '*$') - return objects.values() + return objects.values() def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1): '''Reads data from the trajectory data provided by NGSIM project @@ -776,7 +782,7 @@ for i in xrange(int(obj.length())): p1 = positions[i] s = '{},{},{},{}'.format(obj.num,timeInterval[i],p1.x,p1.y) - if curvilinearPositions != None: + if curvilinearPositions is not None: p2 = curvilinearPositions[i] s += ',{},{}'.format(p2[0],p2[1]) f.write(s+'\n') @@ -844,7 +850,7 @@ self.useFeaturesForPrediction = config.getboolean(self.sectionHeader, 'use-features-prediction') def __init__(self, filename = None): - if filename != None: + if filename is not None: self.loadConfigFile(filename) class SceneParameters: