Refactor includes and add AccountInfoScreener functionality
Updated include paths for consistent structure under the `db` directory. Added `AccountInfoScreener` for parsing card data using Tesseract OCR and enhanced related models. Removed unused code and simplified main workflow.
This commit is contained in:
parent
4b6f740d62
commit
2ac5dcc5e5
Binary file not shown.
@ -2,7 +2,7 @@
|
|||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
#include "AccountDAO.h"
|
#include "AccountDAO.h"
|
||||||
|
|
||||||
#include "AccountInfo.h"
|
#include "db/AccountInfo.h"
|
||||||
#include "DatabaseManager.h"
|
#include "DatabaseManager.h"
|
||||||
|
|
||||||
bool AccountDAO::upsertAccount(const AccountInfo &info) {
|
bool AccountDAO::upsertAccount(const AccountInfo &info) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "AccountInfo.h"
|
#include "db/AccountInfo.h"
|
||||||
|
|
||||||
class AccountDAO {
|
class AccountDAO {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
#include "DeviceDAO.h"
|
#include "DeviceDAO.h"
|
||||||
#include "DatabaseManager.h"
|
#include "DatabaseManager.h"
|
||||||
#include "DeviceInfo.h"
|
#include "db/DeviceInfo.h"
|
||||||
|
|
||||||
QList<DeviceInfo> DeviceDAO::getAllDevices() {
|
QList<DeviceInfo> DeviceDAO::getAllDevices() {
|
||||||
QList<DeviceInfo> devices;
|
QList<DeviceInfo> devices;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <DeviceInfo.h>
|
#include <db/DeviceInfo.h>
|
||||||
|
|
||||||
class DeviceDAO {
|
class DeviceDAO {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "TransactionInfo.h"
|
#include "db/TransactionInfo.h"
|
||||||
|
|
||||||
class TransactionDAO {
|
class TransactionDAO {
|
||||||
public:
|
public:
|
||||||
|
|||||||
39
main.cpp
39
main.cpp
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "database/DatabaseManager.h"
|
#include "database/DatabaseManager.h"
|
||||||
#include "database/dao/CommonDataDAO.h"
|
#include "database/dao/CommonDataDAO.h"
|
||||||
|
#include "db/AccountInfoScreener.h"
|
||||||
#include "services/DeviceScreener.h"
|
#include "services/DeviceScreener.h"
|
||||||
|
|
||||||
void setupWorkerAndThread(QCoreApplication& app) {
|
void setupWorkerAndThread(QCoreApplication& app) {
|
||||||
@ -40,39 +41,19 @@ void setupWorkerAndThread(QCoreApplication& app) {
|
|||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
QList<Card> cards = AccountInfoScreener::parseCardData(QByteArray());
|
||||||
|
qDebug() << "Cards data: " << cards.length();
|
||||||
|
|
||||||
// Setup worker and thread
|
// setupWorkerAndThread(app);
|
||||||
setupWorkerAndThread(app);
|
|
||||||
|
|
||||||
const QDateTime current = QDateTime::currentDateTimeUtc();
|
|
||||||
qDebug() << "Обновление lastScan:" << CommonDataDAO::updateLastScan(current);
|
|
||||||
|
|
||||||
const QDateTime savedTime = CommonDataDAO::getLastScan();
|
|
||||||
qDebug() << "Сохранившееся время:" << savedTime.toString();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// // tesseract, tesseract-lang
|
// const QDateTime current = QDateTime::currentDateTimeUtc();
|
||||||
// QImage image("./images/img.png");
|
// qDebug() << "Обновление lastScan:" << CommonDataDAO::updateLastScan(current);
|
||||||
// if (image.isNull()) {
|
|
||||||
// qDebug() << "Cant load the image";
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
// image = image.convertToFormat(QImage::Format_Grayscale8);
|
// const QDateTime savedTime = CommonDataDAO::getLastScan();
|
||||||
|
// qDebug() << "Сохранившееся время:" << savedTime.toString();
|
||||||
//
|
//
|
||||||
// tesseract::TessBaseAPI tess;
|
|
||||||
// if (tess.Init(nullptr, "rus")) {
|
|
||||||
// qDebug() << "Ошибка инициализации Tesseract с русским языком....";
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
// tess.SetImage(image.bits(), image.width(), image.height(), 1, image.bytesPerLine());
|
// MainWindow window;
|
||||||
//
|
// window.show();
|
||||||
// QString result = QString::fromUtf8(tess.GetUTF8Text());
|
|
||||||
// qDebug() << "Распознанный текст:" << result;
|
|
||||||
|
|
||||||
|
|
||||||
MainWindow window;
|
|
||||||
window.show();
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
14
models/android/Card.h
Normal file
14
models/android/Card.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
struct Card {
|
||||||
|
QString name;
|
||||||
|
QString description;
|
||||||
|
double amount;
|
||||||
|
|
||||||
|
[[nodiscard]] QString toString() const {
|
||||||
|
return QString("Number: %1 | Type: %2 | Amount: %3")
|
||||||
|
.arg(name, description, QString::number(amount, 'f', 2));
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -7,7 +7,7 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <dao/DeviceDAO.h>
|
#include <dao/DeviceDAO.h>
|
||||||
#include <DeviceInfo.h>
|
#include <db/DeviceInfo.h>
|
||||||
|
|
||||||
DeviceScreener::DeviceScreener(QObject *parent) : QObject(parent) {
|
DeviceScreener::DeviceScreener(QObject *parent) : QObject(parent) {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <dao/DeviceDAO.h>
|
#include <dao/DeviceDAO.h>
|
||||||
#include <DeviceInfo.h>
|
#include <db/DeviceInfo.h>
|
||||||
|
|
||||||
class DeviceScreener final : public QObject {
|
class DeviceScreener final : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
56
services/db/AccountInfoScreener.cpp
Normal file
56
services/db/AccountInfoScreener.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "AccountInfoScreener.h"
|
||||||
|
#include <QImage>
|
||||||
|
#include <QList>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <qregularexpression.h>
|
||||||
|
|
||||||
|
#include "android/Card.h"
|
||||||
|
#include "tesseract/baseapi.h"
|
||||||
|
|
||||||
|
QList<Card> AccountInfoScreener::parseCardData(const QByteArray &imageData) {
|
||||||
|
QList<Card> cards;
|
||||||
|
// QImage image;
|
||||||
|
// if (!image.loadFromData(imageData)) {
|
||||||
|
// return {};
|
||||||
|
// }
|
||||||
|
// image = image.convertToFormat(QImage::Format_Grayscale8);
|
||||||
|
|
||||||
|
QImage image("./images/img.png");
|
||||||
|
if (image.isNull()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// важная часть, без нее не парсит
|
||||||
|
image = image.convertToFormat(QImage::Format_Grayscale8);
|
||||||
|
|
||||||
|
tesseract::TessBaseAPI tess;
|
||||||
|
if (tess.Init(nullptr, "rus")) {
|
||||||
|
qDebug() << "Ошибка инициализации Tesseract с русским языком....";
|
||||||
|
}
|
||||||
|
|
||||||
|
tess.SetImage(image.bits(), image.width(), image.height(), 1, image.bytesPerLine());
|
||||||
|
|
||||||
|
const QString result = QString::fromUtf8(tess.GetUTF8Text());
|
||||||
|
qDebug() << "Распознанный текст:" << result;
|
||||||
|
|
||||||
|
|
||||||
|
const QRegularExpression re(R"((дебетовая(?:, цифровая)?),\s*\*(\d{4})\s+([\d]+\.\d{2})\s*Р)",
|
||||||
|
QRegularExpression::CaseInsensitiveOption);
|
||||||
|
|
||||||
|
QRegularExpressionMatchIterator i = re.globalMatch(result);
|
||||||
|
|
||||||
|
while (i.hasNext()) {
|
||||||
|
auto card = Card();
|
||||||
|
bool ok;
|
||||||
|
QRegularExpressionMatch match = i.next();
|
||||||
|
const double amount = match.captured(3).toDouble(&ok);
|
||||||
|
if (ok) {
|
||||||
|
card.amount = amount;
|
||||||
|
card.name = match.captured(2);
|
||||||
|
card.description = match.captured(1);
|
||||||
|
cards.append(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cards;
|
||||||
|
}
|
||||||
8
services/db/AccountInfoScreener.h
Normal file
8
services/db/AccountInfoScreener.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "android/Card.h"
|
||||||
|
|
||||||
|
class AccountInfoScreener {
|
||||||
|
public:
|
||||||
|
[[nodiscard]] static QList<Card> parseCardData(const QByteArray &imageData);
|
||||||
|
};
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "DeviceInfo.h"
|
#include "db/DeviceInfo.h"
|
||||||
|
|
||||||
class DeviceWidget final : public QWidget {
|
class DeviceWidget final : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
|
||||||
#include "DeviceInfo.h"
|
#include "db/DeviceInfo.h"
|
||||||
#include "DeviceWidget.h"
|
#include "DeviceWidget.h"
|
||||||
#include "dao/DeviceDAO.h"
|
#include "dao/DeviceDAO.h"
|
||||||
#include "widget/FlowLayout.h"
|
#include "widget/FlowLayout.h"
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "DeviceInfo.h"
|
#include "db/DeviceInfo.h"
|
||||||
#include "widget/FlowLayout.h"
|
#include "widget/FlowLayout.h"
|
||||||
|
|
||||||
class MainWindow final : public QMainWindow {
|
class MainWindow final : public QMainWindow {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user