| 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 "CReasonerEvaluationHTMLNavigationOverviewSummarizer.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Test { |
| 27 |
|
| 28 |
namespace Evaluation { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
CReasonerEvaluationHTMLNavigationOverviewSummarizer::CReasonerEvaluationHTMLNavigationOverviewSummarizer() { |
| 33 |
mDirLinConString = loadTemplateFromFile("Evaluation/Templates/Navigation/HTMLNavigationOverview/DirectlyLinkedContent.html"); |
| 34 |
mDirLinOveString = loadTemplateFromFile("Evaluation/Templates/Navigation/HTMLNavigationOverview/DirectlyLinkedOverview.html"); |
| 35 |
mDirLinSubString = loadTemplateFromFile("Evaluation/Templates/Navigation/HTMLNavigationOverview/DirectlyLinkedSubsection.html"); |
| 36 |
mDirLinSecString = loadTemplateFromFile("Evaluation/Templates/Navigation/HTMLNavigationOverview/DirectlyLinkedSection.html"); |
| 37 |
|
| 38 |
loadConditionedFiltersFromFile("Evaluation/Templates/Navigation/HTMLNavigationOverview/filters-conditioned.txt",&mFilterConditionedHash); |
| 39 |
loadFiltersFromFile("Evaluation/Templates/Navigation/HTMLNavigationOverview/filters.txt",&mFilterSet); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
CReasonerEvaluationHTMLNavigationOverviewSummarizer::~CReasonerEvaluationHTMLNavigationOverviewSummarizer() { |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
QString CReasonerEvaluationHTMLNavigationOverviewSummarizer::loadTemplateFromFile(const QString& fileString) { |
| 48 |
QString dataString; |
| 49 |
QFile file(fileString); |
| 50 |
if (file.open(QIODevice::ReadOnly)) { |
| 51 |
dataString = file.readAll(); |
| 52 |
} |
| 53 |
return dataString; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
bool CReasonerEvaluationHTMLNavigationOverviewSummarizer::loadFiltersFromFile(const QString& fileString, QSet<QString>* filterSet) { |
| 58 |
QFile file(fileString); |
| 59 |
if (filterSet && file.open(QIODevice::ReadOnly)) { |
| 60 |
while (!file.atEnd()) { |
| 61 |
QString filterLine = file.readLine(); |
| 62 |
if (!filterLine.startsWith("#")) { |
| 63 |
filterLine = filterLine.trimmed(); |
| 64 |
if (!filterLine.isEmpty()) { |
| 65 |
filterSet->insert(filterLine); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
return true; |
| 70 |
} |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
bool CReasonerEvaluationHTMLNavigationOverviewSummarizer::loadConditionedFiltersFromFile(const QString& fileString, QHash<QString,QStringList>* filterConditionedHash) { |
| 77 |
QFile file(fileString); |
| 78 |
if (filterConditionedHash && file.open(QIODevice::ReadOnly)) { |
| 79 |
while (!file.atEnd()) { |
| 80 |
QString filterLine = file.readLine(); |
| 81 |
if (!filterLine.startsWith("#")) { |
| 82 |
filterLine = filterLine.trimmed(); |
| 83 |
if (!filterLine.isEmpty()) { |
| 84 |
QStringList filterList = filterLine.split("\t"); |
| 85 |
if (filterList.count() >= 2) { |
| 86 |
QString conditionString = filterList.takeFirst(); |
| 87 |
filterConditionedHash->insertMulti(conditionString,filterList); |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
return true; |
| 93 |
} |
| 94 |
return false; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
bool CReasonerEvaluationHTMLNavigationOverviewSummarizer::isAcceptedByFilters(const QString& name) { |
| 99 |
bool accepted = true; |
| 100 |
if (!mFilterSet.isEmpty()) { |
| 101 |
bool oneAccepted = false; |
| 102 |
for (QSet<QString>::const_iterator it = mFilterSet.constBegin(), itEnd = mFilterSet.constEnd(); !oneAccepted && it != itEnd; ++it) { |
| 103 |
const QString& filterString(*it); |
| 104 |
if (name.contains(filterString)) { |
| 105 |
oneAccepted = true; |
| 106 |
} |
| 107 |
} |
| 108 |
accepted &= oneAccepted; |
| 109 |
} |
| 110 |
if (!mFilterConditionedHash.isEmpty()) { |
| 111 |
for (QHash<QString,QStringList>::const_iterator it = mFilterConditionedHash.constBegin(), itEnd = mFilterConditionedHash.constEnd(); accepted && it != itEnd; ++it) { |
| 112 |
const QString& conditionString(it.key()); |
| 113 |
const QStringList& filterStringList(it.value()); |
| 114 |
bool oneAccepted = false; |
| 115 |
bool noMatch = true; |
| 116 |
if (name.contains(conditionString)) { |
| 117 |
noMatch = false; |
| 118 |
foreach (const QString& filterString, filterStringList) { |
| 119 |
if (name.contains(filterString)) { |
| 120 |
oneAccepted = true; |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
if (!noMatch) { |
| 125 |
accepted &= oneAccepted; |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
return accepted; |
| 130 |
} |
| 131 |
|
| 132 |
QString CReasonerEvaluationHTMLNavigationOverviewSummarizer::createHTMLForDirectory(const QString& directoryString, const QString& relativePathString, const QString& groupFilterString, cint64* addContentCounter) { |
| 133 |
QString sectionString = mDirLinSecString; |
| 134 |
QDir directory(directoryString); |
| 135 |
QStringList subDirStringList = directory.entryList(QDir::Dirs); |
| 136 |
QStringList fileStringList = directory.entryList(QDir::Files); |
| 137 |
QString sectionContentsString; |
| 138 |
cint64 addedContentCount = 0; |
| 139 |
foreach (const QString& fileString, fileStringList) { |
| 140 |
if (fileString.endsWith(".html") && isAcceptedByFilters(relativePathString+fileString)) { |
| 141 |
QString secConString = mDirLinConString; |
| 142 |
QString titleString = fileString; |
| 143 |
titleString.replace(".html",""); |
| 144 |
secConString.replace("$$_CONTENT_LINK_$$",relativePathString+fileString); |
| 145 |
secConString.replace("$$_CONTENT_TITLE_$$",titleString); |
| 146 |
sectionContentsString += secConString; |
| 147 |
++addedContentCount; |
| 148 |
} |
| 149 |
} |
| 150 |
sectionString.replace("$$_SECTION_CONTENT_$$",sectionContentsString); |
| 151 |
|
| 152 |
QString subsectionsString; |
| 153 |
foreach (const QString& subDirString, subDirStringList) { |
| 154 |
if (subDirString != "." && subDirString != "..") { |
| 155 |
|
| 156 |
bool groupFiltered = false; |
| 157 |
if (subDirString.contains("Grouped")) { |
| 158 |
groupFiltered = true; |
| 159 |
if (subDirString.contains(groupFilterString)) { |
| 160 |
groupFiltered = false; |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
if (!groupFiltered) { |
| 165 |
cint64 recursiveAddedContentCount = 0; |
| 166 |
QString subSecSectionString = createHTMLForDirectory(directoryString+subDirString+"/",relativePathString+subDirString+"/",groupFilterString,&recursiveAddedContentCount); |
| 167 |
if (recursiveAddedContentCount > 0) { |
| 168 |
addedContentCount += recursiveAddedContentCount; |
| 169 |
QString subSecString = mDirLinSubString; |
| 170 |
QString subSecTitleString = subDirString; |
| 171 |
subSecString.replace("$$_SECTION_TITLE_$$",subSecTitleString); |
| 172 |
subSecString.replace("$$_SECTIONS_$$",subSecSectionString); |
| 173 |
subsectionsString += subSecString; |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
if (addContentCounter) { |
| 179 |
*addContentCounter = addedContentCount; |
| 180 |
} |
| 181 |
sectionString.replace("$$_SUBSECTIONS_$$",subsectionsString); |
| 182 |
return sectionString; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
CReasonerEvaluationHTMLNavigationOverviewSummarizer* CReasonerEvaluationHTMLNavigationOverviewSummarizer::createHTMLNavigationOverview(const QString& directory, const QString& evaluationProgramName, const QStringList& reasonerNameList, const QStringList& filterNameList, cint64 testTimeout, cint64 testCount) { |
| 188 |
|
| 189 |
|
| 190 |
QString outputDir = directory; |
| 191 |
if (!outputDir.endsWith("/")) { |
| 192 |
outputDir.append("/"); |
| 193 |
} |
| 194 |
|
| 195 |
QStringList groupFilterList; |
| 196 |
groupFilterList.append(""); |
| 197 |
groupFilterList.append("Directory"); |
| 198 |
groupFilterList.append("Expressiveness"); |
| 199 |
groupFilterList.append("Profile"); |
| 200 |
|
| 201 |
|
| 202 |
foreach (const QString& groupString, groupFilterList) { |
| 203 |
QString outputFileString; |
| 204 |
if (!groupString.isEmpty()) { |
| 205 |
outputFileString = outputDir+QString("Only%1Grouped-DirectlyLinkedNavigationOverview.html").arg(groupString); |
| 206 |
} else { |
| 207 |
outputFileString = outputDir+QString("DirectlyLinkedNavigationOverview.html"); |
| 208 |
} |
| 209 |
QFile outputNavFile(outputFileString); |
| 210 |
if (outputNavFile.open(QIODevice::WriteOnly)) { |
| 211 |
outputNavFile.close(); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
foreach (const QString& groupString, groupFilterList) { |
| 217 |
QString outputFileString; |
| 218 |
if (!groupString.isEmpty()) { |
| 219 |
outputFileString = outputDir+QString("Only%1Grouped-DirectlyLinkedNavigationOverview.html").arg(groupString); |
| 220 |
} else { |
| 221 |
outputFileString = outputDir+QString("DirectlyLinkedNavigationOverview.html"); |
| 222 |
} |
| 223 |
QFile outputNavFile(outputFileString); |
| 224 |
if (outputNavFile.open(QIODevice::WriteOnly)) { |
| 225 |
|
| 226 |
QString overviewNavString = mDirLinOveString; |
| 227 |
|
| 228 |
|
| 229 |
overviewNavString.replace("$$_TEST_COUNT_$$",QString::number(testCount)); |
| 230 |
overviewNavString.replace("$$_TEST_TIMEOUT_$$",QString::number(testTimeout)); |
| 231 |
overviewNavString.replace("$$_EVALUATION_PROGRAM_$$",evaluationProgramName); |
| 232 |
overviewNavString.replace("$$_TEST_REASONERS_$$",reasonerNameList.join(", ")); |
| 233 |
overviewNavString.replace("$$_TEST_DATE_$$",QDateTime::currentDateTime().toString()); |
| 234 |
overviewNavString.replace("$$_TEST_VERSION_$$",CKoncludeInfo::getKoncludeVersionString()); |
| 235 |
overviewNavString.replace("$$_TEST_FILTERS_$$",filterNameList.join(", ")); |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
QString sectionString = createHTMLForDirectory(outputDir,"",groupString); |
| 240 |
overviewNavString.replace("$$_SECTIONS_$$",sectionString); |
| 241 |
|
| 242 |
outputNavFile.write(overviewNavString.toLocal8Bit()); |
| 243 |
|
| 244 |
outputNavFile.close(); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
return this; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
}; // end namespace Evaluation |
| 255 |
|
| 256 |
}; // end namespace Test |
| 257 |
|
| 258 |
}; // end namespace Konclude |