From 6087e0b0dd7a5246aca9024ef777b62080d35834 Mon Sep 17 00:00:00 2001 From: Arseniy-Movshev Date: Thu, 8 Jun 2023 10:59:36 +0100 Subject: StepsDataLoader: Add a way to get the full day's data additionally, this renames the current data access function to 'getTotalForDate()' while the new function gets the old name of 'getDataForDate()'. This naming seems more appropriate. This should allow apps using the QML interface to implement their own graphs --- qmlplugin/stepsDataLoader.cpp | 41 ++++++++++++++++++++++++++++++++--------- qmlplugin/stepsDataLoader.h | 7 +++++-- 2 files changed, 37 insertions(+), 11 deletions(-) (limited to 'qmlplugin') diff --git a/qmlplugin/stepsDataLoader.cpp b/qmlplugin/stepsDataLoader.cpp index 199b324..8a281a2 100644 --- a/qmlplugin/stepsDataLoader.cpp +++ b/qmlplugin/stepsDataLoader.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "stepsDataLoader.h" @@ -28,12 +29,12 @@ StepsDataLoader::StepsDataLoader() : QObject() } } -int StepsDataLoader::getTodayData() { - return getDataForDate(QDate::currentDate()); +int StepsDataLoader::getTodayTotal() { + return getTotalForDate(QDate::currentDate()); } -int StepsDataLoader::getDataForDate(QDate date) { // This is obvious garbage. This should really be abstracted and cached, so that every page doesn't have to reload the file from scratch. -// The intention is to also add graph functionality at some point. The graph will be simplifying the data before loading it in - it would be worth caching the simplified data when it comes to that as well. +int StepsDataLoader::getTotalForDate(QDate date) { // This is obvious garbage. This should really be abstracted and cached, so that every page doesn't have to reload the file from scratch. + // The intention is to also add graph functionality at some point. The graph will be simplifying the data before loading it in - it would be worth caching the simplified data when it comes to that as well. QFile file(fileNameForDate(date, "stepCounter")); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "failed to open file"; @@ -42,8 +43,7 @@ int StepsDataLoader::getDataForDate(QDate date) { // This is obvious garbage. Th QTextStream inStream(&file); QString line = "0"; int i; - while(!inStream.atEnd()) - { + while (!inStream.atEnd()) { line = inStream.readLine(); qDebug() << line; i++; @@ -52,12 +52,35 @@ int StepsDataLoader::getDataForDate(QDate date) { // This is obvious garbage. Th return line.split(":")[1].toInt(); } +QList StepsDataLoader::getTodayData() { + return getDataForDate(QDate::currentDate()); +} + +QList StepsDataLoader::getDataForDate(QDate date) { + QList m_filedata; + QFile file(fileNameForDate(date, "stepCounter")); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "failed to open file"; + return m_filedata; + } + QTextStream inStream(&file); + QString line; + while (!inStream.atEnd()) { + line = inStream.readLine(); + QPointF point; + point.setX(line.split(":")[0].toInt()); + point.setY(line.split(":")[1].toInt()); + m_filedata.append(point); + } + file.close(); + return m_filedata; +} + void StepsDataLoader::triggerDaemonRecording() { m_iface->call("triggerRecording"); } - QString fileNameForDate(QDate date, QString prefix) { - QSettings settings("asteroid","sensorlogd"); //this should be moved out of here at some point TODO - return settings.value("loggerRootPath",QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + prefix + "/" + date.toString("yyyy-MM-dd.log"); + QSettings settings("asteroid", "sensorlogd"); // this should be moved out of here at some point TODO + return settings.value("loggerRootPath", QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + prefix + "/" + date.toString("yyyy-MM-dd.log"); } diff --git a/qmlplugin/stepsDataLoader.h b/qmlplugin/stepsDataLoader.h index 869b434..fa551a3 100644 --- a/qmlplugin/stepsDataLoader.h +++ b/qmlplugin/stepsDataLoader.h @@ -13,6 +13,7 @@ #include #include +#include class StepsDataLoader : public QObject { @@ -20,8 +21,10 @@ class StepsDataLoader : public QObject public: explicit StepsDataLoader(); - Q_INVOKABLE int getDataForDate(QDate date); - Q_INVOKABLE int getTodayData(); + Q_INVOKABLE int getTotalForDate(QDate date); + Q_INVOKABLE int getTodayTotal(); + Q_INVOKABLE QList getDataForDate(QDate date); + Q_INVOKABLE QList getTodayData(); Q_INVOKABLE void triggerDaemonRecording(); private: QDBusInterface *m_iface; -- cgit v1.2.3-70-g09d2