summaryrefslogtreecommitdiffstats
path: root/Monitoring/MonitoringService/DataProcessing/LinearCombination.py
blob: 5174b58839cd5e8239640b772f3e0ac5557f9e34 (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
'''
Created on Mar 21, 2013

@author: steger
'''
from DataProcessing.DataSource import DataSource
from DataProcessing.Aggregator import Aggregator
from DataProcessing.DataError import DataError

class LinearCombination(DataSource):
    '''
    classdocs
    '''

    def __init__(self):
        '''
        Constructor
        '''
        DataSource.__init__(self, dependency = None)
        self._terms = []
        self._value = None
        
    def addTerm(self, factor, aggregate):
        if not isinstance(aggregate, Aggregator):
            raise DataError("Wrong type of term")
        self._terms.append((factor, aggregate))
    
    @property
    def name(self):
        return "BLA"
    
    @property
    def value(self):
        self.process()
        return self._value
    
    def process(self):
        result = 0
        for factor, aggregate in self._terms:
            term = aggregate.aggregate
            result += factor * term
        self._value = result