refactor: move test_helpers, RunningQuality

This commit is contained in:
2026-03-12 20:34:54 +01:00
parent 90f8943930
commit 9aaec182a8
8 changed files with 297 additions and 174 deletions

View File

@@ -6,56 +6,13 @@
#include <vector>
#include "iir_filter.h"
#include "ssf_filter.h"
#include "test_helpers.h"
#include <cmath>
#include <limits>
#define FPS 60
#define MAX_BPM 300
template <typename T> static std::vector<double> apply_filter(T& filter, std::vector<double>& x) {
std::vector<double> y;
y.resize(x.size());
for (int i = 0; i < x.size(); i++) {
y[i] = filter.filter(x[i]);
}
return y;
}
static void npy_save(std::string path, std::vector<double>& x) {
npy::npy_data_ptr<double> d;
d.data_ptr = x.data();
d.shape = {(unsigned long) x.size()};
npy::write_npy(path, d);
}
static std::vector<double> fetch_y_axis(npy::npy_data<double>& acc) {
// TODO: later on, we should use a vector projection towards gravity
std::vector<double> signal;
const size_t rows_real = acc.shape[0];
#if DEBUG_IIR == 1
const size_t rows = 5;
#else
const size_t rows = acc.shape[0];
#endif
int stride = 3;
int offset = 1; // [x,y,z] per row - fetch y
signal.resize(rows);
if (acc.fortran_order) {
stride = 1;
offset = (int) rows_real;
}
/*
std::cout << "is_fortran=" << acc.fortran_order << std::endl;
for (size_t i = 0; i < 10; i++) {
std::cout << "acc.data[" << i << "]=" << acc.data[i] << std::endl;
}
*/
for (int i = 0; i < rows; i++) {
signal[i] = acc.data[i * stride + offset];
}
return signal;
}
TEST(HelloTest, Zong_SSF_Stage1) {
npy::npy_data acc = npy::read_npy<double>("test2/ssf_t2_acc.npy");
npy::npy_data y_ref = npy::read_npy<double>("test2/ssf_t2_y_ref.npy");
@@ -166,16 +123,6 @@ TEST(HelloTest, Zong_SSF_Stage2) {
npy_save("test2/ssf_t2_ssf.npy", ssf);
}
/** Returns the ssf_threshold as the filter output for debugging. */
class DebugSsfStepDetectorThreshold : public SsfStepDetector {
public:
DebugSsfStepDetectorThreshold(size_t len_refr) : SsfStepDetector(len_refr) {}
double filter(double val) {
this->SsfStepDetector::filter(val);
return peek_threshold();
}
};
TEST(HelloTest, Zong_SSF_Stage3) {
npy::npy_data acc = npy::read_npy<double>("test2/ssf_t2_acc.npy");