Mercurial Hosting > traffic-intelligence
changeset 752:14963a9c3b09 dev
debug finished
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 28 Oct 2015 23:37:25 -0400 |
parents | 79405a938407 |
children | 3d48e34db846 |
files | python/storage.py |
diffstat | 1 files changed, 21 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/python/storage.py Wed Oct 28 23:22:57 2015 -0400 +++ b/python/storage.py Wed Oct 28 23:37:25 2015 -0400 @@ -757,7 +757,8 @@ Objects positions will be considered only after warmUpLastInstant (if the object has no such position, it won't be loaded) - Assumed to be sorted over time''' + Assumed to be sorted over time + Warning: if reading from SQLite a limited number of objects, objectNumbers will be the maximum object id''' objects = {} # dictionary of objects index by their id if usePandas: @@ -776,7 +777,7 @@ # positions should be rounded to nDecimals decimals only objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory(S = npround(tmp['POS'].tolist(), nDecimals), Y = npround(tmp['POSLAT'].tolist(), nDecimals), lanes = tmp['LANE'].tolist()) if objectNumbers is not None and objectNumbers > 0 and len(objects) >= objectNumbers: - break + objects.values() else: if filename.endswith(".fzp"): inputfile = openCheck(filename, quitting = True) @@ -804,20 +805,24 @@ if objectNumbers is not None: queryStatement += ' WHERE trajectory_id '+getObjectCriteria(objectNumbers) queryStatement += ' ORDER BY trajectory_id, t' - for row in cursor: - objNum = row[1] - instant = row[0]*simulationStepsPerTimeUnit - s = row[4] - y = row[5] - lane = '{}_{}'.format(row[2], row[3]) - if objNum not in objects: - if warmUpLastInstant is None or instant >= warmUpLastInstant: - if objectNumbers is None or len(objects) < objectNumbers: - objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) - objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() - if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects: - objects[objNum].timeInterval.last = instant - objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) + try: + cursor.execute(queryStatement) + for row in cursor: + objNum = row[1] + instant = row[0]*simulationStepsPerTimeUnit + s = row[4] + y = row[5] + lane = '{}_{}'.format(row[2], row[3]) + if objNum not in objects: + if warmUpLastInstant is None or instant >= warmUpLastInstant: + if objectNumbers is None or len(objects) < objectNumbers: + objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) + objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() + if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects: + objects[objNum].timeInterval.last = instant + objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) + except sqlite3.OperationalError as error: + printDBError(error) else: print("File type of "+filename+" not supported (only .sqlite and .fzp files)") return objects.values()