Coverage for physiodsp / base.py: 88%
33 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-07-14 19:36 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-07-14 19:36 +0000
1from abc import ABC
2from pandas import DataFrame
3from numpy import ndarray
6class BaseAlgorithm(ABC):
8 # Class Attributes
9 _algorithm_name = 'BaseAlgorithm'
10 _version = 'v0.1.0'
11 _window_len = 1
12 _aggregation_window = 60
14 def __init__(self) -> None:
15 return None
17 @property
18 def algorithm_name(self) -> str:
19 """Algorithm Name"""
20 return self._algorithm_name
22 @property
23 def version(self) -> str:
24 """Algorithm Version"""
25 return self._version
27 @property
28 def window_len(self) -> int:
29 """Window length in seconds"""
30 return self._window_len
32 @property
33 def aggregation_window(self) -> int:
34 """Aggregation Window in seconds"""
35 return self._aggregation_window
37 def preprocess(self):
38 raise NotImplementedError
40 def run(self):
41 raise NotImplementedError
43 def aggregate(self,
44 timestamps: ndarray,
45 values: ndarray,
46 method: str = 'mean'
47 ):
49 df = DataFrame({
50 'timestamps': timestamps,
51 'values': values
52 })
54 df['timestamps'] = df[
55 'timestamps'].apply(lambda x: (x // self._aggregation_window) * self._aggregation_window)
57 if method == 'mean':
58 df_agg = df.groupby('timestamps')[
59 'values'].mean().reset_index(drop=False)
61 self.biomarker_agg = df_agg
62 return self