-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTourData.cpp
More file actions
255 lines (223 loc) · 7.27 KB
/
Copy pathTourData.cpp
File metadata and controls
255 lines (223 loc) · 7.27 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#include "TourData.h"
#include <cmath>
TourData::TourData()
{
reset();
}
void TourData::reset()
{
m_tourTimeStamp.clear();
m_tourDistance.clear();
m_tourBatterySoc.clear();
m_tourSpeed.clear();
m_tourCadence.clear();
m_tourAltitude.clear();
m_tourGpsAccuracy.clear();
m_tourTemperature.clear();
m_tourGrade.clear();
m_tourPosLat.clear();
m_tourPosLong.clear();
m_tourHeartRate.clear();
m_tourCalories.clear();
m_tourPower.clear();
m_tourLRBalance.clear();
m_tourLPedalSmoothness.clear();
m_tourRPedalSmoothness.clear();
m_tourLTorqueEffectiveness.clear();
m_tourRTorqueEffectiveness.clear();
m_tourWindSpeed.clear();
m_tourAirSpeed.clear();
m_altCorrectionDone = false;
m_posCorrectionDone = false;
m_tempCorrectionDone = false;
m_battCorrectionDone = false;
m_gradeCorrectionDone = false;
m_caloriesCorrectionDone = false;
m_heartRateCorrectionDone = false;
m_firstPosRead = false;
m_posRead = false;
m_gearTimeStamp.clear();
m_gearDistance.clear();
m_gearNumFront.clear();
m_gearToothFront.clear();
m_gearNumRear.clear();
m_gearToothRear.clear();
m_gearRatio.clear();
m_gearInfoRear = false;
m_gearInfoFront = false;
m_gearCountFront = 0;
m_gearCountRear = 0;
m_session.totalElapsedTime = 0;
m_session.totalTimerTime = 0;
m_session.avgSpeed = 0;
m_session.maxSpeed = 0;
m_session.totalDistance = 0;
m_session.avgCadence = 0;
m_session.maxCadence = 0;
m_session.ascent = 0;
m_session.descent = 0;
m_session.altitudeMax = 0;
m_session.altitudeMin = 0;
m_session.avgTemperature = 0;
m_session.maxTemperature = 0;
m_session.minTemperature = 9999;
m_session.startTime = 0;
m_session.startDistance = 0;
m_session.maxGrade = 0;
m_session.minGrade = 0;
m_session.minHeartRate = 0;
m_session.avgHeartRate = 0;
m_session.maxHeartRate = 0;
for( int i = 0; i < 5; i++ ) m_session.hrTimeInZone[i] = 0.0;
for( int i = 0; i < 8; i++ ) m_session.pwrTimeInZone[i] = 0.0;
m_session.avgPower = 0;
m_session.maxPower = 0;
m_session.leftRightBalance = 0;
m_session.leftPedalSmoothness = 0;
m_session.rightPedalSmoothness = 0;
m_session.leftTorqueEffectiveness = 0;
m_session.rightTorqueEffectiveness = 0;
m_session.totalWork = 0;
m_session.totalCalories = 0;
m_session.normalizedPower = 0;
m_session.thresholdPower = 0;
m_session.trainingStressScore = 0;
m_session.itensityFactor = 0;
m_altCorrectionDone = false;
for( int i = 0; i < 5; i++ ) m_hrZoneHigh[i] = 0.0;
for( int i = 0; i < 8; i++ ) m_pwrZoneHigh[i] = 0.0;
m_deviceInfo.clear();
m_pwrCurve.clear();
m_sections.clear();
m_workoutName.clear();
}
bool TourData::deviceIdIsIncluded(deviceInfo_t a)
{
foreach( deviceInfo_t deviceInfo, m_deviceInfo )
{
if( deviceInfo.deviceId == a.deviceId ) return true;
if( deviceInfo.name == a.name ) return true;
}
return false;
}
int TourData::deviceIdInVectorAt(deviceInfo_t a)
{
for( int i = 0; i < m_deviceInfo.size(); i++ )
{
if( m_deviceInfo.at( i ).deviceId == a.deviceId ) return i;
if( m_deviceInfo.at( i ).name == a.name ) return i;
}
return -1;
}
void TourData::analysePowerCurve()
{
const QVector<double> timeIntervals = {0, 2, 3, 5, 8, 10, 15, 30, 45, 60, 120, 180, 300, 480, 600, 900, 1200, 1800, 2700, 3600, 7200, 10800, 18000, 36000}; // in seconds
if (m_tourTimeStamp.isEmpty() || m_tourPower.isEmpty() ||
m_tourTimeStamp.size() != m_tourPower.size()) {
return;
}
double startTime = m_tourTimeStamp.first();
double endTime = m_tourTimeStamp.last();
double diffTime = endTime - startTime;
for (auto interval : timeIntervals)
{
if (interval > diffTime)
break;
m_pwrCurve.push_back(QPair<double, double>(interval, 0));
}
m_pwrCurve.first().second = getSession().maxPower;
// for each time interval
#pragma omp parallel for
for (int intervalIdx = 1; intervalIdx < timeIntervals.size(); ++intervalIdx) {
double maxAvgPower = 0.0;
double interval = timeIntervals[intervalIdx];
if (startTime + interval < endTime)
{
// move window over all start positions
for (int startIdx = 0; startIdx < m_tourTimeStamp.size(); ++startIdx) {
double windowStartTime = m_tourTimeStamp[startIdx];
double windowEndTime = windowStartTime + interval;
// full windows only
if (windowEndTime > endTime)
break;
double powerSum = 0.0;
int count = 0;
// collect data in window
for (int idx = startIdx; idx < m_tourTimeStamp.size(); ++idx) {
if (m_tourTimeStamp[idx] < windowEndTime) {
powerSum += m_tourPower[idx];
count++;
} else {
break; // quit window
}
}
// calc average
if (count > 0) {
double avgPower = powerSum / count;
maxAvgPower = std::max(maxAvgPower, avgPower);
}
}
m_pwrCurve[intervalIdx].second = maxAvgPower;
}
}
}
void TourData::analysePedalSmoothness()
{
double sumL = 0.0;
double sumR = 0.0;
uint64_t cntL = 0;
uint64_t cntR = 0;
if (m_tourTimeStamp.size() != m_tourLPedalSmoothness.size()) return;
if (m_tourTimeStamp.size() != m_tourRPedalSmoothness.size()) return;
for (int i = 0; i < m_tourTimeStamp.size(); i++)
{
if (!std::isnan(m_tourLPedalSmoothness.at(i)))
{
sumL += m_tourLPedalSmoothness.at(i);
cntL++;
}
if (!std::isnan(m_tourRPedalSmoothness.at(i)))
{
sumR += m_tourRPedalSmoothness.at(i);
cntR++;
}
}
if (cntL)
m_session.leftPedalSmoothness = sumL / cntL;
else
m_session.leftPedalSmoothness = std::numeric_limits<double>::quiet_NaN();
if (cntR)
m_session.rightPedalSmoothness = sumR / cntR;
else
m_session.rightPedalSmoothness = std::numeric_limits<double>::quiet_NaN();
}
void TourData::analyseTorqueEffectiveness()
{
double sumL = 0.0;
double sumR = 0.0;
uint64_t cntL = 0;
uint64_t cntR = 0;
if (m_tourTimeStamp.size() != m_tourLTorqueEffectiveness.size()) return;
if (m_tourTimeStamp.size() != m_tourRTorqueEffectiveness.size()) return;
for (int i = 0; i < m_tourTimeStamp.size(); i++)
{
if (!std::isnan(m_tourLTorqueEffectiveness.at(i)))
{
sumL += m_tourLTorqueEffectiveness.at(i);
cntL++;
}
if (!std::isnan(m_tourRTorqueEffectiveness.at(i)))
{
sumR += m_tourRTorqueEffectiveness.at(i);
cntR++;
}
}
if (cntL)
m_session.leftTorqueEffectiveness = sumL / cntL;
else
m_session.leftTorqueEffectiveness = std::numeric_limits<double>::quiet_NaN();
if (cntR)
m_session.rightTorqueEffectiveness = sumR / cntR;
else
m_session.rightTorqueEffectiveness = std::numeric_limits<double>::quiet_NaN();
}