Browse Source

editing

master
sepehrmoghiseh 2 years ago
parent
commit
9917d0f775
  1. 4
      appLogReader.pro
  2. 8
      appLogReaderCore/AppLogReaderApp.cpp
  3. 6
      appLogReaderCore/AppLogReaderApp.h
  4. 212
      appLogReaderCore/LinkedList.cpp
  5. 43
      appLogReaderCore/LinkedList.h
  6. 4
      appLogReaderCore/MainViewModel.cpp
  7. 13
      appLogReaderCore/Node.h
  8. 319
      appLogReaderCore/SortedLinkedList.cpp
  9. 43
      appLogReaderCore/SortedLinkedList.h
  10. 13
      appLogReaderCore/appLogReaderCore.pro
  11. 6
      appLogReaderQuick/main.cpp
  12. 13
      appLogReaderTest/LinkedListTest.cpp
  13. 11
      appLogReaderTest/LinkedListTest.h
  14. 21
      appLogReaderTest/appLogReaderTest.pro
  15. 36
      appLogReaderTest/main.cpp

4
appLogReader.pro

@ -2,6 +2,8 @@ TEMPLATE = subdirs
SUBDIRS += \
appLogReaderQuick \
appLogReaderCore
appLogReaderCore \
appLogReaderTest
appLogReaderQuick.depends += appLogReaderCore
appLogReaderTest.depends += appLogReaderCore

8
appLogReaderCore/AppLogReaderApp.cpp

@ -1,9 +1,9 @@
#include "appLogReaderApp.h"
#include "AppLogReaderApp.h"
#include "MainViewModel.h"
#include <QtCore/QCommandLineParser>
appLogReaderApp::appLogReaderApp(QObject *parent) :
AppLogReaderApp::AppLogReaderApp(QObject *parent) :
CoreApp(parent)
{
QCoreApplication::setApplicationName(QStringLiteral("appLogReader"));
@ -11,13 +11,13 @@ appLogReaderApp::appLogReaderApp(QObject *parent) :
QCoreApplication::setOrganizationName(QStringLiteral("Example Organization"));
}
void appLogReaderApp::performRegistrations()
void AppLogReaderApp::performRegistrations()
{
//if you are using a qt resource (e.g. "applogreadercore.qrc"), initialize it here
Q_INIT_RESOURCE(applogreadercore);
}
int appLogReaderApp::startApp(const QStringList &arguments)
int AppLogReaderApp::startApp(const QStringList &arguments)
{
QCommandLineParser parser;
parser.addVersionOption();

6
appLogReaderCore/AppLogReaderApp.h

@ -3,12 +3,12 @@
#include <QtMvvmCore/CoreApp>
class appLogReaderApp : public QtMvvm::CoreApp
class AppLogReaderApp : public QtMvvm::CoreApp
{
Q_OBJECT
public:
explicit appLogReaderApp(QObject *parent = nullptr);
explicit AppLogReaderApp(QObject *parent = nullptr);
protected:
void performRegistrations() override;
@ -16,6 +16,6 @@ protected:
};
#undef coreApp
#define coreApp static_cast<appLogReaderApp*>(CoreApp::instance())
#define coreApp static_cast<AppLogReaderApp*>(CoreApp::instance())
#endif // APPLOGREADERAPP_H

212
appLogReaderCore/LinkedList.cpp

@ -0,0 +1,212 @@
#include <QFile>
#include <iostream>
#include "LinkedList.h"
#include "Node.h"
#define SENDER 4
#define COMMAND 2
#define RECEIVER 4
#define TIME 11
using namespace std;
/*<============================================================================================================>*/
void LinkedList::qListLinked(Node* newNode, int count){
if(count == 0)
{
newNode->chainLen += 1;
_linkedList.append(newNode);
}
else
{
Node* tmp = _linkedList.last();
tmp->chainLen += 1;
while(tmp->next != NULL)
{
tmp = tmp->next;
}
tmp->next = newNode;
newNode->pre = tmp;
}
}
/*<============================================================================================================>*/
void LinkedList::pushBack(string sender, string receiver, string command, float time, int count) {
Node* newNode = new Node();
newNode->sender = sender;
newNode->command = command;
newNode->receiver = receiver;
newNode->time = time;
newNode->chainLen = 0;
newNode->next = NULL;
newNode->pre = NULL;
qListLinked(newNode, count);
}
/*<============================================================================================================>*/
void LinkedList::qListOmit(string line){
omitedLines.append(line);
}
/*<============================================================================================================>*/
void LinkedList::addToOmitList(int where){
omitedLines.insert(where + 1, "chain");
}
/*<============================================================================================================>*/
void LinkedList::removeOmitLast(){ //remove uncorrect format
omitedLines.removeLast();
}
/*<============================================================================================================>*/
void LinkedList::addTime(float time){ //addTime to null blocks in chain
Node* head = _linkedList.last();
while(head->next != NULL)
{
head = head->next;
}
if(head->time == NULL)
{
head->time = time;
}
else
{
while(head->time != NULL)
{
head = head->pre;
}
head->time = time;
}
}
/*<============================================================================================================>*/
void LinkedList::makeLinkedList(){
string subLine;
string sender;
string command;
string receiver;
string time;
float numFloat;
string lastLine;
int count = 0;
for(int i = 0; i < omitedLines.length(); i++)
{
if(omitedLines[i].find(">>>") != std::string::npos) //line with <<< init
{
subLine = omitedLines[i].substr(omitedLines[i].find(">") + SENDER);
sender = subLine.substr(0, subLine.find("|") - 1);
subLine = omitedLines[i].substr(omitedLines[i].find("|") + COMMAND);
command = subLine.substr(0, subLine.find("=") - 1);
subLine = omitedLines[i].substr(omitedLines[i].find("==>") + RECEIVER);
receiver = subLine.substr(0, subLine.find(","));
pushBack(sender, receiver, command, NULL, count); //add the line with null
//time
count++;
}
else if(omitedLines[i].find("<<<") != std::string::npos)
{
subLine =
omitedLines[i].substr(omitedLines[i].find("exec time:") + TIME);
time = subLine.substr(0, subLine.find(","));
numFloat = std::stof(time);
addTime(numFloat);
}
else if(omitedLines[i].find("chain") != std::string::npos) //add the time to the
//last null time variable
//in the chain
{
count = 0;
}
}
}
/*<============================================================================================================>*/
void LinkedList::chainDetector(){ //a function for finding the chains P.S: chain can
//have one block.
int count = 0;
for(int i = 0; i < omitedLines.length(); i++)
{
if(omitedLines[i].find(">>>") != std::string::npos)
{
count++;
}
if(omitedLines[i].find("<<<") != std::string::npos)
{
count--;
}
if(omitedLines[i] == "chain")
{
continue;
}
if(count == 0)
{
addToOmitList(i);
}
}
if(omitedLines.last() != "chain")
{
while(omitedLines.last() != "chain")
{
removeOmitLast();
}
}
}
/*<============================================================================================================>*/
void LinkedList::fileOpen(const QString& path){ //read the file & add them to a Qlist for easy
//access
fstream newFile;
newFile.open(path.toStdString(), ios::in);
if(newFile.is_open())
{
string line;
string subLine;
string secSubLine;
while(getline(newFile, line))
{
if(line.find(">>>") != std::string::npos)
{
subLine = line.substr(line.find(">"));
secSubLine = subLine.substr(0, subLine.find(","));
qListOmit(secSubLine);
}
else if(line.find("<<<") != std::string::npos)
{
subLine = line.substr(line.find("<"));
secSubLine = subLine.substr(0, subLine.find(","));
qListOmit(secSubLine);
}
}
}
newFile.close();
}
float LinkedList::convertTime(float input)
{
return input * 1000;
}
/*<============================================================================================================>*/
QList<Node*> LinkedList::Initiate(const QString& path){
fileOpen(path);
chainDetector();
makeLinkedList();
return _linkedList;
}
/*<============================================================================================================>*/

43
appLogReaderCore/LinkedList.h

@ -1,4 +1,41 @@
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#ifndef FILE_H
#define FILE_H
#include <string>
#include <fstream>
#include <iostream>
#include <QList>
using namespace std;
struct Node;
#endif // LINKEDLIST_H
class LinkedList
{
private:
QList<Node*> _linkedList;
QList<string> omitedLines;
Node* head;
void qListLinked(Node* newNode, int count);
void pushBack(string sender, string receiver, string command, float time, int count);
void qListOmit(string line);
void addToOmitList(int where);
void removeOmitLast();
void addTime(float time);
void makeLinkedList();
void chainDetector();
void fileOpen(const QString& path);
public:
QList<Node*> Initiate(const QString& path);
float convertTime(float input);
};
#endif //FILE_H

4
appLogReaderCore/MainViewModel.cpp

@ -1,12 +1,12 @@
#include "MainViewModel.h"
#include <QtMvvmCore/SettingsViewModel>
MainViewModel::MainViewModel(QObject *parent) :
ViewModel(parent),
_text(QStringLiteral("hello world"))
{}
{
}
QString MainViewModel::text() const
{
return _text;

13
appLogReaderCore/Node.h

@ -1,4 +1,15 @@
#ifndef NODE_H
#define NODE_H
#include <string>
struct Node {
std::string sender;
std::string receiver;
std::string command;
float time;
int chainLen;
#endif // NODE_H
Node* next;
Node* pre;
};
#endif //NODE_H

319
appLogReaderCore/SortedLinkedList.cpp

@ -1,6 +1,321 @@
#include <fstream>
#include <iostream>
#include <cstring>
#include <QtMath>
#include "SortedLinkedList.h"
SortedLinkedList::SortedLinkedList()
#include "Node.h"
#include <cmath>
SortedLinkedList::SortedLinkedList(QList<Node*> linkedList) :
defaultLinkedList(linkedList)
{
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::defaultLinkedListGetter(){
return defaultLinkedList;
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::timeSortingAsc(float start, float end){
if(start > 0 && end == FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->time >= start)
{
timeSortedLinkedListAsc.append(defaultLinkedList[i]);
}
}
}
else if(start > 0 && end < FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->time >= start && defaultLinkedList[i]->time <= end)
{
timeSortedLinkedListAsc.append(defaultLinkedList[i]);
}
}
}
else if(start <= 0 && end < FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->time <= end)
{
timeSortedLinkedListAsc.append(defaultLinkedList[i]);
}
}
}
else
{
timeSortedLinkedListAsc = defaultLinkedList;
}
if(!timeSortedLinkedListAsc.isEmpty())
{
for(int k = 1; k < timeSortedLinkedListAsc.length(); k++)
{
Node* temp = timeSortedLinkedListAsc[k];
int j = k - 1;
while(j >= 0 && temp->time <= timeSortedLinkedListAsc[j]->time)
{
timeSortedLinkedListAsc[j + 1] = timeSortedLinkedListAsc[j];
j = j - 1;
}
timeSortedLinkedListAsc[j + 1] = temp;
}
}
return timeSortedLinkedListAsc;
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::timeSortingDes(float start, float end){
if(start > 0 && end == FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->time >= start)
{
timeSortedLinkedListDes.append(defaultLinkedList[i]);
}
}
}
else if(start > 0 && end < FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->time >= start && defaultLinkedList[i]->time <= end)
{
timeSortedLinkedListDes.append(defaultLinkedList[i]);
}
}
}
else if(start <= 0 && end < FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->time <= end)
{
timeSortedLinkedListDes.append(defaultLinkedList[i]);
}
}
}
else
{
timeSortedLinkedListDes = defaultLinkedList;
}
if(!timeSortedLinkedListDes.isEmpty())
{
for(int k = 1; k < timeSortedLinkedListDes.length(); k++)
{
Node* temp = timeSortedLinkedListDes[k];
int j = k - 1;
while(j >= 0 && temp->time >= timeSortedLinkedListDes[j]->time)
{
timeSortedLinkedListDes[j + 1] = timeSortedLinkedListDes[j];
j = j - 1;
}
timeSortedLinkedListDes[j + 1] = temp;
}
}
return timeSortedLinkedListDes;
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::timeSorting(int dir, float start, float end){
switch(dir)
{
case 0:
return timeSortingAsc(start, end);
case 1:
return timeSortingDes(start, end);
default:
break;
}
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::chainLenSortingAsc(float start, float end){
if(start > 0 && end == FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->chainLen >= start)
{
chainLenSortedLinkedListAsc.append(defaultLinkedList[i]);
}
}
}
else if(start > 0 && end < FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->chainLen >= start && defaultLinkedList[i]->chainLen <= end)
{
chainLenSortedLinkedListAsc.append(defaultLinkedList[i]);
}
}
}
else if(start <= 0 && end < FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->chainLen <= end)
{
chainLenSortedLinkedListAsc.append(defaultLinkedList[i]);
}
}
}
else
{
chainLenSortedLinkedListAsc = defaultLinkedList;
}
if(!chainLenSortedLinkedListAsc.isEmpty())
{
for(int k = 1; k < chainLenSortedLinkedListAsc.length(); k++)
{
Node* temp = chainLenSortedLinkedListAsc[k];
int j = k - 1;
while(j >= 0 && temp->chainLen <= chainLenSortedLinkedListAsc[j]->chainLen)
{
chainLenSortedLinkedListAsc[j + 1] = chainLenSortedLinkedListAsc[j];
j = j - 1;
}
chainLenSortedLinkedListAsc[j + 1] = temp;
}
}
return chainLenSortedLinkedListAsc;
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::chainLenSortingDes(float start, float end){
if(start > 0 && end == FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->chainLen >= start)
{
chainLenSortedLinkedListDes.append(defaultLinkedList[i]);
}
}
}
else if(start > 0 && end < FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->chainLen >= start && defaultLinkedList[i]->chainLen <= end)
{
chainLenSortedLinkedListDes.append(defaultLinkedList[i]);
}
}
}
else if(start <= 0 && end < FP_INFINITE)
{
for(int i = 0; i < defaultLinkedList.length(); i++)
{
if(defaultLinkedList[i]->chainLen <= end)
{
chainLenSortedLinkedListDes.append(defaultLinkedList[i]);
}
}
}
else
{
chainLenSortedLinkedListDes = defaultLinkedList;
}
if(!chainLenSortedLinkedListDes.isEmpty())
{
for(int k = 1; k < chainLenSortedLinkedListDes.length(); k++)
{
Node* temp = chainLenSortedLinkedListDes[k];
int j = k - 1;
while(j >= 0 && temp->chainLen >= chainLenSortedLinkedListDes[j]->chainLen)
{
chainLenSortedLinkedListDes[j + 1] = chainLenSortedLinkedListDes[j];
j = j - 1;
}
chainLenSortedLinkedListDes[j + 1] = temp;
}
}
return chainLenSortedLinkedListDes;
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::chainLenSorting(int dir, float start, float end){
switch(dir)
{
case 0:
return chainLenSortingAsc(start, end);
case 1:
return chainLenSortingDes(start, end);
default:
break;
}
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::senderFilter(string filterWord){
transform(filterWord.begin(), filterWord.end(), filterWord.begin(), ::toupper); //uppercase
string iterate;
for(int i = 0; i < defaultLinkedList.length(); i++)
{
iterate = defaultLinkedList[i]->sender;
transform(iterate.begin(), iterate.end(), iterate.begin(), ::toupper); //uppercase
if(iterate.find(filterWord) == 0)
{
senderFilterLinkedList.append(defaultLinkedList[i]);
}
}
return senderFilterLinkedList;
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::receiverFilter(string filterWord){
transform(filterWord.begin(), filterWord.end(), filterWord.begin(), ::toupper); //uppercase
string iterate;
for(int i = 0; i < defaultLinkedList.length(); i++)
{
iterate = defaultLinkedList[i]->receiver;
transform(iterate.begin(), iterate.end(), iterate.begin(), ::toupper); //uppercase
if(iterate.find(filterWord) == 0)
{
receiverFilterLinkedList.append(defaultLinkedList[i]);
}
}
return receiverFilterLinkedList;
}
/*<============================================================================================================>*/
QList<Node*> SortedLinkedList::commandFilter(string filterWord){
transform(filterWord.begin(), filterWord.end(), filterWord.begin(), ::toupper); //uppercase
string iterate;
for(int i = 0; i < defaultLinkedList.length(); i++)
{
iterate = defaultLinkedList[i]->command;
transform(iterate.begin(), iterate.end(), iterate.begin(), ::toupper); //uppercase
if(iterate.find(filterWord) == 0)
{
commandFilterLinkedList.append(defaultLinkedList[i]);
}
}
return commandFilterLinkedList;
}
/*<============================================================================================================>*/

43
appLogReaderCore/SortedLinkedList.h

@ -1,11 +1,44 @@
#ifndef SORTEDLINKEDLIST_H
#define SORTEDLINKEDLIST_H
#ifndef SORTLINKEDLIST_H
#define SORTLINKEDLIST_H
#include <fstream>
#include <iostream>
#include <QList>
#include <QtMath>
#include "LinkedList.h"
class SortedLinkedList
{
private:
QList<Node*> defaultLinkedList;
QList<Node*> timeSortedLinkedListAsc;
QList<Node*> timeSortedLinkedListDes;
QList<Node*> chainLenSortedLinkedListAsc;
QList<Node*> chainLenSortedLinkedListDes;
QList<Node*> senderFilterLinkedList;
QList<Node*> receiverFilterLinkedList;
QList<Node*> commandFilterLinkedList;
QList<Node*> timeSortingAsc(float start = 0, float end = FP_INFINITE);
QList<Node*> timeSortingDes(float start = 0, float end = FP_INFINITE);
QList<Node*> chainLenSortingAsc(float start = 0, float end = FP_INFINITE);
QList<Node*> chainLenSortingDes(float start = 0, float end = FP_INFINITE);
public:
SortedLinkedList();
SortedLinkedList(QList<Node*> linkedList);
QList<Node*> timeSorting(int dir = 0, float start = 0, float end = FP_INFINITE);
QList<Node*> defaultLinkedListGetter();
QList<Node*> chainLenSorting(int dir = 0, float start = 0, float end = FP_INFINITE);
QList<Node*> senderFilter(string filterWord);
QList<Node*> receiverFilter(string filterWord);
QList<Node*> commandFilter(string filterWord);
};
#endif // SORTEDLINKEDLIST_H
#endif //SORTLINKEDLIST_H

13
appLogReaderCore/appLogReaderCore.pro

@ -9,12 +9,17 @@ TARGET = appLogReaderCore
DEFINES += QT_DEPRECATED_WARNINGS
HEADERS += \
appLogReaderApp.h \
MainViewModel.h
AppLogReaderApp.h \
LinkedList.h \
MainViewModel.h \
Node.h \
SortedLinkedList.h
SOURCES += \
appLogReaderApp.cpp \
MainViewModel.cpp
AppLogReaderApp.cpp \
LinkedList.cpp \
MainViewModel.cpp \
SortedLinkedList.cpp
RESOURCES += \
applogreadercore.qrc

6
appLogReaderQuick/main.cpp

@ -1,9 +1,9 @@
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <appLogReaderApp.h>
#include <AppLogReaderApp.h>
#include <MainViewModel.h>
QTMVVM_REGISTER_CORE_APP(appLogReaderApp)
#include <QtMvvmQuick/QuickPresenter>
QTMVVM_REGISTER_CORE_APP(AppLogReaderApp)
int main(int argc, char *argv[])
{

13
appLogReaderTest/LinkedListTest.cpp

@ -1,6 +1,17 @@
#include "LinkedListTest.h"
#include <QTest>
#include "SortedLinkedList.h"
#include "Node.h"
LinkedListTest::LinkedListTest()
{
}
void LinkedListTest::test()
{
LinkedList linkList;
auto l = linkList.Initiate("D:/git commands/App-Log-Reader/test.usl");
SortedLinkedList t(l);
auto result = t.chainLenSorting(1, 2);
QCOMPARE(result.last()->chainLen, 2);
}

11
appLogReaderTest/LinkedListTest.h

@ -1,11 +1,16 @@
#ifndef LINKEDLISTTEST_H
#define LINKEDLISTTEST_H
#include <QObject>
class LinkedListTest
class LinkedListTest : public QObject
{
Q_OBJECT
public:
LinkedListTest();
private slots:
void test();
};
#endif // LINKEDLISTTEST_H
#endif //LINKEDLISTTEST_H

21
appLogReaderTest/appLogReaderTest.pro

@ -6,4 +6,23 @@ CONFIG -= app_bundle
TEMPLATE = app
SOURCES += tst_test.cpp
# Link with core project
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../appLogReaderCore/release/ -lappLogReaderCore
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../appLogReaderCore/debug/ -lappLogReaderCore
else:unix: LIBS += -L$$OUT_PWD/../appLogReaderCore/ -lappLogReaderCore
INCLUDEPATH += $$PWD/../appLogReaderCore
DEPENDPATH += $$PWD/../appLogReaderCore
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../appLogReaderCore/release/libappLogReaderCore.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../appLogReaderCore/debug/libappLogReaderCore.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../appLogReaderCore/release/appLogReaderCore.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../appLogReaderCore/debug/appLogReaderCore.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../appLogReaderCore/libappLogReaderCore.a
SOURCES += \
LinkedListTest.cpp \
main.cpp
HEADERS += \
LinkedListTest.h

36
appLogReaderTest/main.cpp

@ -1,35 +1,9 @@
#include <QtTest>
// add necessary includes here
class test : public QObject
{
Q_OBJECT
public:
test();
~test();
private slots:
void test_case1();
};
test::test()
#include <LinkedListTest.h>
int main()
{
int failedTestsCount = 0;
failedTestsCount += QTest::qExec(new LinkedListTest);
return failedTestsCount;
}
test::~test()
{
}
void test::test_case1()
{
}
QTEST_APPLESS_MAIN(test)
#include "tst_test.moc"

Loading…
Cancel
Save