diff options
Diffstat (limited to 'Monitoring/MonitoringService/DataProcessing/AggregatorManager.py')
-rw-r--r-- | Monitoring/MonitoringService/DataProcessing/AggregatorManager.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Monitoring/MonitoringService/DataProcessing/AggregatorManager.py b/Monitoring/MonitoringService/DataProcessing/AggregatorManager.py new file mode 100644 index 0000000..16d78fc --- /dev/null +++ b/Monitoring/MonitoringService/DataProcessing/AggregatorManager.py @@ -0,0 +1,48 @@ +''' +Created on Dec 10, 2012 + +@author: steger +''' +from DataProcessing.Aggregator import AggregatorError, Aggregator +from DataProcessing.Sampler import Sampler +from DataProcessing.Parameter import ParameterList + +class AggregatorManager(object): + def __init__(self): + self._id = 0; + self._aggregators = {} + + def newAggregator(self, dataSource, cellrequest, commandflow): + for c, ca in commandflow: + if issubclass(c, Aggregator): + dataSource = c(dataSource, cellrequest) + if isinstance(ca, ParameterList): + for p in ca: + dataSource.__setattr__(p.name, p.value[0]) + else: + for k, v in ca.iteritems(): + dataSource.__setattr__(k, v) + elif issubclass(c, Sampler): + dataSource = c(dataSource) + if isinstance(ca, ParameterList): + for p in ca: + dataSource.__setattr__(p.name, p.value[0]) + else: + for k, v in ca.iteritems(): + dataSource.__setattr__(k, v) + self._id += 1 + self._aggregators[ self._id ] = dataSource + return self._id, dataSource + + def __getitem__(self, aggregatorid): + try: + return self._aggregators[ aggregatorid ] + except: + raise AggregatorError("Aggregator with id %s not found" % aggregatorid) + + def pop(self, aggregatorid): + try: + self._aggregators.pop( aggregatorid ) + except KeyError: + print "WW: Aggregator with id %s not found" % aggregatorid +
\ No newline at end of file |