mirror of
https://github.com/OMGeeky/flucto-heisskleber.git
synced 2025-12-26 16:07:50 +01:00
* 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.
20 lines
549 B
Python
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
|