Mercurial Hosting > traffic-intelligence
comparison python/indicators.py @ 693:5ee22bf7e4d5 dev
corrected bug when loading indicator time intervals and updated how queries are created for better legibility
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 30 Jun 2015 15:46:31 -0400 |
parents | 9a258687af4c |
children | b75d0c258ca9 |
comparison
equal
deleted
inserted
replaced
692:9a258687af4c | 693:5ee22bf7e4d5 |
---|---|
17 * a dict, for the values at specific time instants | 17 * a dict, for the values at specific time instants |
18 * or a list with a time interval object if continuous measurements | 18 * or a list with a time interval object if continuous measurements |
19 | 19 |
20 it should have more information like name, unit''' | 20 it should have more information like name, unit''' |
21 | 21 |
22 def __init__(self, name, values, timeInterval=None, maxValue = None): | 22 def __init__(self, name, values, timeInterval = None, maxValue = None): |
23 self.name = name | 23 self.name = name |
24 if timeInterval: | 24 if timeInterval is None: |
25 self.values = values | |
26 instants = sorted(self.values.keys()) | |
27 if len(instants) > 0: | |
28 self.timeInterval = moving.TimeInterval(instants[0], instants[-1]) | |
29 else: | |
30 self.timeInterval = moving.TimeInterval() | |
31 else: | |
25 assert len(values) == timeInterval.length() | 32 assert len(values) == timeInterval.length() |
26 self.timeInterval = timeInterval | 33 self.timeInterval = timeInterval |
27 self.values = {} | 34 self.values = {} |
28 for i in xrange(int(round(self.timeInterval.length()))): | 35 for i in xrange(int(round(self.timeInterval.length()))): |
29 self.values[self.timeInterval[i]] = values[i] | 36 self.values[self.timeInterval[i]] = values[i] |
30 else: | |
31 self.values = values | |
32 instants = sorted(self.values.keys()) | |
33 if instants: | |
34 self.timeInterval = moving.TimeInterval(instants[0], instants[-1]) | |
35 else: | |
36 self.timeInterval = moving.TimeInterval() | |
37 self.maxValue = maxValue | 37 self.maxValue = maxValue |
38 | 38 |
39 def __len__(self): | 39 def __len__(self): |
40 return len(self.values) | 40 return len(self.values) |
41 | 41 |