| 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 "CReasonerEvaluationGroupRequestReasonerBucketCSVComparisonAnalyser.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Test { |
| 27 |
|
| 28 |
namespace Evaluation { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
CReasonerEvaluationGroupRequestReasonerBucketCSVComparisonAnalyser::CReasonerEvaluationGroupRequestReasonerBucketCSVComparisonAnalyser(double bucketsStart, double bucketsEnd, double bucketsIncreaseFactor, double timeoutsEnd) { |
| 33 |
mTimeoutsEnd = timeoutsEnd; |
| 34 |
mBucketsStart = bucketsStart; |
| 35 |
mBucketsEnd = bucketsEnd; |
| 36 |
mBucketsIncreaseFactor = bucketsIncreaseFactor; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
bool CReasonerEvaluationGroupRequestReasonerBucketCSVComparisonAnalyser::analyseGroupedEvaluationData(const QStringList& groubList, const QStringList& requestList, const QStringList& reasonerList, const QString& outputDirectory, CReasonerEvaluationAnalyseContext* context, CReasonerEvaluationGroupRequestSelector* selector) { |
| 41 |
|
| 42 |
|
| 43 |
QList<double> bucketsEndList; |
| 44 |
cint64 bucketCount = 1; |
| 45 |
bucketsEndList.append(mBucketsStart); |
| 46 |
double nextBucketsEnd = mBucketsStart; |
| 47 |
do { |
| 48 |
nextBucketsEnd *= mBucketsIncreaseFactor; |
| 49 |
bucketsEndList.append((cint64)qMin(nextBucketsEnd+0.5,mBucketsEnd)); |
| 50 |
++bucketCount; |
| 51 |
} while (nextBucketsEnd < mBucketsEnd); |
| 52 |
cint64 bucketTimeoutErrorCount = bucketCount+2; |
| 53 |
|
| 54 |
mOutputFileName = QString("%1").arg(selector->getOutputString()); |
| 55 |
|
| 56 |
cint64 reasonerCount = reasonerList.count(); |
| 57 |
bool hasSelectedRequestFile = false; |
| 58 |
|
| 59 |
QDir outDir(outputDirectory); |
| 60 |
outDir.mkpath(mOutputFileName); |
| 61 |
|
| 62 |
cint64** bucketTable = new cint64*[reasonerCount]; |
| 63 |
for (cint64 i = 0; i < reasonerCount; ++i) { |
| 64 |
cint64* tmpVec = new cint64[bucketTimeoutErrorCount]; |
| 65 |
bucketTable[i] = tmpVec; |
| 66 |
for (cint64 j = 0; j < bucketTimeoutErrorCount; ++j) { |
| 67 |
tmpVec[j] = 0; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
cint64** cummBucketTable = new cint64*[reasonerCount]; |
| 72 |
for (cint64 i = 0; i < reasonerCount; ++i) { |
| 73 |
cint64* tmpVec = new cint64[bucketTimeoutErrorCount]; |
| 74 |
cummBucketTable[i] = tmpVec; |
| 75 |
for (cint64 j = 0; j < bucketTimeoutErrorCount; ++j) { |
| 76 |
tmpVec[j] = 0; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
QHash<QString,cint64*> reasonerBucketHash; |
| 82 |
QHash<QString,cint64*> reasonerCummulativeBucketHash; |
| 83 |
cint64 index = 0; |
| 84 |
foreach (const QString& reasonerString, reasonerList) { |
| 85 |
reasonerBucketHash.insert(reasonerString,bucketTable[index]); |
| 86 |
reasonerCummulativeBucketHash.insert(reasonerString,cummBucketTable[index]); |
| 87 |
++index; |
| 88 |
} |
| 89 |
|
| 90 |
cint64 requestCount = 0; |
| 91 |
|
| 92 |
foreach (QString groupString, groubList) { |
| 93 |
|
| 94 |
if (selector->isGroupSelected(groupString)) { |
| 95 |
|
| 96 |
QSet<QString>* groupRequestList = getGroupRequests(groupString); |
| 97 |
foreach (QString requestString, *groupRequestList) { |
| 98 |
|
| 99 |
if (selector->isRequestSelected(groupString,requestString)) { |
| 100 |
|
| 101 |
bool allDataAvailable = true; |
| 102 |
foreach (QString reasonerString, reasonerList) { |
| 103 |
CReasonerEvaluationDataValue* evalData = getGroupRequestReasonerEvaluationData(groupString,requestString,reasonerString); |
| 104 |
if (!evalData || evalData->hasDataNotAvailableFlag()) { |
| 105 |
allDataAvailable = false; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
if (allDataAvailable) { |
| 111 |
|
| 112 |
|
| 113 |
hasSelectedRequestFile = true; |
| 114 |
requestCount++; |
| 115 |
|
| 116 |
|
| 117 |
QString requestReasonerTabList(requestString); |
| 118 |
foreach (const QString& reasonerString, reasonerList) { |
| 119 |
CReasonerEvaluationDataValue* evalData = getGroupRequestReasonerEvaluationData(groupString,requestString,reasonerString); |
| 120 |
CReasonerEvaluationDoubleDataValue* doubleEvalData = dynamic_cast<CReasonerEvaluationDoubleDataValue*>(evalData); |
| 121 |
if (doubleEvalData) { |
| 122 |
double doubleValue = doubleEvalData->getValue(); |
| 123 |
cint64 bucketID = 0; |
| 124 |
if (doubleValue > mTimeoutsEnd) { |
| 125 |
bucketID = bucketTimeoutErrorCount-1; |
| 126 |
} else if (doubleValue > mBucketsEnd) { |
| 127 |
bucketID = bucketTimeoutErrorCount-2; |
| 128 |
} else { |
| 129 |
foreach (double bucketEnd, bucketsEndList) { |
| 130 |
if (doubleValue < bucketEnd) { |
| 131 |
break; |
| 132 |
} |
| 133 |
++bucketID; |
| 134 |
} |
| 135 |
} |
| 136 |
cint64* bucketVec = reasonerBucketHash.value(reasonerString); |
| 137 |
++bucketVec[bucketID]; |
| 138 |
|
| 139 |
|
| 140 |
cint64* cummBucketVec = reasonerCummulativeBucketHash.value(reasonerString); |
| 141 |
++cummBucketVec[bucketID]; |
| 142 |
for (cint64 nextBucketId = bucketID+1; nextBucketId < bucketCount; ++nextBucketId) { |
| 143 |
++cummBucketVec[nextBucketId]; |
| 144 |
} |
| 145 |
|
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
if (hasSelectedRequestFile) { |
| 158 |
|
| 159 |
QStringList bucketList; |
| 160 |
QStringList cumulativeBucketList; |
| 161 |
|
| 162 |
CReasonerEvaluationTableMultiFormatOutputWriter<cint64> bucketOutputWriter; |
| 163 |
|
| 164 |
for (cint64 i = 0; i < bucketTimeoutErrorCount; ++i) { |
| 165 |
QString title; |
| 166 |
QString cumulativeTitle; |
| 167 |
if (i < bucketCount) { |
| 168 |
double bucketStart = 0; |
| 169 |
if (i > 0) { |
| 170 |
bucketStart = bucketsEndList.at(i-1); |
| 171 |
} |
| 172 |
double bucketEnd = bucketsEndList.at(i); |
| 173 |
title = QString("%1-%2").arg(bucketStart).arg(bucketEnd); |
| 174 |
cumulativeTitle = QString("<%1").arg(bucketEnd); |
| 175 |
} else if (i == bucketCount) { |
| 176 |
title = "timeout"; |
| 177 |
cumulativeTitle = "timeout"; |
| 178 |
} else { |
| 179 |
title = "error"; |
| 180 |
cumulativeTitle = "error"; |
| 181 |
} |
| 182 |
bucketList.append(title); |
| 183 |
cumulativeBucketList.append(cumulativeTitle); |
| 184 |
} |
| 185 |
|
| 186 |
bucketOutputWriter.addColumnTitles(QStringList()<<"Reasoner"<<bucketList); |
| 187 |
foreach (const QString& reasonerString, reasonerList) { |
| 188 |
bucketOutputWriter.addNewTableRow(reasonerString); |
| 189 |
for (cint64 bucketID = 0; bucketID < bucketTimeoutErrorCount; ++bucketID) { |
| 190 |
cint64* bucketVec = reasonerBucketHash.value(reasonerString); |
| 191 |
cint64 bucketData = bucketVec[bucketID]; |
| 192 |
bucketOutputWriter.addValuesToLastTableRow(QList<cint64>()<<bucketData); |
| 193 |
} |
| 194 |
} |
| 195 |
QStringList reasonerCompHighchartPlotFileList = bucketOutputWriter.writeCVSTable(QString(outputDirectory+mOutputFileName+"%1-stacked-buckets").arg(bucketCount)); |
| 196 |
if (context->isHighchartPlottingActivated()) { |
| 197 |
foreach (const QString& plotFileString, reasonerCompHighchartPlotFileList) { |
| 198 |
QString outputFile = plotFileString; |
| 199 |
outputFile.remove(".csv"); |
| 200 |
QString title = getPrettyTitleFromOutputFile(outputFile); |
| 201 |
context->getHighchartPlotter()->createReasonerStackedBucketPlot(plotFileString,context->getAdditionalTitleString()+" grouped by "+title+"",bucketList,outputFile,selector->getNameString()+" :: "+context->getAdditionalTitleString()); |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
// write in columns |
| 213 |
CReasonerEvaluationTableMultiFormatOutputWriter<cint64> bucketOutputWriter2; |
| 214 |
|
| 215 |
bucketOutputWriter2.addColumnTitles(QStringList()<<"Reasoner"<<reasonerList); |
| 216 |
|
| 217 |
for (cint64 i = 0; i < bucketTimeoutErrorCount; ++i) { |
| 218 |
QString title = bucketList.at(i); |
| 219 |
bucketOutputWriter2.addNewTableRow(title); |
| 220 |
foreach (const QString& reasonerString, reasonerList) { |
| 221 |
cint64* bucketVec = reasonerBucketHash.value(reasonerString); |
| 222 |
cint64 bucketData = bucketVec[i]; |
| 223 |
bucketOutputWriter2.addValuesToLastTableRow(QList<cint64>()<<bucketData); |
| 224 |
} |
| 225 |
} |
| 226 |
QStringList reasonerColumnCompHighchartPlotFileList = bucketOutputWriter2.writeCVSTable(QString(outputDirectory+mOutputFileName+"%1-column-buckets").arg(bucketCount)); |
| 227 |
if (context->isHighchartPlottingActivated()) { |
| 228 |
foreach (const QString& plotFileString, reasonerColumnCompHighchartPlotFileList) { |
| 229 |
QString outputFile = plotFileString; |
| 230 |
outputFile.remove(".csv"); |
| 231 |
QString title = getPrettyTitleFromOutputFile(outputFile); |
| 232 |
context->getHighchartPlotter()->createReasonerBucketPlot(plotFileString,context->getAdditionalTitleString()+" grouped by "+title+"",reasonerList,outputFile,selector->getNameString()+" :: "+context->getAdditionalTitleString()); |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
// write cumulative in columns |
| 247 |
CReasonerEvaluationTableMultiFormatOutputWriter<cint64> bucketOutputWriter3; |
| 248 |
|
| 249 |
bucketOutputWriter3.addColumnTitles(QStringList()<<"Reasoner"<<reasonerList); |
| 250 |
|
| 251 |
for (cint64 i = 0; i < bucketTimeoutErrorCount; ++i) { |
| 252 |
QString title = cumulativeBucketList.at(i); |
| 253 |
bucketOutputWriter3.addNewTableRow(title); |
| 254 |
foreach (const QString& reasonerString, reasonerList) { |
| 255 |
cint64* cummBucketVec = reasonerCummulativeBucketHash.value(reasonerString); |
| 256 |
cint64 bucketData = cummBucketVec[i]; |
| 257 |
bucketOutputWriter3.addValuesToLastTableRow(QList<cint64>()<<bucketData); |
| 258 |
} |
| 259 |
} |
| 260 |
QStringList reasonerCumulativeColumnCompHighchartPlotFileList = bucketOutputWriter3.writeCVSTable(QString(outputDirectory+mOutputFileName+"%1-cumulative-column-buckets").arg(bucketCount)); |
| 261 |
if (context->isHighchartPlottingActivated()) { |
| 262 |
foreach (const QString& plotFileString, reasonerCumulativeColumnCompHighchartPlotFileList) { |
| 263 |
QString outputFile = plotFileString; |
| 264 |
outputFile.remove(".csv"); |
| 265 |
QString title = getPrettyTitleFromOutputFile(outputFile); |
| 266 |
context->getHighchartPlotter()->createReasonerCumulativeBucketPlot(plotFileString,context->getAdditionalTitleString()+" grouped by "+title+"",reasonerList,outputFile,selector->getNameString()+" :: "+context->getAdditionalTitleString()); |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
for (cint64 i = 0; i < reasonerCount; ++i) { |
| 273 |
delete [] bucketTable[i]; |
| 274 |
} |
| 275 |
delete [] bucketTable; |
| 276 |
|
| 277 |
return true; |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
QString CReasonerEvaluationGroupRequestReasonerBucketCSVComparisonAnalyser::getPrettyTitleFromOutputFile(const QString& outputFile) { |
| 285 |
QString title = outputFile; |
| 286 |
title.remove("table"); |
| 287 |
cint64 slashPos = title.lastIndexOf("/"); |
| 288 |
if (slashPos >= 0) { |
| 289 |
title = title.mid(slashPos+1); |
| 290 |
} |
| 291 |
title.replace("-"," "); |
| 292 |
title.replace("stacked","Stacked"); |
| 293 |
title.replace("column","Column"); |
| 294 |
title.replace("buckets","Buckets"); |
| 295 |
title.replace("cumulative","Cumulative"); |
| 296 |
title.replace("grouped","Grouped"); |
| 297 |
return title; |
| 298 |
} |
| 299 |
|
| 300 |
}; // end namespace Evaluation |
| 301 |
|
| 302 |
}; // end namespace Test |
| 303 |
|
| 304 |
}; // end namespace Konclude |