summaryrefslogtreecommitdiffstats
path: root/Monitoring/MonitoringService/DataProcessing/AggregatorManager.py
blob: 16d78fc258329fcb48d9d364af0bb43ffc6a9f08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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