Mercurial Hosting > traffic-intelligence
changeset 1261:28aeec1f2788
merged
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 15 Apr 2024 11:31:33 -0400 |
parents | 158eee1aeb21 (current diff) 3d6ee243d5c0 (diff) |
children | f10e84505443 |
files | trafficintelligence/storage.py |
diffstat | 1 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/trafficintelligence/storage.py Mon Apr 15 11:29:31 2024 -0400 +++ b/trafficintelligence/storage.py Mon Apr 15 11:31:33 2024 -0400 @@ -357,7 +357,15 @@ def addCurvilinearTrajectoriesFromSqlite(filename, objects): '''Adds curvilinear positions (s_coordinate, y_coordinate, lane) - from a database to an existing MovingObject dict (indexed by each objects's num)''' + from a database to an existing MovingObject dict (indexed by each objects's num) or list''' + if type(objects) == list: + _objects = {obj.getNum(): obj for obj in objects} + elif type(objects) == dict: + _objects = objects + else: + print('objects should be a list of dictionary of objects indexed by their num') + return None + with sqlite3.connect(filename) as connection: cursor = connection.cursor() @@ -372,11 +380,11 @@ for row in cursor: if objNum != row[0]: objNum = row[0] - if objNum in objects: - objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() + if objNum in _objects: + _objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() else: missingObjectNumbers.append(objNum) - if objNum in objects: + if objNum in _objects: objects[objNum].curvilinearPositions.addPositionSYL(row[2],row[3],row[4]) if len(missingObjectNumbers) > 0: print('List of missing objects to attach corresponding curvilinear trajectories: {}'.format(missingObjectNumbers))