Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/storage.py @ 1035:933588568bec
major update to learn motion pattern, see program description
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 20 Jun 2018 16:48:20 -0400 |
parents | 8ffb3ae9f3d2 |
children | 6a6c37eb3a74 |
comparison
equal
deleted
inserted
replaced
1034:4069d8545922 | 1035:933588568bec |
---|---|
19 'truck':3} | 19 'truck':3} |
20 | 20 |
21 tableNames = {'feature':'positions', | 21 tableNames = {'feature':'positions', |
22 'object': 'objects', | 22 'object': 'objects', |
23 'objectfeatures': 'positions'} | 23 'objectfeatures': 'positions'} |
24 | |
25 assignmentTableNames = {'feature':'positions', | |
26 'object': 'objects', | |
27 'objectfeatures': 'positions'} | |
24 | 28 |
25 ######################### | 29 ######################### |
26 # Sqlite | 30 # Sqlite |
27 ######################### | 31 ######################### |
28 | 32 |
50 elif dataType == 'bb': | 54 elif dataType == 'bb': |
51 dropTables(connection, ['bounding_boxes']) | 55 dropTables(connection, ['bounding_boxes']) |
52 elif dataType == 'pois': | 56 elif dataType == 'pois': |
53 dropTables(connection, ['gaussians2d', 'objects_pois']) | 57 dropTables(connection, ['gaussians2d', 'objects_pois']) |
54 elif dataType == 'prototype': | 58 elif dataType == 'prototype': |
55 dropTables(connection, ['prototypes', 'objects_prototypes']) | 59 dropTables(connection, ['prototypes', 'objects_prototypes', 'features_prototypes']) |
56 else: | 60 else: |
57 print('Unknown data type {} to delete from database'.format(dataType)) | 61 print('Unknown data type {} to delete from database'.format(dataType)) |
58 else: | 62 else: |
59 print('{} does not exist'.format(filename)) | 63 print('{} does not exist'.format(filename)) |
60 | 64 |
587 cursor.execute('UPDATE prototypes SET nmatchings = {} WHERE prototype_filename = \"{}\" AND prototype_id = {} AND trajectory_type = \"{}\"'.format(nMatchings, p.getFilename(), p.getNum(), p.getTrajectoryType())) | 591 cursor.execute('UPDATE prototypes SET nmatchings = {} WHERE prototype_filename = \"{}\" AND prototype_id = {} AND trajectory_type = \"{}\"'.format(nMatchings, p.getFilename(), p.getNum(), p.getTrajectoryType())) |
588 except sqlite3.OperationalError as error: | 592 except sqlite3.OperationalError as error: |
589 printDBError(error) | 593 printDBError(error) |
590 connection.commit() | 594 connection.commit() |
591 | 595 |
592 def savePrototypeAssignmentsToSqlite(filename, objects, objectType, labels, prototypes): | 596 def savePrototypeAssignmentsToSqlite(filename, objectNumbers, objectType, labels, prototypes): |
593 with sqlite3.connect(filename) as connection: | 597 with sqlite3.connect(filename) as connection: |
594 cursor = connection.cursor() | 598 cursor = connection.cursor() |
595 try: | 599 try: |
596 if objectType == 'feature': | 600 if objectType == 'feature': |
597 tableName = 'features_prototypes' | 601 tableName = 'features_prototypes' |
598 objectIdColumnName = 'trajectory_id' | 602 objectIdColumnName = 'trajectory_id' |
599 elif objectType == 'object': | 603 elif objectType == 'object': |
600 tableName = 'objects_prototypes' | 604 tableName = 'objects_prototypes' |
601 objectIdColumnName = 'object_id' | 605 objectIdColumnName = 'object_id' |
602 cursor.execute('CREATE TABLE IF NOT EXISTS '+tableName+' ('+objectIdColumnName+' INTEGER, prototype_filename VARCHAR, prototype_id INTEGER, trajectory_type VARCHAR CHECK (trajectory_type IN (\"feature\", \"object\")), PRIMARY KEY('+objectIdColumnName+', prototype_filename, prototype_id, trajectory_type))') | 606 cursor.execute('CREATE TABLE IF NOT EXISTS '+tableName+' ('+objectIdColumnName+' INTEGER, prototype_filename VARCHAR, prototype_id INTEGER, trajectory_type VARCHAR CHECK (trajectory_type IN (\"feature\", \"object\")), PRIMARY KEY('+objectIdColumnName+', prototype_filename, prototype_id, trajectory_type))') |
603 for obj, label in zip(objects, labels): | 607 for objNum, label in zip(objectNumbers, labels): |
604 proto = prototypes[label] | 608 if label >=0: |
605 cursor.execute('INSERT INTO objects_prototypes VALUES(?,?,?,?)', (obj.getNum(), proto.getFilename(), proto.getNum(), proto.getTrajectoryType())) | 609 proto = prototypes[label] |
610 cursor.execute('INSERT INTO '+tableName+' VALUES(?,?,?,?)', (objNum, proto.getFilename(), proto.getNum(), proto.getTrajectoryType())) | |
606 except sqlite3.OperationalError as error: | 611 except sqlite3.OperationalError as error: |
607 printDBError(error) | 612 printDBError(error) |
608 connection.commit() | 613 connection.commit() |
609 | 614 |
610 def loadPrototypesFromSqlite(filename, withTrajectories = True): | 615 def loadPrototypesFromSqlite(filename, withTrajectories = True): |