Mercurial Hosting > traffic-intelligence
diff python/storage.py @ 344:14a2405f54f8
slight modification to safety analysis and generalized script to delete computed data (objects and interactions)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 21 Jun 2013 17:32:57 -0400 |
parents | 74e437ab5f11 |
children | 2aed569f39e7 |
line wrap: on
line diff
--- a/python/storage.py Fri Jun 21 15:28:59 2013 -0400 +++ b/python/storage.py Fri Jun 21 17:32:57 2013 -0400 @@ -56,9 +56,6 @@ connection.commit() connection.close() -def printDBError(error): - print('DB Error: {0}'.format(error)) - def loadPrototypeMatchIndexesFromSqlite(filename): """ This function loads the prototypes table in the database of name <filename>. @@ -72,7 +69,7 @@ try: cursor.execute('SELECT * from prototypes order by prototype_id, trajectory_id_matched') except sqlite3.OperationalError as error: - printDBError(error) + utils.printDBError(error) return [] for row in cursor: @@ -115,7 +112,7 @@ else: print('no trajectory type was chosen') except sqlite3.OperationalError as error: - printDBError(error) + utils.printDBError(error) return [] objId = -1 @@ -185,22 +182,23 @@ obj.userType = userTypes[obj.getNum()] except sqlite3.OperationalError as error: - printDBError(error) + utils.printDBError(error) return [] connection.close() return objects -def removeObjectsFromSqlite(filename): - 'Removes the objects and object_features tables in the filename' +def removeFromSqlite(filename, dataType): + 'Removes some tables in the filename depending on type of data' connection = sqlite3.connect(filename) - utils.dropTables(connection, ['objects', 'objects_features']) + if dataType == 'object': + utils.dropTables(connection, ['objects', 'objects_features']) + elif dataType == 'interaction': + utils.dropTables(connection, ['interactions', 'indicators']) + else: + print('Unknown data type {} to delete from database'.format(dataType)) connection.close() -def deleteIndicators(filename): - 'Deletes all indicator data in db' - pass - def createInteractionTable(cursor): cursor.execute('CREATE TABLE IF NOT EXISTS interactions (id INTEGER PRIMARY KEY, object_id1 INTEGER, object_id2 INTEGER, first_frame_number INTEGER, last_frame_number INTEGER, FOREIGN KEY(object_id1) REFERENCES objects(id), FOREIGN KEY(object_id2) REFERENCES objects(id))') @@ -222,7 +220,7 @@ for inter in interactions: saveInteraction(cursor, inter) except sqlite3.OperationalError as error: - printDBError(error) + utils.printDBError(error) connection.commit() connection.close() @@ -245,7 +243,7 @@ if indicator != None: saveIndicator(cursor, inter.getNum(), indicator) except sqlite3.OperationalError as error: - printDBError(error) + utils.printDBError(error) connection.commit() connection.close() @@ -284,7 +282,7 @@ interactions.append(events.Interaction(interactionNum, moving.TimeInterval(row[3],row[4]), roadUserNumbers[0], roadUserNumbers[1])) interactions[-1].indicators = tmpIndicators except sqlite3.OperationalError as error: - printDBError(error) + utils.printDBError(error) return [] connection.close() return interactions