Mercurial Hosting > traffic-intelligence
diff 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 |
line wrap: on
line diff
--- a/trafficintelligence/storage.py Wed Jun 20 12:04:22 2018 -0400 +++ b/trafficintelligence/storage.py Wed Jun 20 16:48:20 2018 -0400 @@ -22,6 +22,10 @@ 'object': 'objects', 'objectfeatures': 'positions'} +assignmentTableNames = {'feature':'positions', + 'object': 'objects', + 'objectfeatures': 'positions'} + ######################### # Sqlite ######################### @@ -52,7 +56,7 @@ elif dataType == 'pois': dropTables(connection, ['gaussians2d', 'objects_pois']) elif dataType == 'prototype': - dropTables(connection, ['prototypes', 'objects_prototypes']) + dropTables(connection, ['prototypes', 'objects_prototypes', 'features_prototypes']) else: print('Unknown data type {} to delete from database'.format(dataType)) else: @@ -589,7 +593,7 @@ printDBError(error) connection.commit() -def savePrototypeAssignmentsToSqlite(filename, objects, objectType, labels, prototypes): +def savePrototypeAssignmentsToSqlite(filename, objectNumbers, objectType, labels, prototypes): with sqlite3.connect(filename) as connection: cursor = connection.cursor() try: @@ -600,9 +604,10 @@ tableName = 'objects_prototypes' objectIdColumnName = 'object_id' 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))') - for obj, label in zip(objects, labels): - proto = prototypes[label] - cursor.execute('INSERT INTO objects_prototypes VALUES(?,?,?,?)', (obj.getNum(), proto.getFilename(), proto.getNum(), proto.getTrajectoryType())) + for objNum, label in zip(objectNumbers, labels): + if label >=0: + proto = prototypes[label] + cursor.execute('INSERT INTO '+tableName+' VALUES(?,?,?,?)', (objNum, proto.getFilename(), proto.getNum(), proto.getTrajectoryType())) except sqlite3.OperationalError as error: printDBError(error) connection.commit()