File: CReasonerEvaluationGNUPlotPlotter.cpp

package info (click to toggle)
konclude 0.7.0%2B1137~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 48,824 kB
  • sloc: cpp: 378,238; xml: 116,067; makefile: 38; sh: 8; ansic: 3
file content (310 lines) | stat: -rw-r--r-- 11,327 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
 *		Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
 *
 *		This file is part of the reasoning system Konclude.
 *		For details and support, see <http://konclude.com/>.
 *
 *		Konclude is free software: you can redistribute it and/or modify
 *		it under the terms of version 3 of the GNU Lesser General Public
 *		License (LGPLv3) as published by the Free Software Foundation.
 *
 *		Konclude is distributed in the hope that it will be useful,
 *		but WITHOUT ANY WARRANTY; without even the implied warranty of
 *		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *		GNU (Lesser) General Public License for more details.
 *
 *		You should have received a copy of the GNU (Lesser) General Public
 *		License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "CReasonerEvaluationGNUPlotPlotter.h"
#include "CReasonerEvaluationAnalyseContext.h"


namespace Konclude {

	namespace Test {

		namespace Evaluation {



			CReasonerEvaluationGNUPlotPlotter::CReasonerEvaluationGNUPlotPlotter(CReasonerEvaluationAnalyseContext* context) {
				mContext = context;


				//mReasCompTemplateString = 
				//	"set terminal svg size 1280,800 dynamic enhanced fname 'arial'  fsize 10 mousing name \"$$_PLOT_NAME_$$\" butt solid\r\n"
				//	"set output '$$_PLOT_FILE_$$'\r\n"
				//	"set style fill solid 1.00 border lt -1\r\n"
				//	"set style histogram clustered gap 5 title  offset character 0, 0, 0\r\n"
				//	"set style data histograms\r\n"
				//	"set xtics border in scale 0,00 nomirror rotate by -45  offset character 0, 0, 0 autojustify\r\n"
				//	"set xtics norangelimit font \",8\"\r\n"
				//	"set title \"$$_PLOT_TITLE_$$\"\r\n"
				//	"set bmargin 12\r\n"
				//	"set grid ytics lt 0 lw 0.2 lc rgb \"#000000\"\r\n"
				//	"plot '$$_PLOT_DATA_$$' ";


				mReasCompTemplateString = 
					"set terminal svg size 1280,800\r\n"
					"set output '$$_PLOT_FILE_$$'\r\n"
					"set style fill solid 1.00 border lt -1\r\n"
					"set style histogram clustered gap 5 title  offset character 0, 0, 0\r\n"
					"set style data histograms\r\n"
					"set xtics border in scale 0,00 nomirror rotate by -45  offset character 0, 0, 0 autojustify\r\n"
					"set xtics norangelimit font \",8\"\r\n"
					"set title \"$$_PLOT_TITLE_$$\"\r\n"
					"set bmargin 10\r\n"
					"set grid ytics lt 0 lw 0.2 lc rgb \"#000000\"\r\n"
					"plot '$$_PLOT_DATA_$$' ";

				mReasOverTemplateString = 
					"set terminal svg size 1280,800\r\n"
					"set output '$$_PLOT_FILE_$$'\r\n"
					"set title \"$$_PLOT_TITLE_$$\"\r\n"
					"set log y\r\n"
					"set grid ytics lt 0 lw 0.2 lc rgb \"#000000\"\r\n"
					"plot '$$_PLOT_DATA_$$' ";


				mReasColorHash.insert("FaCT++","#E4FECA");
				mReasColorHash.insert("HermiT","#BBD2FF");
				mReasColorHash.insert("Pellet","#404040");
				mReasColorHash.insert("Konclude","#3784A0");
				mReasColorHash.insert("Average","#F7C298");
				mReasColorHash.insert("Min","#D5803D");
				mReasColorHash.insert("Max","#603326");
			}


			CReasonerEvaluationGNUPlotPlotter::~CReasonerEvaluationGNUPlotPlotter() {
			}

