Coverage for tests / test_activity_zero_crossing.py: 100%
27 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
1import os
2import pytest
3from datetime import datetime
5from numpy import arange
6from pandas import read_csv
7from physiodsp.sensors.imu.accelerometer import AccelerometerData
8from physiodsp.activity.zero_crossing import ZeroCrossing
10test_folder_path = os.path.dirname(os.path.realpath(__file__))
13@pytest.mark.parametrize(
14 "fs",
15 [
16 (32),
17 (64),
18 (128)
19 ]
20)
21def test_activity_zero_crossing(fs):
23 df = read_csv(os.path.join(test_folder_path, "accelerometer.csv"), usecols=["x", "y", "z"])
24 n_samples = len(df)
26 timestamp_start = datetime.now().timestamp()
27 timestamps = timestamp_start + arange(start=0, step=1/fs, stop=int(n_samples/fs))
29 accelerometer = AccelerometerData(
30 timestamps=timestamps,
31 x=df.x.values[:len(timestamps)],
32 y=df.y.values[:len(timestamps)],
33 z=df.z.values[:len(timestamps)],
34 fs=fs
35 )
37 processor = ZeroCrossing().run(data=accelerometer).aggregate()
39 zcr_1s = processor.biomarker
40 zcr_60s = processor.biomarker_agg
42 assert len(zcr_1s) == int(n_samples / fs) - 1
43 assert len(zcr_60s) >= 1
44 assert "x" in zcr_1s.columns
45 assert "y" in zcr_1s.columns
46 assert "z" in zcr_1s.columns
47 assert "timestamps" in zcr_1s.columns
48 assert zcr_1s["x"].dtype in [int, float]
49 assert zcr_1s["y"].dtype in [int, float]
50 assert zcr_1s["z"].dtype in [int, float]