comparison python/storage.py @ 211:ada6e8fbe4c6

2 Changes : 1) Modified storage.py to read prototype and matching trajectory indexes from db 2) Modified moving.py to give draw function **kwargs option (to matplotlib.plot)
author Francois Belisle <belisle.francois@gmail.com>
date Wed, 06 Jun 2012 13:24:04 -0400
parents 746d02cea65f
children ce44605f888a
comparison
equal deleted inserted replaced
210:e841ba9981e2 211:ada6e8fbe4c6
53 It returns a list of tuples representing matching ids : [(prototype_id, matched_trajectory_id),...] 53 It returns a list of tuples representing matching ids : [(prototype_id, matched_trajectory_id),...]
54 """ 54 """
55 matched_indexes = [] 55 matched_indexes = []
56 56
57 import sqlite3 57 import sqlite3
58 connection = sqlite3.connect(filename) # add test if it open 58 connection = sqlite3.connect(filename)
59 cursor = connection.cursor() 59 cursor = connection.cursor()
60 60
61 try: 61 try:
62 cursor.execute('SELECT * from prototypes order by prototype_id, trajectory_id_matched') 62 cursor.execute('SELECT * from prototypes order by prototype_id, trajectory_id_matched')
63 except sqlite3.OperationalError: 63 except sqlite3.OperationalError:
64 return matched_indexes 64 return matched_indexes
65 65
66 for row in cursor: 66 for row in cursor:
67 matched_indexes.append((row[0],row[1])) 67 matched_indexes.append((row[0],row[1]))
68
69 connection.close()
68 return matched_indexes 70 return matched_indexes
69 71
70 def testloadPrototypeMatchIndexesFromSqlite(): 72 def testloadPrototypeMatchIndexesFromSqlite():
71 empty_list = loadPrototypeMatchIndexesFromSqlite("bidon") 73 empty_list = loadPrototypeMatchIndexesFromSqlite("bidon")
72 if empty_list == []: 74 if empty_list == []:
75 matches=loadPrototypeMatchIndexesFromSqlite("/home/francois/Unison/École/12Été/CRSNG/TAAM-Experiments/resultats/prototypes-with-matches.sqlite") 77 matches=loadPrototypeMatchIndexesFromSqlite("/home/francois/Unison/École/12Été/CRSNG/TAAM-Experiments/resultats/prototypes-with-matches.sqlite")
76 if len(matches) == 66: 78 if len(matches) == 66:
77 print "Matches test Ok" 79 print "Matches test Ok"
78 return matches 80 return matches
79 81
80
81
82
83 82
84 def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = -1): 83 def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = -1):
85 '''Loads nObjects or the indices in objectNumbers from the database 84 '''Loads nObjects or the indices in objectNumbers from the database
86 TODO: load velocities (replace table name 'positions' by 'velocities' 85 TODO: load velocities (replace table name 'positions' by 'velocities'
87 TODO: load features as well, other ways of averaging trajectories 86 TODO: load features as well, other ways of averaging trajectories