diff options
author | Arseniy-Movshev <dodoradio@outlook.com> | 2023-07-02 14:56:41 +0100 |
---|---|---|
committer | Arseniy-Movshev <dodoradio@outlook.com> | 2023-07-12 17:13:41 +0100 |
commit | 3090f0f1def6140c793a415760da5cdb410ca205 (patch) | |
tree | 72067dbc2f8a0de68428e82c2fdb939cb4dcc4ba | |
parent | 2b4578a2bd73a0f46f027d568533cd51909a8a54 (diff) |
Add a method for getting data over multiple days
-rw-r--r-- | qmlplugin/hrDataLoader.cpp | 30 | ||||
-rw-r--r-- | qmlplugin/hrDataLoader.h | 2 | ||||
-rw-r--r-- | qmlplugin/stepsDataLoader.cpp | 30 | ||||
-rw-r--r-- | qmlplugin/stepsDataLoader.h | 3 | ||||
-rw-r--r-- | qmlplugin/weightDataLoader.cpp | 30 | ||||
-rw-r--r-- | qmlplugin/weightDataLoader.h | 2 |
6 files changed, 90 insertions, 7 deletions
diff --git a/qmlplugin/hrDataLoader.cpp b/qmlplugin/hrDataLoader.cpp index b1eb2ca..4a1f04c 100644 --- a/qmlplugin/hrDataLoader.cpp +++ b/qmlplugin/hrDataLoader.cpp @@ -34,11 +34,15 @@ QVariant HrDataLoader::getTodayData() { } QVariant HrDataLoader::getDataForDate(QDate date) { + return QVariant::fromValue(getRawDataForDate(date)); +} + +QList<QPointF> HrDataLoader::getRawDataForDate(QDate date) { QList<QPointF> m_filedata; QFile file(fileNameForDate(date, "heartrateMonitor")); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "failed to open file"; - return QVariant::fromValue(m_filedata); + return m_filedata; } QTextStream inStream(&file); QString line; @@ -47,10 +51,32 @@ QVariant HrDataLoader::getDataForDate(QDate date) { QPointF point; point.setX(line.split(":")[0].toInt()); point.setY(line.split(":")[1].toInt()); + qDebug() << point; m_filedata.append(point); } file.close(); - return QVariant::fromValue(m_filedata); + return m_filedata; +} + +QVariant HrDataLoader::getDataFromTo(QDate date1, QDate date2) { + QList<QPointF> filedata; + if (date1 > date2) { + QDate temp = date1; + date1 = date2; + date2 = temp; + } + for (QDate i = date1; i <= date2; i = i.addDays(1)) { + qDebug() << "currently loading " << i; + QList<QPointF> data = getRawDataForDate(i); + qDebug() << filedata.count(); + if (filedata.count() == 0) { + filedata = data; + qDebug() << filedata.count(); + } else { + filedata += data; + } + } + return QVariant::fromValue(filedata); } void HrDataLoader::triggerDaemonRecording() { diff --git a/qmlplugin/hrDataLoader.h b/qmlplugin/hrDataLoader.h index 98ba400..78ac571 100644 --- a/qmlplugin/hrDataLoader.h +++ b/qmlplugin/hrDataLoader.h @@ -25,6 +25,8 @@ public: Q_INVOKABLE QVariant getDataForDate(QDate date); Q_INVOKABLE QVariant getTodayData(); Q_INVOKABLE void triggerDaemonRecording(); + Q_INVOKABLE QVariant getDataFromTo(QDate date1, QDate date2); + QList<QPointF> getRawDataForDate(QDate date); private: QDBusInterface *m_iface; }; diff --git a/qmlplugin/stepsDataLoader.cpp b/qmlplugin/stepsDataLoader.cpp index 44b15bb..50a0101 100644 --- a/qmlplugin/stepsDataLoader.cpp +++ b/qmlplugin/stepsDataLoader.cpp @@ -67,11 +67,15 @@ QVariant StepsDataLoader::getTodayData() { } QVariant StepsDataLoader::getDataForDate(QDate date) { + return QVariant::fromValue(getRawDataForDate(date)); +} + +QList<QPointF> StepsDataLoader::getRawDataForDate(QDate date) { QList<QPointF> m_filedata; QFile file(fileNameForDate(date, "stepCounter")); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "failed to open file"; - return QVariant::fromValue(m_filedata); + return m_filedata; } QTextStream inStream(&file); QString line; @@ -80,10 +84,32 @@ QVariant StepsDataLoader::getDataForDate(QDate date) { QPointF point; point.setX(line.split(":")[0].toInt()); point.setY(line.split(":")[1].toInt()); + qDebug() << point; m_filedata.append(point); } file.close(); - return QVariant::fromValue(m_filedata); + return m_filedata; +} + +QVariant StepsDataLoader::getDataFromTo(QDate date1, QDate date2) { + QList<QPointF> filedata; + if (date1 > date2) { + QDate temp = date1; + date1 = date2; + date2 = temp; + } + for (QDate i = date1; i <= date2; i = i.addDays(1)) { + qDebug() << "currently loading " << i; + QList<QPointF> data = getRawDataForDate(i); + qDebug() << filedata.count(); + if (filedata.count() == 0) { + filedata = data; + qDebug() << filedata.count(); + } else { + filedata += data; + } + } + return QVariant::fromValue(filedata); } void StepsDataLoader::triggerDaemonRecording() { diff --git a/qmlplugin/stepsDataLoader.h b/qmlplugin/stepsDataLoader.h index 48a3861..312a9f5 100644 --- a/qmlplugin/stepsDataLoader.h +++ b/qmlplugin/stepsDataLoader.h @@ -29,7 +29,8 @@ public: Q_INVOKABLE QVariant getDataForDate(QDate date); Q_INVOKABLE QVariant getTodayData(); Q_INVOKABLE void triggerDaemonRecording(); - + Q_INVOKABLE QVariant getDataFromTo(QDate date1, QDate date2); + QList<QPointF> getRawDataForDate(QDate date); signals: void todayTotalChanged(); private: diff --git a/qmlplugin/weightDataLoader.cpp b/qmlplugin/weightDataLoader.cpp index 2331252..c585995 100644 --- a/qmlplugin/weightDataLoader.cpp +++ b/qmlplugin/weightDataLoader.cpp @@ -34,11 +34,15 @@ QVariant WeightDataLoader::getTodayData() { } QVariant WeightDataLoader::getDataForDate(QDate date) { + return QVariant::fromValue(getRawDataForDate(date)); +} + +QList<QPointF> WeightDataLoader::getRawDataForDate(QDate date) { QList<QPointF> m_filedata; QFile file(fileNameForDate(date, "weight")); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "failed to open file"; - return QVariant::fromValue(m_filedata); + return m_filedata; } QTextStream inStream(&file); QString line; @@ -47,10 +51,32 @@ QVariant WeightDataLoader::getDataForDate(QDate date) { QPointF point; point.setX(line.split(":")[0].toInt()); point.setY(line.split(":")[1].toInt()); + qDebug() << point; m_filedata.append(point); } file.close(); - return QVariant::fromValue(m_filedata); + return m_filedata; +} + +QVariant WeightDataLoader::getDataFromTo(QDate date1, QDate date2) { + QList<QPointF> filedata; + if (date1 > date2) { + QDate temp = date1; + date1 = date2; + date2 = temp; + } + for (QDate i = date1; i <= date2; i = i.addDays(1)) { + qDebug() << "currently loading " << i; + QList<QPointF> data = getRawDataForDate(i); + qDebug() << filedata.count(); + if (filedata.count() == 0) { + filedata = data; + qDebug() << filedata.count(); + } else { + filedata += data; + } + } + return QVariant::fromValue(filedata); } void WeightDataLoader::addDataPoint(qreal value) { diff --git a/qmlplugin/weightDataLoader.h b/qmlplugin/weightDataLoader.h index 606f066..a9b9b68 100644 --- a/qmlplugin/weightDataLoader.h +++ b/qmlplugin/weightDataLoader.h @@ -26,6 +26,8 @@ public: Q_INVOKABLE QVariant getTodayData(); Q_INVOKABLE void triggerDaemonRecording(); Q_INVOKABLE void addDataPoint(qreal value); + Q_INVOKABLE QVariant getDataFromTo(QDate date1, QDate date2); + QList<QPointF> getRawDataForDate(QDate date); private: QDBusInterface *m_iface; }; |