diff python/indicators.py @ 269:a9988971aac8

removed legacy code + tweaks
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 29 Jul 2012 04:09:43 -0400
parents 7a3bf04cf016
children abbd4bc13dac
line wrap: on
line diff
--- a/python/indicators.py	Sat Jul 28 02:58:47 2012 -0400
+++ b/python/indicators.py	Sun Jul 29 04:09:43 2012 -0400
@@ -3,6 +3,8 @@
 
 __metaclass__ = type
 
+import moving
+
 # need for a class representing the indicators, their units, how to print them in graphs...
 class TemporalIndicator:
     '''Class for temporal indicators
@@ -14,13 +16,14 @@
 
     it should have more information like name, unit'''
     
-    def __init__(self, name, values, timeInterval=None):
+    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.maxValue = maxValue
 
     def empty(self):
         return len(self.values) == 0
@@ -53,9 +56,9 @@
         if not self.timeInterval and type(self.values)==dict:
             instants = self.values.keys()
             if instants:
-                self.timeInterval = TimeInterval(instants[0], instants[-1])
+                self.timeInterval = moving.TimeInterval(instants[0], instants[-1])
             else:
-                self.timeInterval = TimeInterval()
+                self.timeInterval = moving.TimeInterval()
         return self.timeInterval
 
     def getValues(self):
@@ -75,21 +78,27 @@
         else: 
             return values
 
-    def plot(self, options = '', **kwargs):
-        from matplotlib.pylab import plot
-        if not self.timeInterval and type(self.values)==dict:
+    def plot(self, options = '', xfactor = 1., **kwargs):
+        from matplotlib.pylab import plot,ylim
+        if self.getTimeInterval().length() == 1:
+            marker = 'o'
+        else:
+            marker = ''
+        if not self.timeInterval or type(self.values)==dict:
             time = sorted(self.values.keys())
-            plot(time, [self.values[i] for i in time], options, **kwargs)
+            plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs)
         else:
-            plot(list(getTimeInterval()), self.values, options, **kwargs)
-
+            plot([x/xfactor for x in list(self.getTimeInterval())], self.values, options+marker, **kwargs)
+        if self.maxValue:
+            ylim(ymax = self.maxValue)
+            
 class SeverityIndicator(TemporalIndicator):
     '''Class for severity indicators 
     field mostSevereIsMax is True 
     if the most severe value taken by the indicator is the maximum'''
 
-    def __init__(self, name, values, timeInterval=None, mostSevereIsMax=True, ignoredValue = None): 
-        TemporalIndicator.__init__(self, name, values, timeInterval)
+    def __init__(self, name, values, timeInterval=None, mostSevereIsMax=True, ignoredValue = None, maxValue = None): 
+        TemporalIndicator.__init__(self, name, values, timeInterval, maxValue)
         self.mostSevereIsMax = mostSevereIsMax
         self.ignoredValue = ignoredValue