Files
flucto-heisskleber/heisskleber/stream/filter.py
Felix Weiler 26406110e5 Feature/filters (#110)
* Change Serializable definition.

* Add iter and aiter methods to source types.

* Add filter baseclass and two implementations.

G-H filter, a simple observer.
Butterworth filter, can be high or low.

* Fix documentation of gh filter.
2024-04-09 09:34:51 +08:00

20 lines
549 B
Python

from abc import ABC, abstractmethod
from collections.abc import AsyncGenerator
from typing import Any
from heisskleber.core.types import AsyncSource, Serializable
class Filter(ABC):
def __init__(self, source: AsyncSource):
self.source = source
async def __aiter__(self) -> AsyncGenerator[Any, None]:
async for topic, data in self.source:
data = self._filter(data)
yield topic, data
@abstractmethod
def _filter(self, data: dict[str, Serializable]) -> dict[str, Serializable]:
pass