# HG changeset patch # User Francois Belisle # Date 1338919726 14400 # Node ID 746d02cea65fd4cba1e20883262c1b733922b6c3 # Parent d9855499fc8837b442452a4b1a497eaa55f46545 Added function to read Prototype indexes matches. diff -r d9855499fc88 -r 746d02cea65f python/storage.py --- a/python/storage.py Tue Jun 05 13:12:19 2012 -0400 +++ b/python/storage.py Tue Jun 05 14:08:46 2012 -0400 @@ -28,7 +28,6 @@ #creation de la table schema = "CREATE TABLE \"trajectories\"(trajectory_id INTEGER,frame_number INTEGER, x_coordinate REAL, y_coordinate REAL, PRIMARY KEY(trajectory_id, frame_number))" cursor.execute(schema) - trajectory_id = 0 frame_number = 0 if trajectoryType == 'feature': @@ -48,6 +47,39 @@ features = loadTrajectoriesFromSqlite("/home/francois/Unison/École/12Été/CRSNG/Data/prototypes.sqlite",'feature',-1) writeTrajectoriesToSqlite(features, "/home/francois/Unison/École/12Été/CRSNG/TAAM-Experiments/resultats/testWrite.sqlite", 'feature') +def loadPrototypeMatchIndexesFromSqlite(filename): + """ + This function loads the prototypes table in the database of name . + It returns a list of tuples representing matching ids : [(prototype_id, matched_trajectory_id),...] + """ + matched_indexes = [] + + import sqlite3 + connection = sqlite3.connect(filename) # add test if it open + cursor = connection.cursor() + + try: + cursor.execute('SELECT * from prototypes order by prototype_id, trajectory_id_matched') + except sqlite3.OperationalError: + return matched_indexes + + for row in cursor: + matched_indexes.append((row[0],row[1])) + return matched_indexes + +def testloadPrototypeMatchIndexesFromSqlite(): + empty_list = loadPrototypeMatchIndexesFromSqlite("bidon") + if empty_list == []: + print "Empty list test Ok" + + matches=loadPrototypeMatchIndexesFromSqlite("/home/francois/Unison/École/12Été/CRSNG/TAAM-Experiments/resultats/prototypes-with-matches.sqlite") + if len(matches) == 66: + print "Matches test Ok" + return matches + + + + def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = -1): '''Loads nObjects or the indices in objectNumbers from the database