# Path: libre/apps/data_drivers/utils.py
# def return_attrib(obj, attrib):
#     return reduce(get_value, attrib.split(u'.'), obj)


from operator import itemgetter
from .exceptions import LIBREFieldError
from .utils import return_attrib
    def _execute(self, elements):
        if self.properties:
            return sum([return_attrib(itemgetter(self.field)(element), self.properties) for element in elements])
        else:
            return sum([element[self.argument] for element in elements if element[self.argument]])


class Max(Aggregate):
    def _execute(self, elements):
        if self.properties:
            return max([return_attrib(itemgetter(self.field)(element), self.properties) for element in elements])
        else:
            return max([element[self.argument] for element in elements if element[self.argument]])


class Min(Aggregate):
    def _execute(self, elements):
        if self.properties:
            return min([return_attrib(itemgetter(self.field)(element), self.properties) for element in elements])
        else:
            return min([element[self.argument] for element in elements if element[self.argument]])


class Average(Aggregate):
    def _execute(self, elements):
        total = float(0)

        count = 0
        if self.properties:
            for count, element in enumerate(elements, 1):

# Path: libre/apps/data_drivers/utils.py
# def return_attrib(obj, attrib):
#     return reduce(get_value, attrib.split(u'.'), obj)


# Path: libre/apps/data_drivers/aggregates.py
from operator import itemgetter
from .exceptions import LIBREFieldError
from .utils import return_attrib

    def _execute(self, elements):
        if self.properties:
            return sum([return_attrib(itemgetter(self.field)(element), self.properties) for element in elements])
        else:
            return sum([element[self.argument] for element in elements if element[self.argument]])


class Max(Aggregate):
    def _execute(self, elements):
        if self.properties:
            return max([return_attrib(itemgetter(self.field)(element), self.properties) for element in elements])
        else:
            return max([element[self.argument] for element in elements if element[self.argument]])


class Min(Aggregate):
    def _execute(self, elements):
        if self.properties:
            return min([return_attrib(itemgetter(self.field)(element), self.properties) for element in elements])
        else:
            return min([element[self.argument] for element in elements if element[self.argument]])


class Average(Aggregate):
    def _execute(self, elements):
        total = float(0)

        count = 0
        if self.properties:
            for count, element in enumerate(elements, 1):

                total = total + return_attrib(itemgetter(self.field)(element), self.properties)