Mercurial > hg > nsaunier > traffic-intelligence
comparison python/indicators.py @ 724:b75d0c258ca9
update to indicator class
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 06 Aug 2015 18:00:25 -0400 |
| parents | 5ee22bf7e4d5 |
| children | c6d4ea05a2d0 |
comparison
equal
deleted
inserted
replaced
| 723:e14e2101a5a9 | 724:b75d0c258ca9 |
|---|---|
| 42 def empty(self): | 42 def empty(self): |
| 43 return len(self.values) == 0 | 43 return len(self.values) == 0 |
| 44 | 44 |
| 45 def __getitem__(self, t): | 45 def __getitem__(self, t): |
| 46 'Returns the value at time t' | 46 'Returns the value at time t' |
| 47 if t in self.values.keys(): | 47 return self.values.get(t) |
| 48 return self.values[t] | |
| 49 else: | |
| 50 return None | |
| 51 | 48 |
| 52 def getIthValue(self, i): | 49 def getIthValue(self, i): |
| 53 sortedKeys = sorted(self.values.keys()) | 50 sortedKeys = sorted(self.values.keys()) |
| 54 if 0<=i<len(sortedKeys): | 51 if 0<=i<len(sortedKeys): |
| 55 return self.values[sortedKeys[i]] | 52 return self.values[sortedKeys[i]] |
| 85 time = sorted(self.values.keys()) | 82 time = sorted(self.values.keys()) |
| 86 plot([(x+timeShift)/xfactor for x in time], [self.values[i]/yfactor for i in time], options+marker, **kwargs) | 83 plot([(x+timeShift)/xfactor for x in time], [self.values[i]/yfactor for i in time], options+marker, **kwargs) |
| 87 if self.maxValue: | 84 if self.maxValue: |
| 88 ylim(ymax = self.maxValue) | 85 ylim(ymax = self.maxValue) |
| 89 | 86 |
| 90 def valueSorted(self): | |
| 91 ''' return the values after sort the keys in the indicator | |
| 92 This should probably not be used: to delete''' | |
| 93 print('Deprecated: values should not be accessed in this way') | |
| 94 values=[] | |
| 95 keys = self.values.keys() | |
| 96 keys.sort() | |
| 97 for key in keys: | |
| 98 values.append(self.values[key]) | |
| 99 return values | |
| 100 | |
| 101 | 87 |
| 102 def l1Distance(x, y): # lambda x,y:abs(x-y) | 88 def l1Distance(x, y): # lambda x,y:abs(x-y) |
| 103 if x is None or y is None: | 89 if x is None or y is None: |
| 104 return float('inf') | 90 return float('inf') |
| 105 else: | 91 else: |
