Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
1255:c0fe55a6b82f | 1256:56d0195d043e |
---|---|
13 # need for a class representing the indicators, their units, how to print them in graphs... | 13 # need for a class representing the indicators, their units, how to print them in graphs... |
14 class TemporalIndicator(object): | 14 class TemporalIndicator(object): |
15 '''Class for temporal indicators | 15 '''Class for temporal indicators |
16 i.e. indicators that take a value at specific instants | 16 i.e. indicators that take a value at specific instants |
17 | 17 |
18 values should be | 18 values is a dict, for the values at specific time instants |
19 * a dict, for the values at specific time instants | |
20 * or a list with a time interval object if continuous measurements | |
21 | |
22 it should have more information like name, unit''' | 19 it should have more information like name, unit''' |
23 | 20 |
24 def __init__(self, name, values, timeInterval = None, maxValue = None): | 21 def __init__(self, name, values, maxValue = None): |
25 self.name = name | 22 self.name = name |
26 if timeInterval is None: | 23 self.values = values |
27 self.values = values | 24 instants = sorted(self.values.keys()) |
28 instants = sorted(self.values.keys()) | 25 if len(instants) > 0: |
29 if len(instants) > 0: | 26 self.timeInterval = moving.TimeInterval(instants[0], instants[-1]) |
30 self.timeInterval = moving.TimeInterval(instants[0], instants[-1]) | 27 else: |
31 else: | 28 self.timeInterval = moving.TimeInterval() |
32 self.timeInterval = moving.TimeInterval() | 29 # else: |
33 else: | 30 # assert len(values) == timeInterval.length() |
34 assert len(values) == timeInterval.length() | 31 # self.timeInterval = timeInterval |
35 self.timeInterval = timeInterval | 32 # self.values = {} |
36 self.values = {} | 33 # for i in range(int(round(self.timeInterval.length()))): |
37 for i in range(int(round(self.timeInterval.length()))): | 34 # self.values[self.timeInterval[i]] = values[i] |
38 self.values[self.timeInterval[i]] = values[i] | |
39 self.maxValue = maxValue | 35 self.maxValue = maxValue |
40 | 36 |
41 def __len__(self): | 37 def __len__(self): |
42 return len(self.values) | 38 return len(self.values) |
43 | 39 |
65 raise StopIteration | 61 raise StopIteration |
66 else: | 62 else: |
67 self.iterInstantNum += 1 | 63 self.iterInstantNum += 1 |
68 return self.getIthValue(self.iterInstantNum-1) | 64 return self.getIthValue(self.iterInstantNum-1) |
69 | 65 |
66 def min(self): | |
67 return min(self.values.values()) | |
68 | |
69 def max(self): | |
70 return max(self.values.values()) | |
71 | |
70 def getTimeInterval(self): | 72 def getTimeInterval(self): |
71 return self.timeInterval | 73 return self.timeInterval |
72 | 74 |
73 def getName(self): | 75 def getName(self): |
74 return self.name | 76 return self.name |
158 class SeverityIndicator(TemporalIndicator): | 160 class SeverityIndicator(TemporalIndicator): |
159 '''Class for severity indicators | 161 '''Class for severity indicators |
160 field mostSevereIsMax is True | 162 field mostSevereIsMax is True |
161 if the most severe value taken by the indicator is the maximum''' | 163 if the most severe value taken by the indicator is the maximum''' |
162 | 164 |
163 def __init__(self, name, values, timeInterval=None, mostSevereIsMax=True, maxValue = None): | 165 def __init__(self, name, values, mostSevereIsMax=True, maxValue = None): |
164 TemporalIndicator.__init__(self, name, values, timeInterval, maxValue) | 166 TemporalIndicator.__init__(self, name, values, maxValue) |
165 self.mostSevereIsMax = mostSevereIsMax | 167 self.mostSevereIsMax = mostSevereIsMax |
166 | 168 |
167 def getMostSevereValue(self, minNInstants=None, centile=None): | 169 def getMostSevereValue(self, minNInstants=None, centile=None): |
168 '''if there are more than minNInstants observations, | 170 '''if there are more than minNInstants observations, |
169 returns either the average of these maximum values | 171 returns either the average of these maximum values |