Coverage for physiodsp / base.py: 86%
36 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-26 21:14 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-26 21:14 +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 lenght 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 @classmethod
38 def preprocess(self):
39 raise NotImplementedError
41 @classmethod
42 def run(self):
43 raise NotImplementedError
45 @classmethod
46 def aggregate(self,
47 timestamps: ndarray,
48 values: ndarray,
49 method: str = 'mean'
50 ):
52 df = DataFrame(
53 list(zip(timestamps, values)),
54 columns=['timestamps', 'values']
55 )
57 df['timestamps'] = df[
58 'timestamps'].apply(lambda x: (x // self._aggregation_window) * self._aggregation_window)
60 if method == 'mean':
61 df_agg = df.groupby('timestamps')[
62 'values'].mean().reset_index(drop=False)
64 self.biomarker_agg = df_agg
65 return self