Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 74:d3e1a7cf3375
added functions to get simply the values of indicators (and arccos transform for cosines
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 21 Jan 2011 18:27:55 -0500 |
| parents | 45e958ccd9bd |
| children | 5d487f183fe2 |
comparison
equal
deleted
inserted
replaced
| 73:930a6282c9a9 | 74:d3e1a7cf3375 |
|---|---|
| 384 | 384 |
| 385 it should have more information like name, unit''' | 385 it should have more information like name, unit''' |
| 386 | 386 |
| 387 def __init__(self, name, values, timeInterval=None): | 387 def __init__(self, name, values, timeInterval=None): |
| 388 self.name = name | 388 self.name = name |
| 389 self.isCosine = name.find('Cosine') | |
| 389 self.values = values | 390 self.values = values |
| 390 self.timeInterval = timeInterval | 391 self.timeInterval = timeInterval |
| 391 if timeInterval: | 392 if timeInterval: |
| 392 assert len(values) == timeInterval.length() | 393 assert len(values) == timeInterval.length() |
| 393 | 394 |
| 415 self.iterInstantNum += 1 | 416 self.iterInstantNum += 1 |
| 416 if self.timeInterval: | 417 if self.timeInterval: |
| 417 return self.values[self.iterInstantNum-1] | 418 return self.values[self.iterInstantNum-1] |
| 418 else: | 419 else: |
| 419 return self.values.values()[self.iterInstantNum-1] | 420 return self.values.values()[self.iterInstantNum-1] |
| 421 | |
| 422 def getValues(self): | |
| 423 if self.timeInterval: | |
| 424 return self.values | |
| 425 else: | |
| 426 return self.values.values() | |
| 427 | |
| 428 def getAngleValues(self): | |
| 429 '''if the indicator is a function of an angle, | |
| 430 transform it to an angle (eg cos) | |
| 431 (no transformation otherwise)''' | |
| 432 from numpy import arccos | |
| 433 values = self.getValues() | |
| 434 if self.isCosine >= 0: | |
| 435 return [arccos(c) for c in values] | |
| 436 else: | |
| 437 return values | |
| 420 | 438 |
| 421 class SeverityIndicator(TemporalIndicator): | 439 class SeverityIndicator(TemporalIndicator): |
| 422 '''Class for severity indicators | 440 '''Class for severity indicators |
| 423 field mostSevereIsMax is True | 441 field mostSevereIsMax is True |
| 424 if the most severe value taken by the indicator is the maximum''' | 442 if the most severe value taken by the indicator is the maximum''' |
