diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 976ffda6329535590b89787de47d44556f789a34..f45eb9d582adf6b92eefefe24670cbe4ad514539 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ set(vehiclevoyage_SRCS db/sqlvehicle.cpp db/sqlservicerecord.cpp + db/recordanalytics.cpp jsonio.cpp main.cpp ) diff --git a/src/db/recordanalytics.cpp b/src/db/recordanalytics.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a3302b3d3621888af23ddd4adbbe4dec715a506b --- /dev/null +++ b/src/db/recordanalytics.cpp @@ -0,0 +1,42 @@ +/* + * <one line to give the program's name and a brief idea of what it does.> + * Copyright (C) 2020 <Kevin Whitakerr> <eyecreate@eyecreate.org> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "recordanalytics.h" +#include <QtConcurrent/QtConcurrent> +#include <QSqlQuery> +#include <QSqlRecord> + +RecordAnalytics::RecordAnalytics(QObject* parent, QSqlDatabase db) : _db(db) +{ +} + +void RecordAnalytics::checkOilChangeNeededForVehicle(int vehicleId, int milesForChange, int monthsForChange) +{ + QtConcurrent::run([&](){ + QSqlQuery query = _db.exec("SELECT * FROM records WHERE records.servicetype = 0;"); + int milesRecord = query.record().indexOf("miles"); + int dateRecord = query.record().indexOf("servicedate"); + while(query.next()) { + //TODO: query.value(milesRecord); + } + emit this->isOilChangeNeeded(false); + }); +} + + + diff --git a/src/db/recordanalytics.h b/src/db/recordanalytics.h new file mode 100644 index 0000000000000000000000000000000000000000..50da00e8656164f06441b4611fe4ce6679a440dc --- /dev/null +++ b/src/db/recordanalytics.h @@ -0,0 +1,44 @@ +/* + * <one line to give the program's name and a brief idea of what it does.> + * Copyright (C) 2020 <Kevin Whitaker> <eyecreate@eyecreate.org> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RECORDANALYTICS_H +#define RECORDANALYTICS_H + +#include <qobject.h> +#include <QSqlDatabase> + +/** + * Class to analyze attributes of the data in the database. Used mostly for detecting service scheduling. + */ +class RecordAnalytics : public QObject +{ + Q_OBJECT + +public: + RecordAnalytics(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase()); + Q_INVOKABLE void checkOilChangeNeededForVehicle(int vehicleId, int milesForChange=5000, int monthsForChange=6); + +signals: + void isOilChangeNeeded(bool changeNeeded); + +private: + QSqlDatabase _db; + +}; + +#endif // RECORDANALYTICS_H