summaryrefslogtreecommitdiff
path: root/qmlplugin
diff options
context:
space:
mode:
authorArseniy-Movshev <dodoradio@outlook.com>2023-06-08 10:59:36 +0100
committerArseniy-Movshev <dodoradio@outlook.com>2023-06-20 00:05:23 +0100
commit6087e0b0dd7a5246aca9024ef777b62080d35834 (patch)
treede31d8702805ea45755eb926f434a1b3fa26b558 /qmlplugin
parent3e411195ff961a641ad94d9b5058d3ad981834b8 (diff)
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
Diffstat (limited to 'qmlplugin')
-rw-r--r--qmlplugin/stepsDataLoader.cpp41
-rw-r--r--qmlplugin/stepsDataLoader.h7
2 files changed, 37 insertions, 11 deletions
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 <QSettings>
#include <QStandardPaths>
#include <QDBusInterface>
+#include <QPointF>
#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<QPointF> StepsDataLoader::getTodayData() {
+ return getDataForDate(QDate::currentDate());
+}
+
+QList<QPointF> StepsDataLoader::getDataForDate(QDate date) {
+ QList<QPointF> 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 <QObject>
#include <QDBusInterface>
+#include <QPointF>
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<QPointF> getDataForDate(QDate date);
+ Q_INVOKABLE QList<QPointF> getTodayData();
Q_INVOKABLE void triggerDaemonRecording();
private:
QDBusInterface *m_iface;