Skip to content

Commit

Permalink
Fixes TcxParser for HRM Swim files
Browse files Browse the repository at this point in the history
They include one Trackpoint per second with HR,
but distance only once per length.
  • Loading branch information
amtriathlon committed Nov 25, 2015
1 parent 7cf63b4 commit 7d5b6a8
Show file tree
Hide file tree
Showing 4 changed files with 16,104 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/TcxParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ TcxParser::startElement( const QString&, const QString&, const QString& qName, c
if (sport == "Biking") rideFile->setTag("Sport", "Bike");
else if (sport == "Running") rideFile->setTag("Sport", "Run");
else if (sport == "Other") swim = MayBeSwim;
// start of last length for lap swimming
lastLength = 0.0;

} else if (qName == "Lap") {

Expand Down Expand Up @@ -142,6 +144,7 @@ TcxParser::endElement( const QString&, const QString&, const QString& qName)
// Lets derive Speed from Distance or vice-versa
// If we have neither Speed nor Distance then we
// add a point with 0 for speed and distance
double sample_dist = distance;
if (speed == 0 || distance < 0) {

// compute the elapsed time and distance traveled since the
Expand Down Expand Up @@ -221,6 +224,24 @@ TcxParser::endElement( const QString&, const QString&, const QString& qName)
0.0, // tcore
lap);

// Update distance and speed for swimming lengths
if (swim == Swim && sample_dist > 0.0 && secs > lastLength) {
double deltaSecs = secs - lastLength;
double deltaDist = (distance - last_distance) / deltaSecs;
double kph = 3600.0 * deltaDist;
for (int i = rideFile->timeIndex(lastLength);
i>= 0 && i < rideFile->dataPoints().size() &&
rideFile->dataPoints()[i]->secs <= secs;
++i) {
rideFile->dataPoints()[i]->kph = kph;
rideFile->dataPoints()[i]->km = last_distance;
last_distance += deltaDist;
}
last_distance = distance;
if (kph > 0.0) rideFile->setDataPresent(rideFile->kph, true);
lastLength = secs;
}

} else {

// smart recording is on and delta is less than GarminHWM seconds
Expand Down
1 change: 1 addition & 0 deletions src/TcxParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TcxParser : public QXmlDefaultHandler
double distance;
double lapSecs; // for pause intervals in pool swimming files
enum { NotSwim, MayBeSwim, Swim } swim; // to detect pool swimming files
double lastLength; // for pool swimming files

bool first; // first ride found, when it may contain collections!
int lap;
Expand Down
Binary file added test/rides/GarminHRMswim.FIT
Binary file not shown.

0 comments on commit 7d5b6a8

Please sign in to comment.