comparison trafficintelligence/storage.py @ 1279:9562f5e8edf8

corrected bug on adding curvilinear trajectories
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 03 Jul 2024 15:10:47 -0400
parents 8e61ff3cd503
children 76f5693b530c
comparison
equal deleted inserted replaced
1278:8e61ff3cd503 1279:9562f5e8edf8
357 357
358 def addCurvilinearTrajectoriesFromSqlite(filename, objects): 358 def addCurvilinearTrajectoriesFromSqlite(filename, objects):
359 '''Adds curvilinear positions (s_coordinate, y_coordinate, lane) 359 '''Adds curvilinear positions (s_coordinate, y_coordinate, lane)
360 from a database to an existing MovingObject dict (indexed by each objects's num) or list''' 360 from a database to an existing MovingObject dict (indexed by each objects's num) or list'''
361 if type(objects) == list: 361 if type(objects) == list:
362 _objects = {obj.getNum(): obj for obj in objects} 362 tmpobjects = {obj.getNum(): obj for obj in objects}
363 elif type(objects) == dict: 363 elif type(objects) == dict:
364 _objects = objects 364 tmpobjects = objects
365 else: 365 else:
366 print('objects should be a list of dictionary of objects indexed by their num') 366 print('objects should be a list of dictionary of objects indexed by their num')
367 return None 367 return None
368 368
369 with sqlite3.connect(filename) as connection: 369 with sqlite3.connect(filename) as connection:
378 missingObjectNumbers = [] 378 missingObjectNumbers = []
379 objNum = None 379 objNum = None
380 for row in cursor: 380 for row in cursor:
381 if objNum != row[0]: 381 if objNum != row[0]:
382 objNum = row[0] 382 objNum = row[0]
383 if objNum in _objects: 383 if objNum in tmpobjects:
384 _objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() 384 tmpobjects[objNum].curvilinearPositions = moving.CurvilinearTrajectory()
385 else: 385 else:
386 missingObjectNumbers.append(objNum) 386 missingObjectNumbers.append(objNum)
387 if objNum in _objects: 387 if objNum in tmpobjects:
388 objects[objNum].curvilinearPositions.addPositionSYL(row[2],row[3],row[4]) 388 tmpobjects[objNum].curvilinearPositions.addPositionSYL(row[2],row[3],row[4])
389 if len(missingObjectNumbers) > 0: 389 if len(missingObjectNumbers) > 0:
390 print('List of missing objects to attach corresponding curvilinear trajectories: {}'.format(missingObjectNumbers)) 390 print('List of missing objects to attach corresponding curvilinear trajectories: {}'.format(missingObjectNumbers))
391 391
392 def saveTrajectoriesToTable(connection, objects, trajectoryType): 392 def saveTrajectoriesToTable(connection, objects, trajectoryType):
393 'Saves trajectories in table tableName' 393 'Saves trajectories in table tableName'