From fd6c01160d1a4ef2ff6e950eb0fd0207aa6703c2 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Mon, 5 Jan 2015 17:50:26 +0000 Subject: [PATCH] Import TrainingPeaks Manual entries .. hr, spd, power and work are all missing from the data they provide, but things like duration and TSS work --- src/PwxRideFile.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 4 deletions(-) diff --git a/src/PwxRideFile.cpp b/src/PwxRideFile.cpp index c1aed3ac3..f8e5111f0 100644 --- a/src/PwxRideFile.cpp +++ b/src/PwxRideFile.cpp @@ -59,6 +59,18 @@ PwxFileReader::PwxFromDomDoc(QDomDocument doc, QStringList &errors) const // and sort out at the end QDateTime rideDate; + // we collect summary data but discard it for all + // bar manual ride files where this is all we are + // gonna get ! + double manualDuration = 0.00f; + double manualWork = 0.00f; + double manualTSS = 0.00f; + double manualHR = 0.00f; + double manualSpeed = 0.00f; + double manualPower = 0.00f; + double manualKM = 0.00f; + double manualElevation = 0.00f; + int intervals = 0; int samples = 0; @@ -257,8 +269,57 @@ PwxFileReader::PwxFromDomDoc(QDomDocument doc, QStringList &errors) const add.interval); - // ignored for now + } else if (node.nodeName() == "summarydata") { + + // get the summary data in case there are no samples + // this is when there is a manual entry, so we can + // set the overrides from this + + // + //600 + //514.632000296428 + //100 + //
+ // + // + //23000 + //14 + //
+ + // duration + QDomElement off = node.firstChildElement("duration"); + if (!off.isNull()) manualDuration = off.text().toDouble(); + + // work + off = node.firstChildElement("work"); + if (!off.isNull()) manualWork = off.text().toDouble(); + + // tss + off = node.firstChildElement("tss"); + if (!off.isNull()) manualTSS = off.text().toDouble(); + + // hr + off = node.firstChildElement("hr"); + if (!off.isNull()) manualHR = off.text().toDouble(); + + // speed + off = node.firstChildElement("spd"); + if (!off.isNull()) manualSpeed = off.text().toDouble(); + + // power + off = node.firstChildElement("pwr"); + if (!off.isNull()) manualPower = off.text().toDouble(); + + // distance + off = node.firstChildElement("dist"); + if (!off.isNull()) manualKM = off.text().toDouble(); + + // Elevation + off = node.firstChildElement("climbingelevation"); + if (!off.isNull()) manualElevation = off.text().toDouble(); + + } else if (node.nodeName() == "extension") { } @@ -267,9 +328,70 @@ PwxFileReader::PwxFromDomDoc(QDomDocument doc, QStringList &errors) const // post-process and check if (samples < 2) { - errors << "Not enough samples present"; - delete rideFile; - return NULL; + + // set to 1s, it really doesn't matter! + rideFile->setRecIntSecs(1.0f); + + // we're creating a manual ride file so + // set the overrides from the supplied summarydata + + // distance + if (manualKM) { + QMap override; + override.insert("value", QString("%1").arg(manualKM / 1000)); // its in meters + rideFile->metricOverrides.insert("total_distance", override); + } + + // duration + if (manualDuration) { + QMap override; + override.insert("value", QString("%1").arg(manualDuration)); + rideFile->metricOverrides.insert("workout_time", override); + rideFile->metricOverrides.insert("time_riding", override); + } + + // work + if (manualWork) { + QMap override; + override.insert("value", QString("%1").arg(manualWork)); + rideFile->metricOverrides.insert("total_work", override); + } + + // TSS + if (manualTSS) { + QMap override; + override.insert("value", QString("%1").arg(manualTSS)); + rideFile->metricOverrides.insert("coggan_tss", override); + } + + // HR + if (manualHR) { + QMap override; + override.insert("value", QString("%1").arg(manualHR)); + rideFile->metricOverrides.insert("average_hr", override); + } + + // Speed + if (manualSpeed) { + QMap override; + override.insert("value", QString("%1").arg(manualSpeed)); + rideFile->metricOverrides.insert("average_speed", override); + } + + // Power + if (manualPower) { + QMap override; + override.insert("value", QString("%1").arg(manualPower)); + rideFile->metricOverrides.insert("average_power", override); + } + + // Elevation Gain + if (manualElevation) { + QMap override; + override.insert("value", QString("%1").arg(manualElevation)); + rideFile->metricOverrides.insert("elevation_gain", override); + } + } else { // need to determine the recIntSecs - first - second sample?