Mercurial Hosting > traffic-intelligence
diff python/indicators.py @ 282:abbd4bc13dac
modified indicator class (same interface)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 21 Dec 2012 17:50:10 -0500 |
parents | a9988971aac8 |
children | 5957aa1d69e1 8bafd054cda4 |
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