comparison python/storage.py @ 340:1046b7346886

work in progress on storing indicator values
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 19 Jun 2013 23:35:24 -0400
parents 3950bfe22768
children 2f39c4ed0b62
comparison
equal deleted inserted replaced
339:9c1818a71c9c 340:1046b7346886
199 import sqlite3 199 import sqlite3
200 connection = sqlite3.connect(filename) 200 connection = sqlite3.connect(filename)
201 utils.dropTables(connection, ['objects', 'objects_features']) 201 utils.dropTables(connection, ['objects', 'objects_features'])
202 connection.close() 202 connection.close()
203 203
204 def deleteIndicators(filename):
205 'Deletes all indicator data in db'
206 pass
207
208 def saveInteractions(filename, interactions):
209 'Saves the interactions in the table'
210 import sqlite3
211 connection = sqlite3.connect(filename)
212 cursor = connection.cursor()
213 cursor.execute('CREATE TABLE interactions IF NOT EXISTS (id INTEGER PRIMARY KEY, object_id1 INTEGER, object_id2 INTEGER, FOREIGN KEY(object_id1) REFERENCES objects(id), FOREIGN KEY(object_id2) REFERENCES objects(id))')
214 # get the highest interaction id
215 for i in interactions:
216 cursor.execute('INSERT INTO interactions VALUES({})'.format(i.getNum())) # todo getRoadUserNumbers()
217 # CREATE TABLE IF NOT EXISTS interactions (id INTEGER PRIMARY KEY, object_id1 INTEGER, object_id2 INTEGER, FOREIGN KEY(object_id1) REFERENCES objects(id), FOREIGN KEY(object_id2) REFERENCES objects(id));
218 # CREATE TABLE IF NOT EXISTS indicators (id INTEGER PRIMARY KEY, interaction_id INTEGER, indicator_type INTEGER, FOREIGN KEY(interaction_id) REFERENCES interactions(id))
219 # CREATE TABLE IF NOT EXISTS indicator_values (indicator_id INTEGER, frame_number INTEGER, value REAL, FOREIGN KEY(indicator_id) REFERENCES indicators(id), PRIMARY KEY(indicator_id, frame_number))
220
221 connection.close()
222
223 def saveIndicators(filename, indicators):
224 'Saves the indicator values in the table'
225 import sqlite3
226 connection = sqlite3.connect(filename)
227
228
229 connection.close()
204 230
205 ######################### 231 #########################
206 # txt files 232 # txt files
207 ######################### 233 #########################
208 234