# Path: gtool/core/types/core.py
# class Aggregator(object):
#     """
#     Used as the base class for aggreagate plugins
#     """
# 
#     def __init__(self, config=None):
# 
#         if config is None or not isinstance(config,dict):
#             raise TypeError('config keyword arg should be a dict but got a', type(config))
# 
#         self.id = None
#         _payload = None
# 
#         try:
#             _keys = [k for k in config.keys()]
#             if len(_keys) != 1:
#                 raise ValueError()
#             self.id = _keys[0]
#             _values = [v for v in config.values()]
#             if len(_values) != 1:
#                 raise ValueError()
#             _payload = _values[0]
#             if not isinstance(_payload, dict):
#                 raise ValueError()
#         except (KeyError, ValueError, IndexError):
#             raise ValueError('The dict passed via the config keyword arg is not correctly structured. '
#                              'It must contaim a dict with a single Key whose Value is a dict')
# 
#         self.name = _payload.get('name', None) #optional
#         self.function = _payload.get('function', None)
#         self.selecttype = _payload.get('select', None).get('type', None)
#         self.selectors = _payload.get('select', None).get('config', None)
#         self.targetattribute = _payload.get('select', None).get('attribute', None)
# 
#         if self.function is None or not isinstance(self.function, str):
#             raise TypeError('Aggregator function value, received via config dict, '
#                             'should be a string containing a function name but got a', type(self.function))
# 
#         if not isinstance(self.selecttype, Selector):
#             raise TypeError('select.type, received via config dict, should be derived '
#                             'from the Selector Class but got a', type(self.selecttype))
# 
#         if not isinstance(self.selectors, list):
#             raise TypeError('select.config, received via config dict, should be a '
#                             'list but got a', type(self.selecttype))
# 
#         if not isinstance(self.targetattribute, str):
#             raise TypeError('select.attribute, received via config dict, should be a '
#                             'string but got a', type(self.selecttype))
# 
#     @abstractmethod
#     def compute(self):
#         return {self.name if self.name is not None else self.id : self.selecttype.method(*self.selectors)}


from gtool.core.types.core import Aggregator


class Sum(Aggregator):

    def __init__(self, config=None):
        super(Sum, self).__init__(config=config)

    def compute(self):
        selectionDict = super(Sum, self).compute()

        _selection = [v for v in selectionDict.values()][0]
        _name = [k for k in selectionDict.keys()][0]
        values = []
        for val in _selection:
            selectedvalue = getattr(val, self.targetattribute)
            if hasattr(selectedvalue, '__iter__'):
                _values = [v.raw() for v in selectedvalue]
                values.extend(_values)
            else:
                values.append(selectedvalue)

# Path: gtool/core/types/core.py
# class Aggregator(object):
#     """
#     Used as the base class for aggreagate plugins
#     """
# 
#     def __init__(self, config=None):
# 
#         if config is None or not isinstance(config,dict):
#             raise TypeError('config keyword arg should be a dict but got a', type(config))
# 
#         self.id = None
#         _payload = None
# 
#         try:
#             _keys = [k for k in config.keys()]
#             if len(_keys) != 1:
#                 raise ValueError()
#             self.id = _keys[0]
#             _values = [v for v in config.values()]
#             if len(_values) != 1:
#                 raise ValueError()
#             _payload = _values[0]
#             if not isinstance(_payload, dict):
#                 raise ValueError()
#         except (KeyError, ValueError, IndexError):
#             raise ValueError('The dict passed via the config keyword arg is not correctly structured. '
#                              'It must contaim a dict with a single Key whose Value is a dict')
# 
#         self.name = _payload.get('name', None) #optional
#         self.function = _payload.get('function', None)
#         self.selecttype = _payload.get('select', None).get('type', None)
#         self.selectors = _payload.get('select', None).get('config', None)
#         self.targetattribute = _payload.get('select', None).get('attribute', None)
# 
#         if self.function is None or not isinstance(self.function, str):
#             raise TypeError('Aggregator function value, received via config dict, '
#                             'should be a string containing a function name but got a', type(self.function))
# 
#         if not isinstance(self.selecttype, Selector):
#             raise TypeError('select.type, received via config dict, should be derived '
#                             'from the Selector Class but got a', type(self.selecttype))
# 
#         if not isinstance(self.selectors, list):
#             raise TypeError('select.config, received via config dict, should be a '
#                             'list but got a', type(self.selecttype))
# 
#         if not isinstance(self.targetattribute, str):
#             raise TypeError('select.attribute, received via config dict, should be a '
#                             'string but got a', type(self.selecttype))
# 
#     @abstractmethod
#     def compute(self):
#         return {self.name if self.name is not None else self.id : self.selecttype.method(*self.selectors)}


# Path: gtool/plugins/sum.py
from gtool.core.types.core import Aggregator



class Sum(Aggregator):

    def __init__(self, config=None):
        super(Sum, self).__init__(config=config)

    def compute(self):
        selectionDict = super(Sum, self).compute()

        _selection = [v for v in selectionDict.values()][0]
        _name = [k for k in selectionDict.keys()][0]
        values = []
        for val in _selection:
            selectedvalue = getattr(val, self.targetattribute)
            if hasattr(selectedvalue, '__iter__'):
                _values = [v.raw() for v in selectedvalue]
                values.extend(_values)
            else:
                values.append(selectedvalue)

        if len(values) == 0: