| 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 "CReasonerEvaluationGNUPlotPlotter.h" |
| 22 |
#include "CReasonerEvaluationAnalyseContext.h" |
| 23 |
|
| 24 |
|
| 25 |
namespace Konclude { |
| 26 |
|
| 27 |
namespace Test { |
| 28 |
|
| 29 |
namespace Evaluation { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
CReasonerEvaluationGNUPlotPlotter::CReasonerEvaluationGNUPlotPlotter(CReasonerEvaluationAnalyseContext* context) { |
| 34 |
mContext = context; |
| 35 |
|
| 36 |
|
| 37 |
//mReasCompTemplateString = |
| 38 |
// "set terminal svg size 1280,800 dynamic enhanced fname 'arial' fsize 10 mousing name \"$$_PLOT_NAME_$$\" butt solid\r\n" |
| 39 |
// "set output '$$_PLOT_FILE_$$'\r\n" |
| 40 |
// "set style fill solid 1.00 border lt -1\r\n" |
| 41 |
// "set style histogram clustered gap 5 title offset character 0, 0, 0\r\n" |
| 42 |
// "set style data histograms\r\n" |
| 43 |
// "set xtics border in scale 0,00 nomirror rotate by -45 offset character 0, 0, 0 autojustify\r\n" |
| 44 |
// "set xtics norangelimit font \",8\"\r\n" |
| 45 |
// "set title \"$$_PLOT_TITLE_$$\"\r\n" |
| 46 |
// "set bmargin 12\r\n" |
| 47 |
// "set grid ytics lt 0 lw 0.2 lc rgb \"#000000\"\r\n" |
| 48 |
// "plot '$$_PLOT_DATA_$$' "; |
| 49 |
|
| 50 |
|
| 51 |
mReasCompTemplateString = |
| 52 |
"set terminal svg size 1280,800\r\n" |
| 53 |
"set output '$$_PLOT_FILE_$$'\r\n" |
| 54 |
"set style fill solid 1.00 border lt -1\r\n" |
| 55 |
"set style histogram clustered gap 5 title offset character 0, 0, 0\r\n" |
| 56 |
"set style data histograms\r\n" |
| 57 |
"set xtics border in scale 0,00 nomirror rotate by -45 offset character 0, 0, 0 autojustify\r\n" |
| 58 |
"set xtics norangelimit font \",8\"\r\n" |
| 59 |
"set title \"$$_PLOT_TITLE_$$\"\r\n" |
| 60 |
"set bmargin 10\r\n" |
| 61 |
"set grid ytics lt 0 lw 0.2 lc rgb \"#000000\"\r\n" |
| 62 |
"plot '$$_PLOT_DATA_$$' "; |
| 63 |
|
| 64 |
mReasOverTemplateString = |
| 65 |
"set terminal svg size 1280,800\r\n" |
| 66 |
"set output '$$_PLOT_FILE_$$'\r\n" |
| 67 |
"set title \"$$_PLOT_TITLE_$$\"\r\n" |
| 68 |
"set log y\r\n" |
| 69 |
"set grid ytics lt 0 lw 0.2 lc rgb \"#000000\"\r\n" |
| 70 |
"plot '$$_PLOT_DATA_$$' "; |
| 71 |
|
| 72 |
|
| 73 |
mReasColorHash.insert("FaCT++","#E4FECA"); |
| 74 |
mReasColorHash.insert("HermiT","#BBD2FF"); |
| 75 |
mReasColorHash.insert("Pellet","#404040"); |
| 76 |
mReasColorHash.insert("Konclude","#3784A0"); |
| 77 |
mReasColorHash.insert("Average","#F7C298"); |
| 78 |
mReasColorHash.insert("Min","#D5803D"); |
| 79 |
mReasColorHash.insert("Max","#603326"); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
CReasonerEvaluationGNUPlotPlotter::~CReasonerEvaluationGNUPlotPlotter() { |
| 84 |
} |
| 85 |
|
| 86 |
CReasonerEvaluationGNUPlotPlotter* CReasonerEvaluationGNUPlotPlotter::createReasonerComparisonPlot(const QString& dataFileString, const QString& plotTitle, const QStringList& reasonerNameList, const QString& outputFile) { |
| 87 |
QString outputScriptFileString(outputFile+".gpl"); |
| 88 |
QString outputFileString(outputFile+".svg"); |
| 89 |
QFile dataFile(dataFileString); |
| 90 |
QMap<QString,cint64> reasonerStringIndexMap; |
| 91 |
if (dataFile.open(QIODevice::ReadOnly)) { |
| 92 |
QString titleLineString = dataFile.readLine(); |
| 93 |
cint64 nextIndex = 0; |
| 94 |
cint64 nextStartPos = 0; |
| 95 |
cint64 nextEndPos = 0; |
| 96 |
|
| 97 |
bool hasNextTitle = true; |
| 98 |
while (hasNextTitle) { |
| 99 |
nextEndPos = titleLineString.indexOf("\t",nextStartPos); |
| 100 |
if (nextEndPos <= -1) { |
| 101 |
nextEndPos = titleLineString.length(); |
| 102 |
hasNextTitle = false; |
| 103 |
} |
| 104 |
|
| 105 |
QString nextTitle = titleLineString.mid(nextStartPos,nextEndPos-nextStartPos); |
| 106 |
nextTitle.replace("\"",""); |
| 107 |
if (!nextTitle.isEmpty()) { |
| 108 |
reasonerStringIndexMap.insert(nextTitle,nextIndex++); |
| 109 |
} |
| 110 |
nextStartPos = nextEndPos+1; |
| 111 |
|
| 112 |
} |
| 113 |
dataFile.close(); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
QFile outputScriptFile(outputScriptFileString); |
| 118 |
if (outputScriptFile.open(QIODevice::WriteOnly)) { |
| 119 |
|
| 120 |
QString plotScriptString = mReasCompTemplateString; |
| 121 |
QString plotNameString = outputFile; |
| 122 |
cint64 lastSlashPos = plotNameString.lastIndexOf("/"); |
| 123 |
if (lastSlashPos >= 0) { |
| 124 |
plotNameString = plotNameString.mid(lastSlashPos+1); |
| 125 |
} |
| 126 |
plotNameString.replace(" ","_"); |
| 127 |
plotNameString.replace("-table",""); |
| 128 |
plotNameString.replace("-","_"); |
| 129 |
plotScriptString.replace("$$_PLOT_NAME_$$",plotNameString); |
| 130 |
plotScriptString.replace("$$_PLOT_FILE_$$",outputFileString); |
| 131 |
plotScriptString.replace("$$_PLOT_TITLE_$$",plotTitle); |
| 132 |
plotScriptString.replace("$$_PLOT_DATA_$$",dataFileString); |
| 133 |
|
| 134 |
|
| 135 |
bool validColorsForAllReasoners = true; |
| 136 |
QSet<QString> usedReasonerColorSet; |
| 137 |
foreach (QString reasonerString, reasonerNameList) { |
| 138 |
QString colorString = getColorString(reasonerString,&usedReasonerColorSet); |
| 139 |
if (colorString.isEmpty()) { |
| 140 |
validColorsForAllReasoners = false; |
| 141 |
} |
| 142 |
} |
| 143 |
QString colorString = getColorString("Average",&usedReasonerColorSet); |
| 144 |
if (colorString.isEmpty()) { |
| 145 |
validColorsForAllReasoners = false; |
| 146 |
} |
| 147 |
|
| 148 |
cint64 reasonerIndex = 0; |
| 149 |
foreach (QString reasonerString, reasonerNameList) { |
| 150 |
QString plotReasonerString; |
| 151 |
if (reasonerIndex++ == 0) { |
| 152 |
plotReasonerString = QString("using %1:xtic(%2) ti col ").arg(reasonerStringIndexMap.value(reasonerString)+1).arg(reasonerStringIndexMap.value("Requests")+1); |
| 153 |
} else { |
| 154 |
plotReasonerString = QString(", '' u %1 ti col ").arg(reasonerStringIndexMap.value(reasonerString)+1); |
| 155 |
} |
| 156 |
if (validColorsForAllReasoners) { |
| 157 |
plotReasonerString += QString("lc rgb \"%1\"").arg(getColorString(reasonerString)); |
| 158 |
} |
| 159 |
plotScriptString += plotReasonerString; |
| 160 |
} |
| 161 |
|
| 162 |
if (reasonerStringIndexMap.contains("Index") && reasonerStringIndexMap.contains("Average")) { |
| 163 |
QString plotAverageString = QString(", '' using %1:%2 with lines title \"Average\" ").arg(reasonerStringIndexMap.value("Index")+1).arg(reasonerStringIndexMap.value("Average")+1); |
| 164 |
if (validColorsForAllReasoners) { |
| 165 |
plotAverageString += QString("lc rgb \"%1\" ").arg(getColorString("Average")); |
| 166 |
} |
| 167 |
plotAverageString += QString("lw 4\r\n"); |
| 168 |
plotScriptString += plotAverageString; |
| 169 |
} |
| 170 |
|
| 171 |
outputScriptFile.write(plotScriptString.toLocal8Bit()); |
| 172 |
|
| 173 |
outputScriptFile.close(); |
| 174 |
|
| 175 |
plotScriptFile(outputScriptFileString); |
| 176 |
} |
| 177 |
|
| 178 |
return this; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
CReasonerEvaluationGNUPlotPlotter* CReasonerEvaluationGNUPlotPlotter::createReasonerOverviewPlot(const QString& dataFileString, const QString& plotTitle, const QStringList& reasonerNameList, const QString& outputFile) { |
| 183 |
|
| 184 |
|
| 185 |
QString outputScriptFileString(outputFile+".gpl"); |
| 186 |
QString outputFileString(outputFile+".svg"); |
| 187 |
QFile dataFile(dataFileString); |
| 188 |
QMap<QString,cint64> reasonerStringIndexMap; |
| 189 |
if (dataFile.open(QIODevice::ReadOnly)) { |
| 190 |
QString titleLineString = dataFile.readLine(); |
| 191 |
cint64 nextIndex = 0; |
| 192 |
cint64 nextStartPos = 0; |
| 193 |
cint64 nextEndPos = 0; |
| 194 |
|
| 195 |
bool hasNextTitle = true; |
| 196 |
while (hasNextTitle) { |
| 197 |
nextEndPos = titleLineString.indexOf("\t",nextStartPos); |
| 198 |
if (nextEndPos <= -1) { |
| 199 |
nextEndPos = titleLineString.length(); |
| 200 |
hasNextTitle = false; |
| 201 |
} |
| 202 |
|
| 203 |
QString nextTitle = titleLineString.mid(nextStartPos,nextEndPos-nextStartPos); |
| 204 |
nextTitle.replace("\"",""); |
| 205 |
nextTitle = nextTitle.trimmed(); |
| 206 |
if (!nextTitle.isEmpty()) { |
| 207 |
reasonerStringIndexMap.insert(nextTitle,nextIndex++); |
| 208 |
} |
| 209 |
nextStartPos = nextEndPos+1; |
| 210 |
|
| 211 |
} |
| 212 |
dataFile.close(); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
QFile outputScriptFile(outputScriptFileString); |
| 217 |
if (outputScriptFile.open(QIODevice::WriteOnly)) { |
| 218 |
|
| 219 |
QString plotScriptString = mReasOverTemplateString; |
| 220 |
QString plotNameString = outputFile; |
| 221 |
cint64 lastSlashPos = plotNameString.lastIndexOf("/"); |
| 222 |
if (lastSlashPos >= 0) { |
| 223 |
plotNameString = plotNameString.mid(lastSlashPos+1); |
| 224 |
} |
| 225 |
plotNameString.replace(" ","_"); |
| 226 |
plotNameString.replace("-table",""); |
| 227 |
plotNameString.replace("-","_"); |
| 228 |
plotScriptString.replace("$$_PLOT_NAME_$$",plotNameString); |
| 229 |
plotScriptString.replace("$$_PLOT_FILE_$$",outputFileString); |
| 230 |
plotScriptString.replace("$$_PLOT_TITLE_$$",plotTitle); |
| 231 |
plotScriptString.replace("$$_PLOT_DATA_$$",dataFileString); |
| 232 |
|
| 233 |
|
| 234 |
bool validColorsForAllReasoners = true; |
| 235 |
QSet<QString> usedReasonerColorSet; |
| 236 |
foreach (QString reasonerString, reasonerNameList) { |
| 237 |
QString colorString = getColorString(reasonerString,&usedReasonerColorSet); |
| 238 |
if (colorString.isEmpty()) { |
| 239 |
validColorsForAllReasoners = false; |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
cint64 reasonerIndex = 0; |
| 244 |
foreach (QString reasonerString, reasonerNameList) { |
| 245 |
QString plotReasonerString; |
| 246 |
cint64 reasonerIndexValu = reasonerStringIndexMap.value(reasonerString); |
| 247 |
if (reasonerIndex++ == 0) { |
| 248 |
plotReasonerString = QString("using %1:%2 with lines ti col ").arg(reasonerStringIndexMap.value("Index")+1).arg(reasonerStringIndexMap.value(reasonerString)+1); |
| 249 |
} else { |
| 250 |
plotReasonerString = QString(", '' u %1 with lines ti col ").arg(reasonerStringIndexMap.value(reasonerString)+1); |
| 251 |
} |
| 252 |
if (validColorsForAllReasoners) { |
| 253 |
plotReasonerString += QString("lc rgb \"%1\"").arg(getColorString(reasonerString)); |
| 254 |
} |
| 255 |
plotReasonerString += " lw 3"; |
| 256 |
plotScriptString += plotReasonerString; |
| 257 |
} |
| 258 |
|
| 259 |
outputScriptFile.write(plotScriptString.toLocal8Bit()); |
| 260 |
|
| 261 |
outputScriptFile.close(); |
| 262 |
|
| 263 |
plotScriptFile(outputScriptFileString); |
| 264 |
} |
| 265 |
|
| 266 |
return this; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
CReasonerEvaluationGNUPlotPlotter* CReasonerEvaluationGNUPlotPlotter::plotScriptFile(const QString& scriptFileString) { |
| 272 |
QProcess gnuPlotProcess; |
| 273 |
gnuPlotProcess.start(QString("gnuplot < \"%1\"").arg(scriptFileString)); |
| 274 |
gnuPlotProcess.waitForFinished(300000); |
| 275 |
gnuPlotProcess.terminate(); |
| 276 |
gnuPlotProcess.kill(); |
| 277 |
return this; |
| 278 |
} |
| 279 |
|
| 280 |
QString CReasonerEvaluationGNUPlotPlotter::getColorString(const QString& reasonerString, QSet<QString>* usedReasonerColorSet) { |
| 281 |
QString reasonerColorString(reasonerString); |
| 282 |
QString colorString; |
| 283 |
if (mReasColorHash.contains(reasonerColorString)) { |
| 284 |
colorString = mReasColorHash.value(reasonerColorString); |
| 285 |
} else { |
| 286 |
cint64 versionSplitSpacePos = reasonerColorString.indexOf(" "); |
| 287 |
if (versionSplitSpacePos >= 0) { |
| 288 |
reasonerColorString = reasonerColorString.mid(0,versionSplitSpacePos); |
| 289 |
if (mReasColorHash.contains(reasonerColorString)) { |
| 290 |
colorString = mReasColorHash.value(reasonerColorString); |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
if (usedReasonerColorSet && !colorString.isEmpty()) { |
| 295 |
if (usedReasonerColorSet->contains(reasonerColorString)) { |
| 296 |
colorString.clear(); |
| 297 |
} else { |
| 298 |
usedReasonerColorSet->insert(reasonerColorString); |
| 299 |
} |
| 300 |
} |
| 301 |
return colorString; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
}; // end namespace Evaluation |
| 307 |
|
| 308 |
}; // end namespace Test |
| 309 |
|
| 310 |
}; // end namespace Konclude |