Add in new class to analyze records for automation of data.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
set(vehiclevoyage_SRCS
|
set(vehiclevoyage_SRCS
|
||||||
db/sqlvehicle.cpp
|
db/sqlvehicle.cpp
|
||||||
db/sqlservicerecord.cpp
|
db/sqlservicerecord.cpp
|
||||||
|
db/recordanalytics.cpp
|
||||||
jsonio.cpp
|
jsonio.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
42
src/db/recordanalytics.cpp
Normal file
42
src/db/recordanalytics.cpp
Normal file
@@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
44
src/db/recordanalytics.h
Normal file
44
src/db/recordanalytics.h
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user