Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/indicators.py @ 1265:0f5bebd62a55
minor modifications
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 24 May 2024 16:15:38 -0400 |
| parents | 56d0195d043e |
| children | ad60e5adf084 |
comparison
equal
deleted
inserted
replaced
| 1264:dff5b678a33a | 1265:0f5bebd62a55 |
|---|---|
| 183 values = sorted(values, reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values | 183 values = sorted(values, reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values |
| 184 return mean(values[:minNInstants]) | 184 return mean(values[:minNInstants]) |
| 185 else: | 185 else: |
| 186 return None | 186 return None |
| 187 | 187 |
| 188 def getInstantOfMostSevereValue(self): | 188 def getInstantOfMostSevereValue(self, minSevereValue = None): |
| 189 '''Returns the instant at which the indicator reaches its most severe value''' | 189 '''Returns the instant at which the indicator reaches its most severe value |
| 190 if self.mostSevereIsMax: | 190 or the instants when value is above minSevereValue (it not None)''' |
| 191 return max(self.values, key=self.values.get) | 191 if minSevereValue is None: |
| 192 else: | 192 if self.mostSevereIsMax: |
| 193 return min(self.values, key=self.values.get) | 193 return max(self.values, key=self.values.get) |
| 194 else: | |
| 195 return min(self.values, key=self.values.get) | |
| 196 else: | |
| 197 if self.mostSevereIsMax: | |
| 198 return [t for t in self.values if self.values[t] >= minSevereValue] | |
| 199 else: | |
| 200 return [t for t in self.values if self.values[t] <= minSevereValue] | |
| 194 | 201 |
| 195 # functions to aggregate discretized maps of indicators | 202 # functions to aggregate discretized maps of indicators |
| 196 # TODO add values in the cells between the positions (similar to discretizing vector graphics to bitmap) | 203 # TODO add values in the cells between the positions (similar to discretizing vector graphics to bitmap) |
| 197 | 204 |
| 198 def indicatorMap(indicatorValues, trajectory, squareSize): | 205 def indicatorMap(indicatorValues, trajectory, squareSize): |
