Debian Codegraph @

Source/Test/Evaluation/CReasonerEvaluationAnalyserChecker.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CReasonerEvaluationAnalyserChecker.h"
22
23
24 namespace Konclude {
25
26 namespace Test {
27
28 namespace Evaluation {
29
30
31
32 CReasonerEvaluationAnalyserChecker::CReasonerEvaluationAnalyserChecker() : CLogIdentifier("::Konclude::Test::Evaluation::AnalyserUpdateChecker",this) {
33 }
34
35
36 CReasonerEvaluationAnalyserChecker::~CReasonerEvaluationAnalyserChecker() {
37 }
38
39
40 bool CReasonerEvaluationAnalyserChecker::loadAnalysingUpdateCheckFile(const QString& analyserCheckFileString) {
41 mAnalysedResponseCountHash.clear();
42 QFile analyserCheckFile(analyserCheckFileString);
43 if (analyserCheckFile.open(QIODevice::ReadOnly)) {
44 LOG(INFO,getLogDomain(),logTr("Loading alraedy analysed data from file '%1'.").arg(analyserCheckFileString),this);
45 while (!analyserCheckFile.atEnd()) {
46 QString analysedCheckLine(analyserCheckFile.readLine());
47 QStringList analysedParsedList = analysedCheckLine.trimmed().split(" ");
48 if (analysedParsedList.count() == 2) {
49 cint64 analysdCount = analysedParsedList.first().toInt();
50 QString analysedFileString = analysedParsedList.last();
51 if (analysdCount > 0 && !analysedFileString.isEmpty()) {
52 mAnalysedResponseCountHash.insert(analysedFileString,analysdCount);
53 }
54 }
55 }
56 analyserCheckFile.close();
57 return true;
58 } else {
59 LOG(ERROR,getLogDomain(),logTr("Could not load alraedy analysed data from file '%1'.").arg(analyserCheckFileString),this);
60 }
61 return false;
62 }
63
64
65 bool CReasonerEvaluationAnalyserChecker::saveAnalysingUpdateCheckFile(const QString& analyserCheckFileString) {
66 QFile analyserCheckFile(analyserCheckFileString);
67 if (analyserCheckFile.open(QIODevice::WriteOnly)) {
68 LOG(INFO,getLogDomain(),logTr("Save updated analysed data to file '%1'.").arg(analyserCheckFileString),this);
69 for (QHash<QString,cint64>::const_iterator it = mAnalysedResponseCountHash.constBegin(), itEnd = mAnalysedResponseCountHash.constEnd(); it != itEnd; ++it) {
70 QString writeLine = QString("%1 %2\n").arg(it.value()).arg(it.key());
71 analyserCheckFile.write(writeLine.toLocal8Bit());
72 }
73 analyserCheckFile.close();
74 return true;
75 } else {
76 LOG(ERROR,getLogDomain(),logTr("Could not save updated analysed data to file '%1'.").arg(analyserCheckFileString),this);
77 }
78 return false;
79 }
80
81
82 bool CReasonerEvaluationAnalyserChecker::checkAnalysingUpdateNecessary(const QStringList& reasonerPathList, const QString& analyserCheckFileString, cint64 maxAnalyseCount) {
83 mMaxAnalyseCount = maxAnalyseCount;
84 bool updateNecessary = false;
85 loadAnalysingUpdateCheckFile(analyserCheckFileString);
86 foreach (const QString& reasonerPath, reasonerPathList) {
87 updateNecessary |= checkAnalysingUpdateNecessary(reasonerPath);
88 }
89 return updateNecessary;
90 }
91
92 bool CReasonerEvaluationAnalyserChecker::checkAnalysingUpdateNecessary(const QString& baseDirectory) {
93 return checkDirsAnalysingUpdateNecessary(baseDirectory,baseDirectory);
94 }
95
96 bool CReasonerEvaluationAnalyserChecker::checkDirsAnalysingUpdateNecessary(const QString& directory, const QString& baseDirectory) {
97 bool updateNecessary = false;
98 QDir dir(directory);
99 QStringList dirList = dir.entryList(QDir::Dirs,QDir::Name|QDir::IgnoreCase);
100 foreach (QString dirString, dirList) {
101 if (dirString != "." && dirString != "..") {
102 LOG(INFO,getLogDomain(),logTr("Checking analysing update necessary for data from '%1'.").arg(dirString),this);
103 updateNecessary |= checkFilesAnalysingUpdateNecessary(directory+dirString+"/",dirString);
104 }
105 }
106 foreach (QString dirString, dirList) {
107 if (dirString != "." && dirString != "..") {
108 updateNecessary |= checkDirsAnalysingUpdateNecessary(directory+dirString+"/",baseDirectory);
109 }
110 }
111 return updateNecessary;
112 }
113
114
115 bool CReasonerEvaluationAnalyserChecker::checkFilesAnalysingUpdateNecessary(const QString& directory, const QString& requestFileString) {
116 bool updateNecessary = false;
117 QDir dir(directory);
118 QStringList fileList = dir.entryList(QDir::Files,QDir::Name|QDir::IgnoreCase);
119 cint64 fileCount = fileList.count();
120 cint64 analysedCount = mAnalysedResponseCountHash.value(directory,0);
121 if (analysedCount < mMaxAnalyseCount) {
122 if (fileCount > analysedCount) {
123 analysedCount = qMin(mMaxAnalyseCount,fileCount);
124 updateNecessary = true;
125 mAnalysedResponseCountHash.insert(directory,analysedCount);
126 }
127 }
128 return updateNecessary;
129 }
130
131 }; // end namespace Evaluation
132
133 }; // end namespace Test
134
135 }; // end namespace Konclude