Skip to content

Commit

Permalink
Store R-R data into XData for SML files
Browse files Browse the repository at this point in the history
In line with R-R data treatment for FIT files
Test file: test/rides/Ambit3-HRVbutNoHR.sml
  • Loading branch information
amtriathlon committed Jan 30, 2017
1 parent 674f7fc commit cba3d28
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/FileIO/SmlParser.cpp
Expand Up @@ -301,21 +301,38 @@ SmlParser::endElement(const QString&, const QString&, const QString& qName)
}
}

else if (qName == "Data" && !rideFile->isDataPresent(rideFile->hr))
{ // R-R data and no HR in samples: backfill using EWMA filtered R-R
else if (qName == "Data")
{ // R-R data: store in XData, when no HR in samples backfill
// using EWMA filtered R-R
double secs = 0.0;
double ewmaRR = -1.0;
const double ewmaTC = 5.0;
XDataSeries *hrvXdata = new XDataSeries();
hrvXdata->name = "HRV";
hrvXdata->valuename << "R-R";
hrvXdata->unitname << "msecs";
foreach (QString strRR, buffer.split(" ")) {
double rr = strRR.toDouble() / 1000.0;
if (ewmaRR < 0.0) ewmaRR = rr;
else ewmaRR += (rr - ewmaRR)/ewmaTC;
for (int i = 0; secs + rr >= trunc(secs) + i + 1; i++) {
rideFile->dataPoints()[rideFile->timeIndex(secs + i)]->hr = round(60.0/ ewmaRR);
if (!rideFile->isDataPresent(rideFile->hr)) {
for (int i = 0; secs + rr >= trunc(secs) + i + 1; i++) {
rideFile->dataPoints()[rideFile->timeIndex(secs + i)]->hr = round(60.0/ ewmaRR);
}
}
secs += rr;
XDataPoint *p = new XDataPoint();
p->secs = secs;
p->km = 0;
p->number[0] = rr * 1000.0;
hrvXdata->datapoints.append(p);
}
if (ewmaRR >= 0.0) rideFile->setDataPresent(rideFile->hr, true);
if (ewmaRR >= 0.0 && !rideFile->isDataPresent(rideFile->hr))
rideFile->setDataPresent(rideFile->hr, true);
if (hrvXdata->datapoints.count()>0)
rideFile->addXData("HRV", hrvXdata);
else
delete hrvXdata;
}

else if (qName == "Samples")
Expand Down

0 comments on commit cba3d28

Please sign in to comment.