Fix Lap Swims - Ignore lengths shorter than Min Rest

This adds a minimum rest parameter to Fix Lap Swims DP to
ignore lengths shorter than a configured minimum value,
the corresponding time is added to the next length where it
is assumed to belong.
Minimum rest length default value is 3 secs, but it can be
changed in DP config.
Test files contributed by Jean Div at the users forum.
Fixes #4571
This commit is contained in:
Alejandro Martinez
2024-11-20 19:29:48 -03:00
parent 3570e089b4
commit 04cb57bda3
4 changed files with 37 additions and 2 deletions

View File

@@ -198,6 +198,7 @@
#define GC_CAD2SMO2 "<global-general>dataprocess/fixmoxy/cad2smo2" #define GC_CAD2SMO2 "<global-general>dataprocess/fixmoxy/cad2smo2"
#define GC_SPD2THB "<global-general>dataprocess/fixmoxy/spd2thb" #define GC_SPD2THB "<global-general>dataprocess/fixmoxy/spd2thb"
#define GC_DPFLS_PL "<global-general>dataprocess/fixlapswim/pool_length" #define GC_DPFLS_PL "<global-general>dataprocess/fixlapswim/pool_length"
#define GC_DPFLS_MR "<global-general>dataprocess/fixlapswim/min_rest"
#define GC_RR_MAX "<global-general>dataprocess/filterhrv/rr_max" // #define GC_RR_MAX "<global-general>dataprocess/filterhrv/rr_max" //
#define GC_RR_MIN "<global-general>dataprocess/filterhrv/rr_min" // #define GC_RR_MIN "<global-general>dataprocess/filterhrv/rr_min" //
#define GC_RR_FILT "<global-general>dataprocess/filterhrv/rr_filt" // #define GC_RR_FILT "<global-general>dataprocess/filterhrv/rr_filt" //

View File

@@ -38,6 +38,8 @@ class FixLapSwimConfig : public DataProcessorConfig
QHBoxLayout *layout; QHBoxLayout *layout;
QLabel *plLabel; QLabel *plLabel;
QSpinBox *pl; QSpinBox *pl;
QLabel *minRestLabel;
QSpinBox *minRest;
public: public:
FixLapSwimConfig(QWidget *parent) : DataProcessorConfig(parent) { FixLapSwimConfig(QWidget *parent) : DataProcessorConfig(parent) {
@@ -59,6 +61,16 @@ class FixLapSwimConfig : public DataProcessorConfig
layout->addWidget(plLabel); layout->addWidget(plLabel);
layout->addWidget(pl); layout->addWidget(pl);
layout->addStretch(); layout->addStretch();
minRestLabel = new QLabel(tr("Min Rest (s)"));
minRest = new QSpinBox();
minRest->setMaximum(10);
minRest->setMinimum(1);
minRest->setSingleStep(1);
layout->addWidget(minRestLabel);
layout->addWidget(minRest);
layout->addStretch();
} }
//~FixLapSwimConfig() {} // deliberately not declared since Qt will //~FixLapSwimConfig() {} // deliberately not declared since Qt will
@@ -72,17 +84,22 @@ class FixLapSwimConfig : public DataProcessorConfig
"in Editor SWIM tab: TYPE, DURATION and STROKES.\n" "in Editor SWIM tab: TYPE, DURATION and STROKES.\n"
"This tool recompute accumulated time, distance " "This tool recompute accumulated time, distance "
"and sample Speed/Cadence from the updated lengths.\n" "and sample Speed/Cadence from the updated lengths.\n"
"Laps are recreated using pause lengths as markers\n\n" "Laps are recreated using length distance changes as markers\n\n"
"Pool Length (in meters) allows to re-define the " "Pool Length (in meters) allows to re-define the "
"field if value is > 0"); "field if value is > 0\n\n"
"Lengths shorter than Min Rest (in seconds) "
"are removed and their duration carried to "
"the next length.\n\n");
} }
void readConfig() { void readConfig() {
pl->setValue(appsettings->value(NULL, GC_DPFLS_PL, "0").toDouble()); pl->setValue(appsettings->value(NULL, GC_DPFLS_PL, "0").toDouble());
minRest->setValue(appsettings->value(NULL, GC_DPFLS_MR, "3").toDouble());
} }
void saveConfig() { void saveConfig() {
appsettings->setValue(GC_DPFLS_PL, pl->value()); appsettings->setValue(GC_DPFLS_PL, pl->value());
appsettings->setValue(GC_DPFLS_MR, minRest->value());
} }
}; };
@@ -120,11 +137,14 @@ FixLapSwim::postProcess(RideFile *ride, DataProcessorConfig *config=0, QString o
{ {
// get settings // get settings
double pl; double pl;
double minRest;
if (config == NULL) { // being called automatically if (config == NULL) { // being called automatically
// when the file is created use poll length in the file // when the file is created use poll length in the file
pl = (op == "NEW") ? 0.0 : appsettings->value(NULL, GC_DPFLS_PL, "0").toDouble(); pl = (op == "NEW") ? 0.0 : appsettings->value(NULL, GC_DPFLS_PL, "0").toDouble();
minRest = appsettings->value(NULL, GC_DPFLS_MR, "3").toDouble();
} else { // being called manually } else { // being called manually
pl = ((FixLapSwimConfig*)(config))->pl->value(); pl = ((FixLapSwimConfig*)(config))->pl->value();
minRest = ((FixLapSwimConfig*)(config))->minRest->value();
} }
if (pl == 0.0) // If Pool Length is not configured, get from metadata if (pl == 0.0) // If Pool Length is not configured, get from metadata
@@ -151,6 +171,20 @@ FixLapSwim::postProcess(RideFile *ride, DataProcessorConfig *config=0, QString o
// Stroke Type or Duration are mandatory, Strokes only to compute cadence // Stroke Type or Duration are mandatory, Strokes only to compute cadence
if (typeIdx == -1 || durationIdx == -1) return false; if (typeIdx == -1 || durationIdx == -1) return false;
// Remove lengths shorter than minRest secs and carry that time over the next length
double prev_length_duration = 0.0;
for (int i=0; i< series->datapoints.count(); i++) {
double length_duration = series->datapoints.at(i)->number[durationIdx];
if (length_duration < minRest) {
ride->command->deleteXDataPoints("SWIM", i, 1);
prev_length_duration += length_duration;
} else if (prev_length_duration > 0.0) {
ride->command->setXDataPointValue("SWIM", i, durationIdx, prev_length_duration + length_duration);
prev_length_duration = 0.0;
}
}
QVariant GarminHWM = appsettings->value(NULL, GC_GARMIN_HWMARK); QVariant GarminHWM = appsettings->value(NULL, GC_GARMIN_HWMARK);
if (GarminHWM.isNull() || GarminHWM.toInt() == 0) GarminHWM.setValue(25); // default to 25 seconds. if (GarminHWM.isNull() || GarminHWM.toInt() == 0) GarminHWM.setValue(25); // default to 25 seconds.

Binary file not shown.

Binary file not shown.