			CReasonerEvaluationGNUPlotPlotter* CReasonerEvaluationGNUPlotPlotter::createReasonerComparisonPlot(const QString& dataFileString, const QString& plotTitle, const QStringList& reasonerNameList, const QString& outputFile) {
				QString outputScriptFileString(outputFile+".gpl");
				QString outputFileString(outputFile+".svg");
				QFile dataFile(dataFileString);
				QMap<QString,cint64> reasonerStringIndexMap;
				if (dataFile.open(QIODevice::ReadOnly)) {
					QString titleLineString = dataFile.readLine();
					cint64 nextIndex = 0;
					cint64 nextStartPos = 0;
					cint64 nextEndPos = 0;

					bool hasNextTitle = true;
					while (hasNextTitle) {
						nextEndPos = titleLineString.indexOf("\t",nextStartPos);
						if (nextEndPos <= -1) {
							nextEndPos = titleLineString.length();
							hasNextTitle = false;
						}

						QString nextTitle = titleLineString.mid(nextStartPos,nextEndPos-nextStartPos);
						nextTitle.replace("\"","");
						if (!nextTitle.isEmpty()) {
							reasonerStringIndexMap.insert(nextTitle,nextIndex++);
						}
						nextStartPos = nextEndPos+1;

					}
					dataFile.close();
				}


				QFile outputScriptFile(outputScriptFileString);
				if (outputScriptFile.open(QIODevice::WriteOnly)) {

					QString plotScriptString = mReasCompTemplateString;
					QString plotNameString = outputFile;
					cint64 lastSlashPos = plotNameString.lastIndexOf("/");
					if (lastSlashPos >= 0) {
						plotNameString = plotNameString.mid(lastSlashPos+1);
					}
					plotNameString.replace(" ","_");
					plotNameString.replace("-table","");
					plotNameString.replace("-","_");
					plotScriptString.replace("$$_PLOT_NAME_$$",plotNameString);
					plotScriptString.replace("$$_PLOT_FILE_$$",outputFileString);
					plotScriptString.replace("$$_PLOT_TITLE_$$",plotTitle);
					plotScriptString.replace("$$_PLOT_DATA_$$",dataFileString);


					bool validColorsForAllReasoners = true;
					QSet<QString> usedReasonerColorSet;
					foreach (QString reasonerString, reasonerNameList) {
						QString colorString = getColorString(reasonerString,&usedReasonerColorSet);
						if (colorString.isEmpty()) {
							validColorsForAllReasoners = false;
						}
					}
					QString colorString = getColorString("Average",&usedReasonerColorSet);
					if (colorString.isEmpty()) {
						validColorsForAllReasoners = false;
					}

					cint64 reasonerIndex = 0;
					foreach (QString reasonerString, reasonerNameList) {
						QString plotReasonerString;
						if (reasonerIndex++ == 0) {
							plotReasonerString = QString("using %1:xtic(%2) ti col ").arg(reasonerStringIndexMap.value(reasonerString)+1).arg(reasonerStringIndexMap.value("Requests")+1);
						} else {
							plotReasonerString = QString(", '' u %1 ti col ").arg(reasonerStringIndexMap.value(reasonerString)+1);
						}
						if (validColorsForAllReasoners) {
							plotReasonerString += QString("lc rgb \"%1\"").arg(getColorString(reasonerString));
						}
						plotScriptString += plotReasonerString;
					}

					if (reasonerStringIndexMap.contains("Index") && reasonerStringIndexMap.contains("Average")) {
						QString plotAverageString = QString(", '' using %1:%2 with lines title \"Average\" ").arg(reasonerStringIndexMap.value("Index")+1).arg(reasonerStringIndexMap.value("Average")+1);
						if (validColorsForAllReasoners) {
							plotAverageString += QString("lc rgb \"%1\" ").arg(getColorString("Average"));
						}
						plotAverageString += QString("lw 4\r\n");
						plotScriptString += plotAverageString;
					}

					outputScriptFile.write(plotScriptString.toLocal8Bit());

					outputScriptFile.close();

					plotScriptFile(outputScriptFileString);
				}

				return this;
			}


