changeset 282:abbd4bc13dac

modified indicator class (same interface)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 21 Dec 2012 17:50:10 -0500
parents 4f012e3d881b
children dbe7e53334d7
files python/indicators.py python/run-tests.sh python/utils.py
diffstat 3 files changed, 22 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/python/indicators.py	Fri Dec 21 17:29:43 2012 -0500
+++ b/python/indicators.py	Fri Dec 21 17:50:10 2012 -0500
@@ -19,23 +19,29 @@
     def __init__(self, name, values, timeInterval=None, maxValue = None):
         self.name = name
         self.isCosine = name.find('Cosine')
-        self.values = values
-        self.timeInterval = timeInterval
         if timeInterval:
             assert len(values) == timeInterval.length()
+            self.timeInterval = timeInterval
+            self.values = {}
+            for i in xrange(int(round(self.timeInterval.length()))):
+                self.values[self.timeInterval[i]] = values[i]
+        else:
+            self.values = values
+            instants = sorted(self.values.keys())
+            if instants:
+                self.timeInterval = moving.TimeInterval(instants[0], instants[-1])
+            else:
+                self.timeInterval = moving.TimeInterval()
         self.maxValue = maxValue
 
     def empty(self):
         return len(self.values) == 0
 
     def __getitem__(self, i):
-        if self.timeInterval:
-            if self.timeInterval.contains(i):
-                return self.values[i-self.timeInterval.first]
+        if i in self.values.keys():
+            return self.values[i]
         else:
-            if i in self.values.keys():
-                return self.values[i]
-        return None # default
+            return None
 
     def __iter__(self):
         self.iterInstantNum = 0 # index in the interval or keys of the dict
@@ -47,25 +53,13 @@
             raise StopIteration
         else:
             self.iterInstantNum += 1
-            if self.timeInterval:
-                return self.values[self.iterInstantNum-1]
-            else:
-                return self.values.values()[self.iterInstantNum-1]
+            return self.values[self.values.keys()[self.iterInstantNum-1]]
 
     def getTimeInterval(self):
-        if not self.timeInterval and type(self.values)==dict:
-            instants = self.values.keys()
-            if instants:
-                self.timeInterval = moving.TimeInterval(instants[0], instants[-1])
-            else:
-                self.timeInterval = moving.TimeInterval()
         return self.timeInterval
 
     def getValues(self):
-        if self.timeInterval:
-            return self.values
-        else:
-            return self.values.values()
+        return self.values.values()
 
     def getAngleValues(self):
         '''if the indicator is a function of an angle, 
@@ -84,14 +78,11 @@
             marker = 'o'
         else:
             marker = ''
-        if not self.timeInterval or type(self.values)==dict:
-            time = sorted(self.values.keys())
-            plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs)
-        else:
-            plot([x/xfactor for x in list(self.getTimeInterval())], self.values, options+marker, **kwargs)
+        time = sorted(self.values.keys())
+        plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs)
         if self.maxValue:
             ylim(ymax = self.maxValue)
-            
+
 class SeverityIndicator(TemporalIndicator):
     '''Class for severity indicators 
     field mostSevereIsMax is True 
--- a/python/run-tests.sh	Fri Dec 21 17:29:43 2012 -0500
+++ b/python/run-tests.sh	Fri Dec 21 17:50:10 2012 -0500
@@ -5,4 +5,4 @@
 rm nonexistent
 python indicators.py
 python utils.py
-python extrapolation.py
\ No newline at end of file
+python prediction.py
\ No newline at end of file
--- a/python/utils.py	Fri Dec 21 17:29:43 2012 -0500
+++ b/python/utils.py	Fri Dec 21 17:50:10 2012 -0500
@@ -166,8 +166,8 @@
 #########################
 
 def LCSS(l1, l2, threshold, distance):
-    "returns the longest common subsequence similarity
-    based on the threshold on distance between two elements of lists l1, l2"
+    """returns the longest common subsequence similarity
+    based on the threshold on distance between two elements of lists l1, l2"""
     from numpy import zeros
     m = len(l1)
     n = len(l2)