Skip to content

Commit

Permalink
FixPower
Browse files Browse the repository at this point in the history
... allow fix power value to be added/subtracted in addition to percentage values
  • Loading branch information
Joern-R committed Aug 27, 2017
1 parent 429de11 commit 2c62390
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/Core/Settings.h
Expand Up @@ -170,6 +170,7 @@
#define GC_DPFS_VARIANCE "<global-general>dataprocess/fixspikes/variance"
#define GC_DPTA "<global-general>dataprocess/torqueadjust/adjustment"
#define GC_DPPA "<global-general>dataprocess/poweradjust/adjustment"
#define GC_DPPA_ABS "<global-general>dataprocess/poweradjust/adjustment_abs"
#define GC_DPFHRS_MAX "<global-general>dataprocess/fixhrspikes/max"
#define GC_DPDP_BIKEWEIGHT "<global-general>dataprocess/fixderivepower/bikewheight"
#define GC_DPDP_CRR "<global-general>dataprocess/fixderivepower/crr"
Expand Down
76 changes: 53 additions & 23 deletions src/FileIO/FixPower.cpp
Expand Up @@ -33,9 +33,9 @@ class FixPowerConfig : public DataProcessorConfig
friend class ::FixPower;
protected:
QHBoxLayout *layout;
QLabel *paLabel;
QLabel *percentLabel;
QLineEdit *pa;
QLabel *relPaLabel, *absPaLabel;
QLabel *percentLabel,*wattLabel;
QLineEdit *paRel, *paAbs;

public:
FixPowerConfig(QWidget *parent) : DataProcessorConfig(parent) {
Expand All @@ -44,20 +44,27 @@ class FixPowerConfig : public DataProcessorConfig
parent->setWhatsThis(help->getWhatsThisText(HelpWhatsThis::MenuBar_Edit_AdjustPowerValues));

layout = new QHBoxLayout(this);

layout->setContentsMargins(0,0,0,0);
setContentsMargins(0,0,0,0);

paLabel = new QLabel(tr("Power Adjustment"));

pa = new QLineEdit();

relPaLabel = new QLabel(tr("Percent Adjustment"));
paRel = new QLineEdit();
percentLabel = new QLabel(tr("%"));

layout->addWidget(paLabel);
layout->addWidget(pa);
layout->addStretch();
absPaLabel = new QLabel(tr("Fix Adjustment"));
paAbs = new QLineEdit();
wattLabel = new QLabel(tr("watt"));

layout->addWidget(relPaLabel);
layout->addWidget(paRel);
layout->addWidget(percentLabel);
layout->addStretch();

layout->addWidget(absPaLabel);
layout->addWidget(paAbs);
layout->addWidget(wattLabel);


}

//~FixPowerConfig() {} // deliberately not declared since Qt will delete
Expand All @@ -66,18 +73,25 @@ class FixPowerConfig : public DataProcessorConfig
QString explain() {
return(QString(tr("Adjusting power values allows you to "
"uplift or degrade the power values by a "
"percentage. It takes a single parameter:\n\n"
"Power Adjustment - this defines percentage "
" to modify values by. Negative values are supported."
"percentage and/or a fix value. It takes two parameters:\n\n"
"Percent Adjustment - this defines percentage "
" to modify values by. Negative values are supported.\n\n"
"Fix Adjustment - this defines an fix amount "
" to modify values by. Negative values are supported.\n\n"
"If both parameters are given, first the relative adjustment "
"takes place, then the fix value adjustment is applied on the result."
)));
}

void readConfig() {
pa->setText(appsettings->value(NULL, GC_DPPA, "0").toString());
paRel->setText(appsettings->value(NULL, GC_DPPA, "0").toString());
paAbs->setText(appsettings->value(NULL, GC_DPPA_ABS, "0").toString());
}

void saveConfig() {
appsettings->setValue(GC_DPPA, pa->text());
appsettings->setValue(GC_DPPA, paRel->text());
appsettings->setValue(GC_DPPA_ABS, paAbs->text());

}
};

Expand Down Expand Up @@ -115,37 +129,53 @@ FixPower::postProcess(RideFile *ride, DataProcessorConfig *config=0, QString op=
Q_UNUSED(op)

// Lets do it then!
QString tp;
QString tpRel, tpAbs;
double percentageAdjust = 0;
double absoluteAdjust = 0;

if (config == NULL) { // being called automatically
tp = appsettings->value(NULL, GC_DPPA, "0").toString();
tpRel = appsettings->value(NULL, GC_DPPA, "0").toString();
tpAbs = appsettings->value(NULL, GC_DPPA_ABS, "0").toString();
} else { // being called manually
tp = ((FixPowerConfig*)(config))->pa->text();
tpRel = ((FixPowerConfig*)(config))->paRel->text();
tpAbs = ((FixPowerConfig*)(config))->paAbs->text();

}

percentageAdjust = tp.toDouble();
percentageAdjust = tpRel.toDouble();
absoluteAdjust = tpAbs.toDouble();

// does this ride have power?
if (ride->areDataPresent()->watts == false) return false;

// no adjustment required
if (percentageAdjust == 0) return false;
if ((percentageAdjust == 0) && (absoluteAdjust == 0)) return false;

// apply the change
ride->command->startLUW("Adjust Power");
for (int i=0; i<ride->dataPoints().count(); i++) {
RideFilePoint *point = ride->dataPoints()[i];

double newWatts = point->watts;
// only add/adjust if we have a value > 0
if (point->watts != 0 && percentageAdjust != 0) {
ride->command->setPointValue(i, RideFile::watts, point->watts + (point->watts * (percentageAdjust / 100)));
newWatts += (newWatts * (percentageAdjust / 100));
}
// only add/adjust if we have a value > 0
if (point->watts != 0 && absoluteAdjust != 0) {
newWatts += absoluteAdjust;
}
if (newWatts != point->watts) {
ride->command->setPointValue(i, RideFile::watts, newWatts);
}

}
ride->command->endLUW();

double currentta = ride->getTag("Power Adjust", "0.0").toDouble();
ride->setTag("Power Adjust", QString("%1").arg(currentta + percentageAdjust));
double currenttaAbs = ride->getTag("Power Adjust fix", "0.0").toDouble();
ride->setTag("Power Adjust fix", QString("%1").arg(currenttaAbs + absoluteAdjust));


return true;
}

0 comments on commit 2c62390

Please sign in to comment.