Debian Codegraph @

Source/Test/Evaluation/CReasonerEvaluationGroupRequestStatisticsCSVComparisonAnalyser.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 "CReasonerEvaluationGroupRequestStatisticsCSVComparisonAnalyser.h"
22
23
24 namespace Konclude {
25
26 namespace Test {
27
28 namespace Evaluation {
29
30
31
32 CReasonerEvaluationGroupRequestStatisticsCSVComparisonAnalyser::CReasonerEvaluationGroupRequestStatisticsCSVComparisonAnalyser(CReasonerEvaluationFiltering* filtering) {
33 mFiltering = filtering;
34 }
35
36
37 CReasonerEvaluationGroupRequestStatisticsCSVComparisonAnalyser::~CReasonerEvaluationGroupRequestStatisticsCSVComparisonAnalyser() {
38 }
39
40
41 bool CReasonerEvaluationGroupRequestStatisticsCSVComparisonAnalyser::analyseGroupedEvaluationData(const QStringList& groubList, const QStringList& requestList, const QStringList& reasonerList, const QString& outputDirectory, CReasonerEvaluationAnalyseContext* context, CReasonerEvaluationGroupRequestSelector* selector) {
42
43 mOutputFileName = QString("%1").arg(selector->getOutputString());
44
45 QDir outDir(outputDirectory);
46 outDir.mkpath(mOutputFileName);
47 QString outputFileString(outputDirectory+mOutputFileName+"request-statistics");
48
49
50 QStringList titleList;
51 titleList.append("Statistic");
52 titleList.append("Minimum");
53 titleList.append("Maximum");
54 titleList.append("Mean");
55 titleList.append("StandardDerivation");
56 titleList.append("Median");
57 titleList.append("Sum");
58
59
60 CReasonerEvaluationTableMultiFormatOutputWriter<double> tableMultiFormatOutputWriter;
61 tableMultiFormatOutputWriter.addColumnTitles(titleList);
62
63
64 QHash<QString,CRequestStatisticsData> statisticNameDataHash;
65
66
67 bool hasSelectedRequestFile = false;
68
69 foreach (QString groupString, groubList) {
70
71 if (selector->isGroupSelected(groupString)) {
72
73 QSet<QString>* groupRequestList = getGroupRequests(groupString);
74 foreach (QString requestString, *groupRequestList) {
75
76 if (selector->isRequestSelected(groupString,requestString)) {
77
78
79
80 bool allReasonerResultAvailable = true;
81 QString pathRequestString;
82
83 foreach (QString reasonerString, reasonerList) {
84 CReasonerEvaluationDataValue* evalData = getGroupRequestReasonerEvaluationData(groupString,requestString,reasonerString);
85 if (!evalData || evalData->hasDataNotAvailableFlag()) {
86 allReasonerResultAvailable = false;
87 } else {
88 CReasonerEvaluationStringListValue* stringListDataValue = dynamic_cast<CReasonerEvaluationStringListValue*>(evalData);
89 if (stringListDataValue) {
90 QStringList stringList = stringListDataValue->getValue();
91 if (!stringList.isEmpty()) {
92 pathRequestString = stringList.first();
93 } else {
94 allReasonerResultAvailable = false;
95 }
96 } else {
97 allReasonerResultAvailable = false;
98 }
99 }
100 }
101 if (allReasonerResultAvailable && !pathRequestString.isEmpty()) {
102 hasSelectedRequestFile = true;
103
104 QStringList statisticList = mFiltering->loadStatistics(pathRequestString);
105 if (statisticList.isEmpty()) {
106 statisticList.append(QString("%1\t%2").arg("StatisticsMissing:").arg("1"));
107 statisticList.append(QString("%1\t%2").arg("StatisticsAvailable:").arg("0"));
108 } else {
109 statisticList.append(QString("%1\t%2").arg("StatisticsMissing:").arg("0"));
110 statisticList.append(QString("%1\t%2").arg("StatisticsAvailable:").arg("1"));
111 }
112 statisticList.append(QString("%1\t%2").arg("RequestFiles:").arg("1"));
113
114 foreach (const QString& statisticString, statisticList) {
115 QStringList statisticValueList = statisticString.split("\t");
116 if (statisticValueList.count() == 2) {
117 QString statisticNameString = statisticValueList.first().trimmed();
118 QString statisticValueString = statisticValueList.last().trimmed();
119 bool statisticValueConvertionSuccessfull = false;
120 double statisticValue = statisticValueString.toDouble(&statisticValueConvertionSuccessfull);
121 if (statisticValueConvertionSuccessfull) {
122 CRequestStatisticsData& reqStatData = statisticNameDataHash[statisticNameString];
123 if (!reqStatData.mInitialized) {
124 reqStatData.setDataName(statisticNameString);
125 reqStatData.mInitialized = true;
126 }
127 reqStatData.addData(statisticValue,pathRequestString);
128 }
129 }
130 }
131 }
132
133
134
135 }
136 }
137 }
138 }
139
140 if (hasSelectedRequestFile) {
141
142
143 for (QHash<QString,CRequestStatisticsData>::iterator it = statisticNameDataHash.begin(), itEnd = statisticNameDataHash.end(); it != itEnd; ++it) {
144 const QString& statisticName(it.key());
145 CRequestStatisticsData& statisticData(it.value());
146 tableMultiFormatOutputWriter.addNewTableRow(statisticName);
147 statisticData.calculateStatistics();
148 QList<double> statisticValueList;
149 statisticValueList.append(statisticData.mMinValue);
150 statisticValueList.append(statisticData.mMaxValue);
151 statisticValueList.append(statisticData.mMeanValue);
152 statisticValueList.append(statisticData.mStandardDerivationValue);
153 statisticValueList.append(statisticData.mMedianValue);
154 statisticValueList.append(statisticData.mSumValue);
155 tableMultiFormatOutputWriter.addValuesToLastTableRow(statisticValueList);
156 }
157
158
159
160
161 QStringList reasonerCompHighchartPlotFileList;
162
163 tableMultiFormatOutputWriter.buildSortedIndex();
164 reasonerCompHighchartPlotFileList += tableMultiFormatOutputWriter.writeCVSTable(outputFileString);
165
166 if (context->isHighchartPlottingActivated()) {
167 foreach (QString plotFileString, reasonerCompHighchartPlotFileList) {
168 if (true /*plotFileString.contains("-by-Average-")*/) {
169 QString outputFile = plotFileString;
170 outputFile.remove(".csv");
171 QString title = getPrettyTitleFromOutputFile(outputFile);
172 context->getHighchartPlotter()->createRequestStatisticsPlot(plotFileString,context->getAdditionalTitleString()+title,titleList,outputFile,selector->getNameString());
173 }
174 }
175 }
176
177
178 }
179
180 return true;
181 }
182
183
184 QString CReasonerEvaluationGroupRequestStatisticsCSVComparisonAnalyser::getPrettyTitleFromOutputFile(const QString& outputFile) {
185 QString title = outputFile;
186 title.remove("table");
187 cint64 slashPos = title.lastIndexOf("/");
188 if (slashPos >= 0) {
189 title = title.mid(slashPos+1);
190 }
191 title.replace("-"," ");
192 return title;
193 }
194
195
196 }; // end namespace Evaluation
197
198 }; // end namespace Test
199
200 }; // end namespace Konclude