Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/storage.py @ 1258:3d6ee243d5c0
update to add curvilinear positions
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 07 Apr 2024 22:09:40 -0400 |
parents | e59a0a475a0a |
children | 28aeec1f2788 |
comparison
equal
deleted
inserted
replaced
1257:e59a0a475a0a | 1258:3d6ee243d5c0 |
---|---|
355 printDBError(error) | 355 printDBError(error) |
356 return None | 356 return None |
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)''' | 360 from a database to an existing MovingObject dict (indexed by each objects's num) or list''' |
361 if type(objects) == list: | |
362 _objects = {obj.getNum(): obj for obj in objects} | |
363 elif type(objects) == dict: | |
364 _objects = objects | |
365 else: | |
366 print('objects should be a list of dictionary of objects indexed by their num') | |
367 return None | |
368 | |
361 with sqlite3.connect(filename) as connection: | 369 with sqlite3.connect(filename) as connection: |
362 cursor = connection.cursor() | 370 cursor = connection.cursor() |
363 | 371 |
364 try: | 372 try: |
365 cursor.execute('SELECT * from curvilinear_positions order by trajectory_id, frame_number') | 373 cursor.execute('SELECT * from curvilinear_positions order by trajectory_id, frame_number') |
370 missingObjectNumbers = [] | 378 missingObjectNumbers = [] |
371 objNum = None | 379 objNum = None |
372 for row in cursor: | 380 for row in cursor: |
373 if objNum != row[0]: | 381 if objNum != row[0]: |
374 objNum = row[0] | 382 objNum = row[0] |
375 if objNum in objects: | 383 if objNum in _objects: |
376 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() | 384 _objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() |
377 else: | 385 else: |
378 missingObjectNumbers.append(objNum) | 386 missingObjectNumbers.append(objNum) |
379 if objNum in objects: | 387 if objNum in _objects: |
380 objects[objNum].curvilinearPositions.addPositionSYL(row[2],row[3],row[4]) | 388 objects[objNum].curvilinearPositions.addPositionSYL(row[2],row[3],row[4]) |
381 if len(missingObjectNumbers) > 0: | 389 if len(missingObjectNumbers) > 0: |
382 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)) |
383 | 391 |
384 def saveTrajectoriesToTable(connection, objects, trajectoryType): | 392 def saveTrajectoriesToTable(connection, objects, trajectoryType): |