Remove unused scoring engine

This commit is contained in:
Muki 2019-03-17 13:02:10 +01:00
parent 963d6682c2
commit c048b764f9
7 changed files with 1 additions and 243 deletions

View file

@ -16,7 +16,6 @@ INCLUDEPATH += src
SOURCES += \
src/main.cpp \
src/ai.cpp \
src/utils.cpp \
src/tabmodel.cpp \
src/listmodel.cpp \
@ -39,7 +38,6 @@ SOURCES += \
HEADERS += \
src/info.h \
src/ai.h \
src/utils.h \
src/tabmodel.h \
src/listmodel.h \

View file

@ -59,8 +59,6 @@ ListItem {
readonly property alias expandable: box.expandable
property bool expandedMode: settings.expandedMode
property int evaluation: 0
signal markedAsRead
signal markedAsUnread
signal markedReadlater
@ -73,7 +71,6 @@ ListItem {
signal openInViewer
signal openInBrowser
signal showFeedContent
signal evaluated(int evaluation)
signal share
signal pocketAdd
signal saveImage

View file

@ -239,7 +239,6 @@ Page {
landscapeMode: root.landscapeMode
onlineurl: model.link
offlineurl: cserver.getUrlbyId(model.uid)
evaluation: ai.evaluation(model.uid)
signal singleEntryClicked
signal doubleEntryClicked
@ -462,10 +461,6 @@ Page {
openEntryInViewer()
}
onEvaluated: {
ai.addEvaluation(model.uid, model.title, evaluation)
}
onShare: {
pageStack.push(Qt.resolvedUrl("ShareLinkPage.qml"),{"link": model.link, "linkTitle": model.title})
}

View file

@ -1,180 +0,0 @@
/*
Copyright (C) 2017 Michal Kosciesza <michal@mkiol.net>
This file is part of Kaktus.
Kaktus 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.
Kaktus 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 Kaktus. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QSqlQuery>
#include "ai.h"
#include "settings.h"
Ai::Ai(QObject *parent) : QObject(parent)
{
}
Ai::~Ai()
{
db.close();
QSqlDatabase::removeDatabase("qt_sql_kaktusai_connection");
}
void Ai::init()
{
if (!openDB()) {
qWarning() << "Error when trying to open AI-DB.";
return;
}
int ver = version();
if (Ai::VERSION != ver) {
if (ver != 0) {
qWarning() << "AI-DB version mismatch. Exising version is"
<< ver << ", but required is" << Ai::VERSION;
deleteDB();
init();
if (!openDB()) {
qWarning() << "Error when trying to open AI-DB.";
return;
}
} else {
qWarning() << "AI-DB file doesn't exist.";
}
createDB();
}
}
bool Ai::openDB()
{
Settings *s = Settings::instance();
db = QSqlDatabase::addDatabase("QSQLITE","qt_sql_kaktusai_connection");
dbFilePath = s->getSettingsDir();
dbFilePath.append(QDir::separator()).append("ai.db");
dbFilePath = QDir::toNativeSeparators(dbFilePath);
db.setDatabaseName(dbFilePath);
return db.open();
}
void Ai::deleteDB()
{
db.close();
QSqlDatabase::removeDatabase("qt_sql_kaktusai_connection");
if (!QFile::exists(dbFilePath)) {
qWarning() << "AI-DB file doesn't exist.";
return;
}
QFile::remove(dbFilePath);
}
int Ai::version()
{
QSqlQuery query(db);
query.exec("PRAGMA user_version");
query.first();
return query.value(0).toInt();
}
void Ai::createDB()
{
QSqlQuery query(db);
query.exec("PRAGMA journal_mode = MEMORY");
query.exec("PRAGMA synchronous = OFF");
query.exec(QString("PRAGMA user_version = %1").arg(Ai::VERSION));
query.exec("CREATE TABLE IF NOT EXISTS entries ("
"id VARCHAR(50) PRIMARY KEY, "
"title TEXT, "
"evaluation INTEGER DEFAULT 0, "
"status INTEGER DEFAULT 1, "
"last_update TIMESTAMP "
");");
query.exec("CREATE INDEX IF NOT EXISTS entries_evaluation "
"ON entries(id, evaluation);");
}
void Ai::addEvaluation(const QString &id, const QString &title, int evaluation)
{
if (!db.isOpen()) {
qWarning() << "AI-DB is not open.";
return;
}
QSqlQuery query(db);
query.prepare("INSERT OR REPLACE INTO entries (id, title, evaluation, last_update) VALUES (?,?,?,?)");
query.addBindValue(id);
query.addBindValue(title);
query.addBindValue(evaluation);
query.addBindValue(QDateTime::currentDateTimeUtc().toTime_t());
if (!query.exec())
qWarning() << "SQL error:" << query.lastQuery();
}
int Ai::evaluationCount(const int evaluation)
{
if (!db.isOpen()) {
qWarning() << "AI-DB is not open.";
return 0;
}
QSqlQuery query(db);
query.prepare("SELECT count(*) FROM entries WHERE evaluation = ?");
query.addBindValue(evaluation);
if (!query.exec()) {
qWarning() << "SQL error:" << query.lastQuery();
return 0;
}
while (query.next()) {
return query.value(0).toInt();
}
return 0;
}
int Ai::evaluation(const QString &id)
{
if (!db.isOpen()) {
qWarning() << "AI-DB is not open.";
return 0;
}
QSqlQuery query(db);
query.prepare("SELECT evaluation FROM entries WHERE id = ? LIMIT 1");
query.addBindValue(id);
if (!query.exec()) {
qWarning() << "SQL error:" << query.lastQuery();
return 0;
}
while (query.next()) {
return query.value(0).toInt();
}
return 0;
}

View file

@ -1,49 +0,0 @@
/*
Copyright (C) 2017 Michal Kosciesza <michal@mkiol.net>
This file is part of Kaktus.
Kaktus 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.
Kaktus 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 Kaktus. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AI_H
#define AI_H
#include <QObject>
#include <QSqlDatabase>
#include <QString>
class Ai : public QObject
{
Q_OBJECT
public:
explicit Ai(QObject *parent = 0);
~Ai();
Q_INVOKABLE void init();
Q_INVOKABLE void addEvaluation(const QString &id, const QString &title, int evaluation);
Q_INVOKABLE int evaluation(const QString &id);
Q_INVOKABLE int evaluationCount(const int evaluation);
private:
const static int VERSION = 1;
QSqlDatabase db;
QString dbFilePath;
bool openDB();
int version();
void deleteDB();
void createDB();
};
#endif // AI_H

View file

@ -204,7 +204,7 @@ void DownloadManager::networkAccessibleChanged(QNetworkAccessManager::NetworkAcc
void DownloadManager::doDownload(DatabaseManager::CacheItem item)
{
qDebug() << "item.finalUrl:" << item.finalUrl;
//qDebug() << "item.finalUrl:" << item.finalUrl;
QNetworkRequest request(QUrl(item.finalUrl));
Settings *s = Settings::instance();
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)

View file

@ -45,7 +45,6 @@
#include "utils.h"
#include "settings.h"
#include "networkaccessmanagerfactory.h"
#include "ai.h"
int main(int argc, char *argv[])
{
@ -127,7 +126,6 @@ int main(int argc, char *argv[])
app->installTranslator(&translator);
settings->context = context;
Ai ai; ai.init();
QObject::connect(engine.data(), SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
@ -139,7 +137,6 @@ int main(int argc, char *argv[])
context->setContextProperty("dm", DownloadManager::instance());
context->setContextProperty("cache", CacheServer::instance());
context->setContextProperty("cserver", CacheServer::instance());
context->setContextProperty("ai", &ai);
context->setContextProperty("settings", settings);
#ifdef SAILFISH