Mercurial Hosting > traffic-intelligence
diff trafficintelligence/indicators.py @ 1256:56d0195d043e
cleaning indicators (no more time interval) and runtimeerror with arccos
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 03 Apr 2024 14:41:20 -0400 |
parents | bb14f919d1cb |
children | 0f5bebd62a55 |
line wrap: on
line diff
--- a/trafficintelligence/indicators.py Wed Apr 03 12:30:36 2024 -0400 +++ b/trafficintelligence/indicators.py Wed Apr 03 14:41:20 2024 -0400 @@ -15,27 +15,23 @@ '''Class for temporal indicators i.e. indicators that take a value at specific instants - values should be - * a dict, for the values at specific time instants - * or a list with a time interval object if continuous measurements - + values is a dict, for the values at specific time instants it should have more information like name, unit''' - def __init__(self, name, values, timeInterval = None, maxValue = None): + def __init__(self, name, values, maxValue = None): self.name = name - if timeInterval is None: - self.values = values - instants = sorted(self.values.keys()) - if len(instants) > 0: - self.timeInterval = moving.TimeInterval(instants[0], instants[-1]) - else: - self.timeInterval = moving.TimeInterval() + self.values = values + instants = sorted(self.values.keys()) + if len(instants) > 0: + self.timeInterval = moving.TimeInterval(instants[0], instants[-1]) else: - assert len(values) == timeInterval.length() - self.timeInterval = timeInterval - self.values = {} - for i in range(int(round(self.timeInterval.length()))): - self.values[self.timeInterval[i]] = values[i] + self.timeInterval = moving.TimeInterval() + # else: + # assert len(values) == timeInterval.length() + # self.timeInterval = timeInterval + # self.values = {} + # for i in range(int(round(self.timeInterval.length()))): + # self.values[self.timeInterval[i]] = values[i] self.maxValue = maxValue def __len__(self): @@ -67,6 +63,12 @@ self.iterInstantNum += 1 return self.getIthValue(self.iterInstantNum-1) + def min(self): + return min(self.values.values()) + + def max(self): + return max(self.values.values()) + def getTimeInterval(self): return self.timeInterval @@ -160,8 +162,8 @@ 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, maxValue = None): - TemporalIndicator.__init__(self, name, values, timeInterval, maxValue) + def __init__(self, name, values, mostSevereIsMax=True, maxValue = None): + TemporalIndicator.__init__(self, name, values, maxValue) self.mostSevereIsMax = mostSevereIsMax def getMostSevereValue(self, minNInstants=None, centile=None):