How to use the eventkit.ops.aggregate.Reduce function in eventkit

To help you get started, we’ve selected a few eventkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erdewit / eventkit / eventkit / ops / aggregate.py View on Github external
else:
                self._prev = self._func(self._initializer, arg)
                self.emit(self._prev)
        else:
            self._prev = self._func(self._prev, arg)
            self.emit(self._prev)


class Min(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, min, float('inf'), source)


class Max(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, max, -float('inf'), source)


class Sum(Reduce):
    __slots__ = ()

    def __init__(self, start=0, source=None):
        Reduce.__init__(self, operator.add, start, source)


class Product(Reduce):
    __slots__ = ()
github erdewit / eventkit / eventkit / ops / aggregate.py View on Github external
class Mean(Op):
    __slots__ = ('_count', '_sum')

    def __init__(self, source=None):
        Op.__init__(self, source)
        self._count = 0
        self._sum = 0

    def on_source(self, arg):
        self._count += 1
        self._sum += arg
        self.emit(self._sum / self._count)


class Any(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, lambda prev, v: prev or bool(v), False, source)


class All(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, lambda prev, v: prev and bool(v), True, source)


class Ema(Op):
    __slots__ = ('_f1', '_f2', '_prev')
github erdewit / eventkit / eventkit / event.py View on Github external
Apply a two-argument reduction function to the previous reduction
        result and the current value and emit the new reduction result.

        Args:
            func: Reduction function::

                emit(args) -> emit(func(prev_args, args))

            initializer: First argument of first reduction::

                    first_result = func(initializer, first_value)

                If no initializer is given, then the first result is
                emitted on the second source emit.
        """
        return Reduce(func, initializer, self)
github erdewit / eventkit / eventkit / ops / aggregate.py View on Github external
self._initializer = initializer
        self._prev = NO_VALUE

    def on_source(self, arg):
        if self._prev is NO_VALUE:
            if self._initializer is NO_VALUE:
                self._prev = arg
            else:
                self._prev = self._func(self._initializer, arg)
                self.emit(self._prev)
        else:
            self._prev = self._func(self._prev, arg)
            self.emit(self._prev)


class Min(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, min, float('inf'), source)


class Max(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, max, -float('inf'), source)


class Sum(Reduce):
    __slots__ = ()
github erdewit / eventkit / eventkit / ops / aggregate.py View on Github external
self._sum = 0

    def on_source(self, arg):
        self._count += 1
        self._sum += arg
        self.emit(self._sum / self._count)


class Any(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, lambda prev, v: prev or bool(v), False, source)


class All(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, lambda prev, v: prev and bool(v), True, source)


class Ema(Op):
    __slots__ = ('_f1', '_f2', '_prev')

    def __init__(self, n=None, weight=None, source=None):
        Op.__init__(self, source)
        self._f1 = weight or 2.0 / (n + 1)
        self._f2 = 1 - self._f1
        self._prev = NO_VALUE

    def on_source(self, *args):
github erdewit / eventkit / eventkit / ops / aggregate.py View on Github external
class Min(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, min, float('inf'), source)


class Max(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, max, -float('inf'), source)


class Sum(Reduce):
    __slots__ = ()

    def __init__(self, start=0, source=None):
        Reduce.__init__(self, operator.add, start, source)


class Product(Reduce):
    __slots__ = ()

    def __init__(self, start=1, source=None):
        Reduce.__init__(self, operator.mul, start, source)


class Mean(Op):
    __slots__ = ('_count', '_sum')
github erdewit / eventkit / eventkit / ops / aggregate.py View on Github external
class Max(Reduce):
    __slots__ = ()

    def __init__(self, source=None):
        Reduce.__init__(self, max, -float('inf'), source)


class Sum(Reduce):
    __slots__ = ()

    def __init__(self, start=0, source=None):
        Reduce.__init__(self, operator.add, start, source)


class Product(Reduce):
    __slots__ = ()

    def __init__(self, start=1, source=None):
        Reduce.__init__(self, operator.mul, start, source)


class Mean(Op):
    __slots__ = ('_count', '_sum')

    def __init__(self, source=None):
        Op.__init__(self, source)
        self._count = 0
        self._sum = 0

    def on_source(self, arg):
        self._count += 1