			CReasonerEvaluationGNUPlotPlotter* CReasonerEvaluationGNUPlotPlotter::createReasonerOverviewPlot(const QString& dataFileString, const QString& plotTitle, const QStringList& reasonerNameList, const QString& outputFile) {


				QString outputScriptFileString(outputFile+".gpl");
				QString outputFileString(outputFile+".svg");
				QFile dataFile(dataFileString);
				QMap<QString,cint64> reasonerStringIndexMap;
				if (dataFile.open(QIODevice::ReadOnly)) {
					QString titleLineString = dataFile.readLine();
					cint64 nextIndex = 0;
					cint64 nextStartPos = 0;
					cint64 nextEndPos = 0;

					bool hasNextTitle = true;
					while (hasNextTitle) {
						nextEndPos = titleLineString.indexOf("\t",nextStartPos);
						if (nextEndPos <= -1) {
							nextEndPos = titleLineString.length();
							hasNextTitle = false;
						}

						QString nextTitle = titleLineString.mid(nextStartPos,nextEndPos-nextStartPos);
						nextTitle.replace("\"","");
						nextTitle = nextTitle.trimmed();
						if (!nextTitle.isEmpty()) {
							reasonerStringIndexMap.insert(nextTitle,nextIndex++);
						}
						nextStartPos = nextEndPos+1;

					}
					dataFile.close();
				}


				QFile outputScriptFile(outputScriptFileString);
				if (outputScriptFile.open(QIODevice::WriteOnly)) {

					QString plotScriptString = mReasOverTemplateString;
					QString plotNameString = outputFile;
					cint64 lastSlashPos = plotNameString.lastIndexOf("/");
					if (lastSlashPos >= 0) {
						plotNameString = plotNameString.mid(lastSlashPos+1);
					}
					plotNameString.replace(" ","_");
					plotNameString.replace("-table","");
					plotNameString.replace("-","_");
					plotScriptString.replace("$$_PLOT_NAME_$$",plotNameString);
					plotScriptString.replace("$$_PLOT_FILE_$$",outputFileString);
					plotScriptString.replace("$$_PLOT_TITLE_$$",plotTitle);
					plotScriptString.replace("$$_PLOT_DATA_$$",dataFileString);


					bool validColorsForAllReasoners = true;
					QSet<QString> usedReasonerColorSet;
					foreach (QString reasonerString, reasonerNameList) {
						QString colorString = getColorString(reasonerString,&usedReasonerColorSet);
						if (colorString.isEmpty()) {
							validColorsForAllReasoners = false;
						}
					}

					cint64 reasonerIndex = 0;
					foreach (QString reasonerString, reasonerNameList) {
						QString plotReasonerString;
						cint64 reasonerIndexValu = reasonerStringIndexMap.value(reasonerString);
						if (reasonerIndex++ == 0) {
							plotReasonerString = QString("using %1:%2 with lines ti col ").arg(reasonerStringIndexMap.value("Index")+1).arg(reasonerStringIndexMap.value(reasonerString)+1);
						} else {
							plotReasonerString = QString(", '' u %1 with lines ti col ").arg(reasonerStringIndexMap.value(reasonerString)+1);
						}
						if (validColorsForAllReasoners) {
							plotReasonerString += QString("lc rgb \"%1\"").arg(getColorString(reasonerString));
						}
						plotReasonerString += " lw 3";
						plotScriptString += plotReasonerString;
					}

					outputScriptFile.write(plotScriptString.toLocal8Bit());

					outputScriptFile.close();

					plotScriptFile(outputScriptFileString);
				}

				return this;
			}



			CReasonerEvaluationGNUPlotPlotter* CReasonerEvaluationGNUPlotPlotter::plotScriptFile(const QString& scriptFileString) {
				QProcess gnuPlotProcess;
				gnuPlotProcess.start(QString("gnuplot < \"%1\"").arg(scriptFileString));
				gnuPlotProcess.waitForFinished(300000);
				gnuPlotProcess.terminate();
				gnuPlotProcess.kill();				
				return this;
			}

			QString CReasonerEvaluationGNUPlotPlotter::getColorString(const QString& reasonerString, QSet<QString>* usedReasonerColorSet) {
				QString reasonerColorString(reasonerString);
				QString colorString;
				if (mReasColorHash.contains(reasonerColorString)) {
					colorString = mReasColorHash.value(reasonerColorString);
				} else {
					cint64 versionSplitSpacePos = reasonerColorString.indexOf(" ");
					if (versionSplitSpacePos >= 0) {
						reasonerColorString = reasonerColorString.mid(0,versionSplitSpacePos);
						if (mReasColorHash.contains(reasonerColorString)) {
							colorString = mReasColorHash.value(reasonerColorString);
						}
					}
				}
				if (usedReasonerColorSet && !colorString.isEmpty()) {
					if (usedReasonerColorSet->contains(reasonerColorString)) {
						colorString.clear();
					} else {
						usedReasonerColorSet->insert(reasonerColorString);
					}
				}
				return colorString;
			}



		}; // end namespace Evaluation

	}; // end namespace Test

}; // end namespace Konclude