mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Refresh metrics for rides after a new weight form Withings download
This commit is contained in:
@@ -59,7 +59,14 @@ MetricAggregator::~MetricAggregator()
|
||||
// used to store timestamp and fingerprint used in database
|
||||
struct status { unsigned long timestamp, fingerprint; };
|
||||
|
||||
// Refresh not up to date metrics
|
||||
void MetricAggregator::refreshMetrics()
|
||||
{
|
||||
refreshMetrics(QDateTime());
|
||||
}
|
||||
|
||||
// Refresh not up to date metrics and metrics after date
|
||||
void MetricAggregator::refreshMetrics(QDateTime forceAfterThisDate)
|
||||
{
|
||||
// only if we have established a connection to the database
|
||||
if (dbaccess == NULL || main->isclean==true) return;
|
||||
@@ -143,7 +150,8 @@ void MetricAggregator::refreshMetrics()
|
||||
QApplication::processEvents();
|
||||
|
||||
if (dbTimeStamp < QFileInfo(file).lastModified().toTime_t() ||
|
||||
zoneFingerPrint != fingerprint) {
|
||||
zoneFingerPrint != fingerprint ||
|
||||
(!forceAfterThisDate.isNull() && name >= forceAfterThisDate.toString("yyyy_MM_dd_hh_mm_ss"))) {
|
||||
QStringList errors;
|
||||
|
||||
// log
|
||||
|
||||
@@ -43,7 +43,8 @@ class MetricAggregator : public QObject
|
||||
~MetricAggregator();
|
||||
|
||||
|
||||
void refreshMetrics();
|
||||
void refreshMetrics();
|
||||
void refreshMetrics(QDateTime forceAfterThisDate);
|
||||
void getFirstLast(QDate &, QDate &);
|
||||
DBAccess *db() { return dbaccess; }
|
||||
SummaryMetrics getAllMetricsFor(QString filename); // for a single ride
|
||||
|
||||
@@ -49,24 +49,51 @@ WithingsDownload::downloadFinished(QNetworkReply *reply)
|
||||
QString text = reply->readAll();
|
||||
QStringList errors;
|
||||
parser->parse(text, errors);
|
||||
QString status = QString(tr("%1 measurements received.")).arg(parser->readings().count());
|
||||
QMessageBox::information(main, tr("Withings Data Download"), status);
|
||||
|
||||
//main->metricDB->db()->connection().transaction();
|
||||
newMeasures = 0;
|
||||
allMeasures = parser->readings().count();
|
||||
QDateTime olderDate;
|
||||
|
||||
|
||||
// debug output to examine data downloaded
|
||||
foreach (WithingsReading x, parser->readings()) {
|
||||
SummaryMetrics add;
|
||||
add.setDateTime(x.when);
|
||||
add.setText("Weight", QString("%1").arg(x.weightkg));
|
||||
add.setText("Height", QString("%1").arg(x.sizemeter));
|
||||
add.setText("Lean Mass", QString("%1").arg(x.leankg));
|
||||
add.setText("Fat Mass", QString("%1").arg(x.fatkg));
|
||||
add.setText("Fat Ratio", QString("%1").arg(x.fatpercent));
|
||||
QList<SummaryMetrics> list = main->metricDB->getAllMeasuresFor(x.when,x.when);
|
||||
bool presentOrEmpty = false;
|
||||
for (int i=0;i<list.size();i++) {
|
||||
SummaryMetrics sm = list.at(i);
|
||||
if (((x.weightkg == 0) || (sm.getText("Weight", "").length()>0)) &&
|
||||
((x.sizemeter == 0) || (sm.getText("Height", "").length()>0)) &&
|
||||
((x.leankg>0) || (sm.getText("Lean Mass", "").length()>0)) &&
|
||||
((x.fatkg>0) || (sm.getText("Fat Mass", "").length()>0)) &&
|
||||
((x.fatpercent>0) || (sm.getText("Fat Ratio", "").length()>0))) {
|
||||
presentOrEmpty = true;
|
||||
}
|
||||
}
|
||||
|
||||
main->metricDB->importMeasure(&add);
|
||||
if (!presentOrEmpty) {
|
||||
newMeasures ++;
|
||||
SummaryMetrics add;
|
||||
add.setDateTime(x.when);
|
||||
add.setText("Weight", QString("%1").arg(x.weightkg));
|
||||
add.setText("Height", QString("%1").arg(x.sizemeter));
|
||||
add.setText("Lean Mass", QString("%1").arg(x.leankg));
|
||||
add.setText("Fat Mass", QString("%1").arg(x.fatkg));
|
||||
add.setText("Fat Ratio", QString("%1").arg(x.fatpercent));
|
||||
|
||||
main->metricDB->importMeasure(&add);
|
||||
|
||||
if (olderDate.isNull() || x.when<olderDate)
|
||||
olderDate = x.when;
|
||||
}
|
||||
}
|
||||
|
||||
QString status = QString(tr("%1 new on %2 measurements received.")).arg(newMeasures).arg(allMeasures);
|
||||
QMessageBox::information(main, tr("Withings Data Download"), status);
|
||||
|
||||
if (!olderDate.isNull()) {
|
||||
main->isclean = false;
|
||||
main->metricDB->refreshMetrics(olderDate);
|
||||
}
|
||||
//main->metricDB->db()->connection().commit();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,5 +45,8 @@ private:
|
||||
MainWindow *main;
|
||||
QNetworkAccessManager *nam;
|
||||
WithingsParser *parser;
|
||||
|
||||
int allMeasures;
|
||||
int newMeasures;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "ZeoDownload.h"
|
||||
#include "MetricAggregator.h"
|
||||
#include <QScriptEngine>
|
||||
|
||||
ZeoDownload::ZeoDownload(MainWindow *main) : main(main)
|
||||
|
||||
Reference in New Issue
Block a user