/
Banister.h
118 lines (91 loc) · 3.48 KB
/
Banister.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (c) 2019 Mark Liversedge (liversedge@gmail.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "RideMetric.h"
#include "Context.h"
#include "Estimator.h"
#include <QObject>
#include <QDate>
#include <QVector>
#ifndef GC_Banister_h
#define GC_Banister_h 1
// typical athlete as defined by the opendata analysis
// using floats because they are typically used in calculations
// that require float precision (the actual values are integers)
extern const double typical_CP, typical_WPrime, typical_Pmax;
// calculate power index, used to model in cp plot too
extern double powerIndex(double averagepower, double duration);
// gap with no training that constitutes break in seasons
extern const int typical_SeasonBreak;
class banisterData{
public:
banisterData() : score(0), nte(0), pte(0), perf(0), test(0) {}
double score, // TRIMP, BikeScore etc for day
g, // accumulated load with t1 decay for pte
h, // accumulated load with t2 decay for nte
nte, // Negative Training Effect
pte, // Positive Training Effect
perf, // Performance (nte+pte)
test; // test value
};
class Banister;
class banisterFit {
public:
banisterFit(Banister *parent) : p0(0),k1(0),k2(0),t1(0),t2(0),tests(0),testoffset(-1),parent(parent) {}
double f(double t, const double *p);
void combine(banisterFit other);
void compute(long startIndex, long stopIndex);
long startIndex, stopIndex;
QDate startDate, stopDate;
double p0,k1,k2,t1,t2;
// for indexing into banister::performanceDay and banister::performanceScore
int tests;
int testoffset;
Banister *parent;
};
class Banister : public QObject {
Q_OBJECT
public:
Banister(Context *context, QString symbol, double t1, double t2, double k1=0, double k2=0);
double value(QDate date, int type);
// model parameters - initial 'priors' to use
QString symbol; // load metric
double k1, k2; // nte/pte coefficients
double t1, t2; // nte/pte decay constants
// metric
RideMetric *metric;
QDate start, stop;
long long days;
// curves
double meanscore; // whats the average non-zero ride score (used for scaling)
long rides; // how many rides are there with a non-zero score
// time series data
QVector<banisterData> data;
// fitting windows with parameter estimates
// window effectively a season
QList<banisterFit> windows;
// performances as double
int performances;
QVector<double> performanceDay, performanceScore;
public slots:
void init(); // reset previous fits
void refresh(); // collect data from rides etc
void fit(); // perform fits along windows
private:
Context *context;
};
#endif