From 8dae828da2717dd8e07a385349c3ab4b45be790a Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sun, 8 Jul 2012 15:38:53 +0100 Subject: [PATCH] Withings Weight and Watts per Kilogram Fixed up the code to use withings weight when calculating watts per kilogram and the display on the CP chart. There will be issues when retrospectively refreshing data from a withings account, but that is such an edge case we can just ask people to delete old .cpx files to ensure they are refreshed. --- src/MainWindow.cpp | 19 +++---------------- src/RideFile.cpp | 24 +++++++++++++----------- src/RideFile.h | 1 + 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index b7d2625ba..c922e2bdd 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -692,27 +692,14 @@ MainWindow::MainWindow(const QDir &home) : rideMenu->addAction(tr("Split &activity..."), this, SLOT(splitRide())); rideMenu->addSeparator (); - - // XXX MEASURES ARE NOT IMPLEMENTED YET -//#if 0 - QMenu *measureMenu = menuBar()->addMenu(tr("&Measure")); - measureMenu->addAction(tr("&Record Measures..."), this, - SLOT(recordMeasure()), tr("Ctrl+R")); - measureMenu->addSeparator(); - measureMenu->addAction(tr("&Export Measures..."), this, - SLOT(exportMeasures()), tr("Ctrl+E")); - measureMenu->addAction(tr("&Import Measures..."), this, - SLOT(importMeasures()), tr("Ctrl+I")); - measureMenu->addSeparator(); - measureMenu->addAction(tr("Get &Withings Data..."), this, - SLOT (downloadMeasures())); -//#endif - QMenu *optionsMenu = menuBar()->addMenu(tr("&Tools")); optionsMenu->addAction(tr("&Options..."), this, SLOT(showOptions())); optionsMenu->addAction(tr("Critical Power Calculator..."), this, SLOT(showTools())); optionsMenu->addAction(tr("Air Density (Rho) Estimator..."), this, SLOT(showRhoEstimator())); + optionsMenu->addSeparator(); + optionsMenu->addAction(tr("Get &Withings Data..."), this, + SLOT (downloadMeasures())); optionsMenu->addSeparator(); optionsMenu->addAction(tr("Workout Wizard"), this, SLOT(showWorkoutWizard())); optionsMenu->addAction(tr("Get Workouts from ErgDB"), this, SLOT(downloadErgDB())); diff --git a/src/RideFile.cpp b/src/RideFile.cpp index 65b6b9e6d..87ae2cb86 100644 --- a/src/RideFile.cpp +++ b/src/RideFile.cpp @@ -40,12 +40,12 @@ RideFile::RideFile(const QDateTime &startTime, double recIntSecs) : startTime_(startTime), recIntSecs_(recIntSecs), - deviceType_("unknown"), data(NULL) + deviceType_("unknown"), data(NULL), weight_(0) { command = new RideFileCommand(this); } -RideFile::RideFile() : recIntSecs_(0.0), deviceType_("unknown"), data(NULL) +RideFile::RideFile() : recIntSecs_(0.0), deviceType_("unknown"), data(NULL), weight_(0) { command = new RideFileCommand(this); } @@ -508,8 +508,6 @@ RideFilePoint::value(RideFile::SeriesType series) const double RideFile::getPointValue(int index, SeriesType series) const { - if (series == wattsKg) - qDebug() << "wattsKg value"; return dataPoints_[index]->value(series); } @@ -634,37 +632,41 @@ RideFile::appendPoints(QVector newRows) void RideFile::emitSaved() { + weight_ = 0; emit saved(); } void RideFile::emitReverted() { + weight_ = 0; emit reverted(); } void RideFile::emitModified() { + weight_ = 0; emit modified(); } double RideFile::getWeight() { + if (weight_) return weight_; // cached value + // ride - double weight; - if ((weight = getTag("Weight", "0.0").toDouble()) > 0) { - return weight; + if ((weight_ = getTag("Weight", "0.0").toDouble()) > 0) { + return weight_; } -#if 0 + // withings? QList measures = mainwindow->metricDB->getAllMeasuresFor(QDateTime::fromString("Jan 1 00:00:00 1900"), startTime()); if (measures.count()) { - return measures.last().getText("Weight", "0.0").toDouble(); + return weight_ = measures.last().getText("Weight", "0.0").toDouble(); } -#endif + // global options - return appsettings->cvalue(mainwindow->cyclist, GC_WEIGHT, "75.0").toString().toDouble(); // default to 75kg + return weight_ = appsettings->cvalue(mainwindow->cyclist, GC_WEIGHT, "75.0").toString().toDouble(); // default to 75kg } diff --git a/src/RideFile.h b/src/RideFile.h index f45b6c87c..08cdef3e4 100644 --- a/src/RideFile.h +++ b/src/RideFile.h @@ -194,6 +194,7 @@ class RideFile : public QObject // QObject to emit signals QList intervals_; QMap tags_; EditorData *data; + double weight_; // cached to save calls to getWeight(); }; struct RideFilePoint