Skip to content

Commit

Permalink
Updated date searching to be much faster. Acts as a filter now
Browse files Browse the repository at this point in the history
  • Loading branch information
AmericanEnglish committed Dec 2, 2017
1 parent 64d9f8a commit bacba01
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 34 deletions.
51 changes: 39 additions & 12 deletions cpp/rsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
// and additionally it will also be designed to
// be done with QThread in conjuction with a
// master thread reading it data as it worked
rSearch::rSearch(QStringList Dates, QMap<QString, QRegularExpression> Params, QString Base, QStringList Files, QStringList *Entries, bool *Complete) {
rSearch::rSearch(QList<QDate> Dates, QMap<QString, QRegularExpression> Params, QString Base, QStringList Files, QStringList *Entries, bool *Complete) {
// Fill internal variables
dates = Dates;
bDate = Dates.at(0);
qDebug() << "bDate.isValid():" << bDate.isValid();
aDate = Dates.at(1);
qDebug() << "aDate.isValid():" << aDate.isValid();
params = Params;
base = Base;
files = Files;
Expand All @@ -38,12 +41,23 @@ void rSearch::run() {
// Run
qDebug() << "=rSearch: Beginning...";
// #pragma omp parallel for
QDate newDate;
QString file;
QString comp = "ChatLogyyyyMMdd_00.txt";
for (int i = 0; i < len; i++) {
if (*stopped) {
qDebug() << "=rSearch: Searching halted, shutting down...";
break;
}
entries[i] = searchFile(i);
file = files.at(i);
newDate = QDate::fromString(file, comp);
// qDebug() << file + ".isValid():" << newDate.isValid();
if (dateCheck(newDate)) {
entries[i] = searchFile(i);
}
else {
entries[i] = QStringList();
}
// Thread Saftey at its finest
complete[i] = true;
}
Expand All @@ -63,17 +77,30 @@ void rSearch::setStop(bool *cond) {
}

// Dates have to be done with QStringList
bool rSearch::dateCheck(QString date) {
bool rSearch::dateCheck(QDate date) {
// std::cout << "Place 7 paramlen=" << parameters.length() << std::endl;
if (!dates.at(0).isEmpty()) {
if (!dates.at(1).isEmpty()) {
return (dates.at(0) <= date) && (date <= dates.at(1));
// Checks if the date is valid
QDate newDate = date;
// if (!dates.at(0).isEmpty()) { // Checks for a valid date
if (bDate.isValid()) { // Checks for a valid date
// if (!dates.at(1).isEmpty()) { // Checks for a valid date
if (aDate.isValid()) { // Checks for a valid date
// qDebug() << bDate.toString("MM dd, yyy") + " <=" << newDate.toString("MM dd, yyyy") + " <=" << aDate.toString("MM dd, yyyy") + " :" <<
// ((bDate <= newDate) && (newDate <= aDate));
return (bDate <= newDate) && (newDate <= aDate);
}
return dates.at(0) <= date;
// qDebug() << bDate.toString("MM dd, yyy") + " <=" << newDate.toString("MM dd, yyyy") + " :" <<
// ((bDate <= newDate));
return bDate <= newDate;
}
else if (!dates.at(1).isEmpty()) {
return date <= dates.at(1);
// else if (!dates.at(1).isEmpty()) {
else if (aDate.isValid()) {
// qDebug() << newDate.toString("MM dd, yyyy") + " <=" << aDate.toString("MM dd, yyyy") + " :" <<
// ((newDate <= aDate));
return newDate <= aDate;
}
// qDebug() << bDate.toString("MM dd, yyy") + " <=" << newDate.toString("MM dd, yyyy") + " <=" << aDate.toString("MM dd, yyyy") + " :" <<
// ((bDate <= newDate) && (newDate <= aDate));
return true;
}

Expand Down Expand Up @@ -128,7 +155,7 @@ QStringList rSearch::buildLine(QStringList file, QString str, int start) {
// Main Functions
bool rSearch::full_check(QStringList line) {
// std::cout << "Place 6 linelen=" << line.length() << std::endl;
bool res1 = dateCheck(line.at(0));// &&
// bool res1 = dateCheck(line.at(0));// &&
// std::cout << "Place 12" << std::endl;
bool res2 = sidCheck(line.at(3)); // &&
// std::cout << "Place 13" << std::endl;
Expand All @@ -138,7 +165,7 @@ bool rSearch::full_check(QStringList line) {
// std::cout << "Place 15" << std::endl;
bool res5 = keywordCheck(line.at(5));
// std::cout << "Place 16" << std::endl;
return res1 && res2 && res3 && res4 && res5;
return res2 && res3 && res4 && res5;
}

// QStringList searchfile(QMap<QString, QStringList> parameters, QString filename) {
Expand Down
29 changes: 15 additions & 14 deletions cpp/widgets/chatdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,21 @@ void ChatDate::clearDate2() {
endLabel->setText(QString());
}

QStringList ChatDate::liquidate() {
QStringList results;
if (begin.isValid()) {
results << begin.toString("yyyy-MM-dd") + "T00:00:00";
}
else {
results << QString();
}
if (end.isValid()) {
results << end.toString("yyyy-MM-dd") + "T23:59:59";
}
else {
results << QString();
}
QList<QDate> ChatDate::liquidate() {
QList<QDate> results;
results << begin << end;
// if (begin.isValid()) {
// results << begin.toString("yyyy-MM-dd") + "T00:00:00";
// }
// else {
// results << QString();
// }
// if (end.isValid()) {
// results << end.toString("yyyy-MM-dd") + "T23:59:59";
// }
// else {
// results << QString();
// }

return results;
}
4 changes: 2 additions & 2 deletions cpp/widgets/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ Reader::Reader(QString basepath, QMap<QDate, QStringList> allData, QWidget *pare
}

// Dynamic Reader!
Reader::Reader(QString basepath, QStringList Files, QStringList Dates, QMap<QString, QRegularExpression> Params, QWidget *parent) : QWidget(parent) {
Reader::Reader(QString basepath, QStringList Files, QList<QDate> Dates, QMap<QString, QRegularExpression> Params, QWidget *parent) : QWidget(parent) {
qDebug() << "New reader has been spawned!";
initGui();
newSearch(basepath, Files, Dates, Params);
}

void Reader::newSearch(QString basepath, QStringList Files, QStringList Dates, QMap<QString, QRegularExpression> Params) {
void Reader::newSearch(QString basepath, QStringList Files, QList<QDate> Dates, QMap<QString, QRegularExpression> Params) {
base = basepath;
len = Files.length();
filesSearched->setMaximum(len);
Expand Down
7 changes: 4 additions & 3 deletions headers/rsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class rSearch : public QObject {
Q_OBJECT

public:
rSearch(QStringList Dates, QMap<QString, QRegularExpression> Params, QString Base, QStringList Files, QStringList *Entries, bool *Complete);
rSearch(QList<QDate> Dates, QMap<QString, QRegularExpression> Params, QString Base, QStringList Files, QStringList *Entries, bool *Complete);
~rSearch() {qDebug() << "=rSearch Destroyed!";}
// Variables
QStringList dates;
QMap<QString, QRegularExpression> params;
QString base;
QStringList files;
QStringList *entries;
QDate bDate;
QDate aDate;
bool *complete;
public slots:
void run();
Expand All @@ -38,7 +39,7 @@ class rSearch : public QObject {
bool pidCheck(QString name);
bool chatCheck(QString term);
bool keywordCheck(QString message);
bool dateCheck(QString date);
bool dateCheck(QDate date);
QStringList too_many_tabs(QStringList line);
QStringList buildLine(QStringList file, QString str, int start);
QStringList searchFile(int i);
Expand Down
2 changes: 1 addition & 1 deletion headers/widgets/chatdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ChatDate : public QWidget {
public:
ChatDate(QWidget *parent = 0);
// Methods
QStringList liquidate();
QList<QDate> liquidate();

// Variables

Expand Down
4 changes: 2 additions & 2 deletions headers/widgets/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class Reader : public QWidget {

public:
Reader(QString basepath, QMap<QDate, QStringList> allData, QWidget *parent = 0);
Reader(QString basepath, QStringList Files, QStringList Dates, QMap<QString, QRegularExpression> Params, QWidget *parent = 0);
Reader(QString basepath, QStringList Files, QList<QDate> Dates, QMap<QString, QRegularExpression> Params, QWidget *parent = 0);

// Methods
// void refresh(QString basepath, QMap<QDate, QStringList> allData);
void newSearch(QString basepath, QStringList Files, QStringList Dates, QMap<QString, QRegularExpression> Params);
void newSearch(QString basepath, QStringList Files, QList<QDate> Dates, QMap<QString, QRegularExpression> Params);
void clear();
void stopExecution();

Expand Down

0 comments on commit bacba01

Please sign in to comment.