fix PM to use exp weighted avg

Also limit decimal places in STS, LTS, and SB display fields.
This commit is contained in:
Eric Murray
2009-10-16 15:13:16 -07:00
committed by Sean Rhea
parent 46d026674f
commit 617f034fa3
4 changed files with 38 additions and 29 deletions

View File

@@ -59,7 +59,7 @@ void PerfPlot::plot() {
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
int num, tics;
tics = 27;
tics = 42;
setAxisScale(yLeft, _sc->min(), _sc->max());
num = xmax - xmin;
@@ -76,6 +76,8 @@ void PerfPlot::plot() {
tics = 7;
} else if (num < 141) {
tics = 14;
} else if (num < 364) {
tics = 27;
}
setAxisScale(xBottom, xmin, xmax,tics);

View File

@@ -21,6 +21,7 @@ PerformanceManagerWindow::PerformanceManagerWindow()
QLabel *PMSTSLabel = new QLabel(settings->value(GC_STS_ACRONYM,"STS").toString() + ":", this);
PMSTSValue = new QLineEdit("0");
PMSTSValue->setReadOnly(true);
PMSTSValue->setValidator(new QDoubleValidator(0,500,1,PMSTSValue));
PMPickerLayout->addWidget(PMSTSLabel);
PMPickerLayout->addWidget(PMSTSValue);
@@ -28,6 +29,7 @@ PerformanceManagerWindow::PerformanceManagerWindow()
PMLTSValue = new QLineEdit("0");
PMLTSValue->setReadOnly(true);
PMLTSValue->setValidator(new QDoubleValidator(0,500,1,PMLTSValue));
PMPickerLayout->addWidget(PMLTSLabel);
PMPickerLayout->addWidget(PMLTSValue);
@@ -35,6 +37,7 @@ PerformanceManagerWindow::PerformanceManagerWindow()
PMSBValue = new QLineEdit("0");
PMSBValue->setReadOnly(true);
PMSBValue->setValidator(new QDoubleValidator(-500,500,1,PMSBValue));
PMPickerLayout->addWidget(PMSBLabel);
PMPickerLayout->addWidget(PMSBValue);
@@ -185,19 +188,19 @@ PerformanceManagerWindow::PMpickerMoved(const QPoint &pos)
if (day >= perfplot->min() && day < perfplot->max()) {
// set the date string
PMDayValue->setText(perfplot->getStartDate().addDays(day).toString());
PMDayValue->setText(perfplot->getStartDate().addDays(day).toString("MMM d yyyy"));
sts = perfplot->getSTS(day);
QString STSlabel = QString("%1").arg(sts);
QString STSlabel = QString("%1").arg(sts,0,'f',1,0);
PMSTSValue->setText(STSlabel);
lts = perfplot->getLTS(day);
QString LTSlabel = QString("%1").arg(lts);
QString LTSlabel = QString("%1").arg(lts,0,'f',1,0);
PMLTSValue->setText(LTSlabel);
sb = perfplot->getSB(day);
QString SBlabel = QString("%1").arg(sb);
QString SBlabel = QString("%1").arg(sb,0,'f',1,0);
PMSBValue->setText(SBlabel);
}

View File

@@ -27,6 +27,8 @@ StressCalculator::StressCalculator (
xdays.resize(days+1);
list.resize(days+1);
lte = (double)exp(-1.0/longTermDays);
ste = (double)exp(-1.0/shortTermDays);
}
@@ -211,34 +213,34 @@ void StressCalculator::addRideData(double BS, QDateTime rideDate) {
// fprintf(stderr,"addRideData (%.2f, %d)\n",BS,daysIndex);
}
/*
* calculate stress (in Bike Score units) using
* stress = today's BS * (1 - exp(-1/days)) + yesterday's stress * exp(-1/days)
* where days is the time period of concern- 7 for STS and 42 for LTS.
*
* exp(-1/days) for short and long term is calculated when the
* class is instantiated.
*
*/
void StressCalculator::calculate(int daysIndex) {
int i;
double sum;
double lastLTS, lastSTS;
// LTS
sum = 0.0;
if (daysIndex < longTermDays - 1) {
// fake the first N days using the initial value
sum = initialLTS * (longTermDays - (daysIndex + 1));
i = 0;
}
else { i = daysIndex - (longTermDays - 1); }
// sum the real values
for (; i <= daysIndex; i++)
sum += list[i];
ltsvalues[daysIndex] = sum / longTermDays;
if (daysIndex == 0)
lastLTS = initialLTS;
else
lastLTS = ltsvalues[daysIndex-1];
ltsvalues[daysIndex] = (list[daysIndex] * (1.0 - lte)) + (lastLTS * lte);
// STS
sum = 0.0;
if (daysIndex < shortTermDays - 1) {
// fake the first N days using the initial value
sum = initialSTS * (shortTermDays - (daysIndex + 1));
i = 0;
}
else { i = daysIndex - (shortTermDays - 1); }
// sum the real values
for (; i <= daysIndex; i++)
sum += list[i];
stsvalues[daysIndex] = sum / shortTermDays;
if (daysIndex == 0)
lastSTS = initialSTS;
else
lastSTS = stsvalues[daysIndex-1];
stsvalues[daysIndex] = (list[daysIndex] * (1.0 - ste)) + (lastSTS * ste);
// SB (stress balance) long term - short term
sbvalues[daysIndex] = ltsvalues[daysIndex] - stsvalues[daysIndex] ;
@@ -246,3 +248,4 @@ void StressCalculator::calculate(int daysIndex) {
// xdays
xdays[daysIndex] = daysIndex+1;
}

View File

@@ -26,6 +26,7 @@ class StressCalculator:public QObject {
int longTermDays;
double initialSTS;
double initialLTS;
double ste, lte;
int lastDaysIndex;