# HG changeset patch # User Nicolas Saunier # Date 1371699324 14400 # Node ID 1046b7346886149be9fbd26f1f639c107fa3c5ea # Parent 9c1818a71c9c06386b9f3760f88ede361f65bf74 work in progress on storing indicator values diff -r 9c1818a71c9c -r 1046b7346886 python/events.py --- 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) diff -r 9c1818a71c9c -r 1046b7346886 python/indicators.py --- 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: diff -r 9c1818a71c9c -r 1046b7346886 python/storage.py --- 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