Debian Codegraph @

Source/Test/Evaluation/CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser.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 "CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser.h"
22
23
24 namespace Konclude {
25
26 namespace Test {
27
28 namespace Evaluation {
29
30
31
32 CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser::CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser() {
33 }
34
35
36 CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser::~CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser() {
37 }
38
39
40
41 CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser* CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser::addNextStatisticName(const QString& statName) {
42 mStatNameList.append(statName);
43 return this;
44 }
45
46
47 bool CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser::analyseGroupedEvaluationData(const QStringList& groubList, const QStringList& requestList, const QStringList& reasonerList, const QString& outputDirectory, CReasonerEvaluationAnalyseContext* context, CReasonerEvaluationGroupRequestSelector* selector) {
48
49 mOutputFileName = QString("%1").arg(selector->getOutputString());
50
51 QDir outDir(outputDirectory);
52 outDir.mkpath(mOutputFileName);
53
54
55 QHash< QPair<QString,QString>,double >* reasonerRequestValueHash = mSelectorReasonerRequestValueHash[selector];
56 if (!reasonerRequestValueHash) {
57 reasonerRequestValueHash = new QHash< QPair<QString,QString>,double >();
58 mSelectorReasonerRequestValueHash[selector] = reasonerRequestValueHash;
59 }
60
61 bool hasDataSelected = false;
62
63 foreach (QString groupString, groubList) {
64
65 if (selector->isGroupSelected(groupString)) {
66
67 QSet<QString>* groupRequestList = getGroupRequests(groupString);
68 foreach (QString requestString, *groupRequestList) {
69
70 if (selector->isRequestSelected(groupString,requestString)) {
71
72 bool allDataAvailable = true;
73 foreach (QString reasonerString, reasonerList) {
74
75 bool dataAvailable = false;
76 CReasonerEvaluationDataValue* evalData = getGroupRequestReasonerEvaluationData(groupString,requestString,reasonerString);
77 if (!evalData || evalData->hasDataNotAvailableFlag()) {
78 allDataAvailable = false;
79 } else if (evalData) {
80 CReasonerEvaluationDoubleDataValue* doubleDataValue = dynamic_cast<CReasonerEvaluationDoubleDataValue*>(evalData);
81 if (doubleDataValue) {
82 hasDataSelected = true;
83 dataAvailable = true;
84 reasonerRequestValueHash->insertMulti(QPair<QString,QString>(reasonerString,groupString+requestString),doubleDataValue->getValue());
85 }
86 }
87
88 if (!dataAvailable) {
89 reasonerRequestValueHash->insertMulti(QPair<QString,QString>(reasonerString,groupString+requestString),0.);
90 }
91 }
92
93 }
94 }
95 }
96 }
97
98
99
100
101
102 if (hasDataSelected) {
103 foreach (QString reasonerString, reasonerList) {
104
105
106 QString outputFileString(outputDirectory+mOutputFileName+reasonerString+"-statistic-values");
107
108 CReasonerEvaluationTableMultiFormatOutputWriter<double> tableMultiFormatOutputWriter;
109 QStringList titleList;
110 titleList.append("Request");
111 titleList.append(mStatNameList);
112 tableMultiFormatOutputWriter.addColumnTitles(titleList);
113 bool tableFilled = false;
114
115
116
117 QString outputFileGroupString(outputDirectory+mOutputFileName+reasonerString+"-included-grouping-statistic-values");
118
119 CReasonerEvaluationTableMultiFormatOutputWriter<double> groupTableMultiFormatOutputWriter;
120 QStringList groupTitleList;
121 groupTitleList.append("Request\tGroup");
122 groupTitleList.append(mStatNameList);
123 groupTableMultiFormatOutputWriter.addColumnTitles(groupTitleList);
124
125
126 foreach (const QString& groupString, groubList) {
127
128 if (selector->isGroupSelected(groupString)) {
129
130 QSet<QString>* groupRequestList = getGroupRequests(groupString);
131 foreach (QString requestString, *groupRequestList) {
132
133 if (selector->isRequestSelected(groupString,requestString)) {
134
135 QList<double> valueList(reasonerRequestValueHash->values(QPair<QString,QString>(reasonerString,groupString+requestString)));
136 if (valueList.count() >= mStatNameList.count()) {
137 groupTableMultiFormatOutputWriter.addNewTableRow(requestString+"\t"+groupString);
138 tableMultiFormatOutputWriter.addNewTableRow(requestString);
139 QList<double> reverseDoubleValueList;
140 foreach (double doubleDataValue, valueList) {
141 reverseDoubleValueList.prepend(doubleDataValue);
142 tableFilled = true;
143 }
144
145 foreach (double doubleValue, reverseDoubleValueList) {
146 tableMultiFormatOutputWriter.addValuesToLastTableRow(QList<double>()<<doubleValue);
147 groupTableMultiFormatOutputWriter.addValuesToLastTableRow(QList<double>()<<doubleValue);
148 }
149
150 }
151 }
152
153 }
154 }
155 }
156
157
158
159
160
161 if (tableFilled) {
162 QStringList reasonerCompGNUPlotFileList;
163 QStringList reasonerCompHighchartPlotFileList;
164
165 tableMultiFormatOutputWriter.buildSortedIndex();
166 reasonerCompHighchartPlotFileList += tableMultiFormatOutputWriter.writeCVSTable(outputFileString);
167 reasonerCompHighchartPlotFileList += groupTableMultiFormatOutputWriter.writeCVSTable(outputFileGroupString);
168
169 if (context->isGNUPlottingActivated()) {
170 reasonerCompGNUPlotFileList += tableMultiFormatOutputWriter.writeGNUPlotDataTable(outputFileString);
171 foreach (QString plotFileString, reasonerCompGNUPlotFileList) {
172 if (true /*plotFileString.contains("-by-Average-")*/) {
173 QString outputFile = plotFileString;
174 outputFile.remove(".dat");
175 QString title = getPrettyTitleFromOutputFile(outputFile);
176 context->getGNUPlotPlotter()->createReasonerComparisonPlot(plotFileString,title,mStatNameList,outputFile);
177 }
178 }
179 }
180 if (context->isHighchartPlottingActivated()) {
181 foreach (QString plotFileString, reasonerCompHighchartPlotFileList) {
182 if (true /*plotFileString.contains("-by-Average-")*/) {
183 QString outputFile = plotFileString;
184 outputFile.remove(".csv");
185 QString title = getPrettyTitleFromOutputFile(outputFile);
186 context->getHighchartPlotter()->createReasonerComparisonPlot(plotFileString,title,mStatNameList,outputFile,selector->getNameString()+" :: "+context->getAdditionalTitleString());
187 }
188 }
189 }
190 }
191 }
192 }
193
194
195 return true;
196 }
197
198
199 QString CReasonerEvaluationGroupRequestReasonerStatisticValueCollectingCSVComparisonAnalyser::getPrettyTitleFromOutputFile(const QString& outputFile) {
200 QString title = outputFile;
201 title.remove("table");
202 cint64 slashPos = title.lastIndexOf("/");
203 if (slashPos >= 0) {
204 title = title.mid(slashPos+1);
205 }
206 title.replace("-"," ");
207 title.replace("mmm","Comparision,");
208 title.replace("sorted","Sorted");
209 title.replace("separate","Separate");
210
211 return title;
212 }
213
214
215 }; // end namespace Evaluation
216
217 }; // end namespace Test
218
219 }; // end namespace Konclude