changeset 209:746d02cea65f

Added function to read Prototype indexes matches.
author Francois Belisle <belisle.francois@gmail.com>
date Tue, 05 Jun 2012 14:08:46 -0400
parents d9855499fc88
children e841ba9981e2
files python/storage.py
diffstat 1 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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 <filename>.
+    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