changeset 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 9c1818a71c9c
children 2f39c4ed0b62
files python/events.py python/indicators.py python/storage.py
diffstat 3 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/python/events.py	Wed Jun 19 22:56:21 2013 -0400
+++ b/python/events.py	Wed Jun 19 23:35:24 2013 -0400
@@ -41,6 +41,9 @@
         self.categoryNum = categoryNum
         self.indicators = {}
 
+    def getRoadUserNumbers(self):
+        return self.roadUserNumbers
+
     def getIndicator(self, indicatorName):
         return self.indicators.get(indicatorName, None)
 
--- a/python/indicators.py	Wed Jun 19 22:56:21 2013 -0400
+++ b/python/indicators.py	Wed Jun 19 23:35:24 2013 -0400
@@ -72,17 +72,6 @@
     def getValues(self):
         return [self.__getitem__(t) for t in self.timeInterval]
 
-    def getAngleValues(self):
-        '''if the indicator is a function of an angle, 
-        transform it to an angle (eg cos)
-        (no transformation otherwise)'''
-        from numpy import arccos
-        values = self.getValues()
-        if self.isCosine:
-            return [arccos(c) for c in values]
-        else: 
-            return values
-
     def plot(self, options = '', xfactor = 1., **kwargs):
         from matplotlib.pylab import plot,ylim
         if self.getTimeInterval().length() == 1:
--- a/python/storage.py	Wed Jun 19 22:56:21 2013 -0400
+++ b/python/storage.py	Wed Jun 19 23:35:24 2013 -0400
@@ -201,6 +201,32 @@
     utils.dropTables(connection, ['objects', 'objects_features'])
     connection.close()
 
+def deleteIndicators(filename):
+    'Deletes all indicator data in db'
+    pass
+
+def saveInteractions(filename, interactions):
+    'Saves the interactions in the table'
+    import sqlite3
+    connection = sqlite3.connect(filename)
+    cursor = connection.cursor()
+    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))')
+    # get the highest interaction id
+    for i in interactions:
+        cursor.execute('INSERT INTO interactions VALUES({})'.format(i.getNum())) # todo getRoadUserNumbers()
+    # 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));
+    # CREATE TABLE IF NOT EXISTS indicators (id INTEGER PRIMARY KEY, interaction_id INTEGER, indicator_type INTEGER, FOREIGN KEY(interaction_id) REFERENCES interactions(id))
+    # 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))
+
+    connection.close()
+
+def saveIndicators(filename, indicators):
+    'Saves the indicator values in the table'
+    import sqlite3
+    connection = sqlite3.connect(filename)
+    
+
+    connection.close()
 
 #########################
 # txt files