Debian Codegraph @

Source/Test/Evaluation/CReasonerEvaluationStatisticsValueExtractor.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 "CReasonerEvaluationStatisticsValueExtractor.h"
22
23
24 namespace Konclude {
25
26 namespace Test {
27
28 namespace Evaluation {
29
30
31
32 CReasonerEvaluationStatisticsValueExtractor::CReasonerEvaluationStatisticsValueExtractor(const QString& statName, QSet<QString>* statNameSet, double timelimit, double errorPunishmentTime, CReasonerEvaluationDataValueCacher* cacher) {
33 mTimelimit = timelimit;
34 mErrorPunishmentTime = errorPunishmentTime;
35 mCacher = cacher;
36
37 mStatName = statName;
38 mStatNameSet = statNameSet;
39 }
40
41
42
43
44 CReasonerEvaluationDoubleDataValue* CReasonerEvaluationStatisticsValueExtractor::extractSpecifiedStatisticsValueEvaluationData(QDomDocument& document, const QString& responseFileString, const QString& statName) {
45 CReasonerEvaluationDoubleDataValue* doubleEvalValue = nullptr;
46
47 if (mCacher) {
48 doubleEvalValue = dynamic_cast<CReasonerEvaluationDoubleDataValue*>(mCacher->getCachedDataValue(responseFileString,statName));
49 }
50
51 if (!doubleEvalValue) {
52 double doubleValue = 0;
53 bool errorOccured = false;
54 bool timeoutOccured = false;
55 bool allRespTimeValid = true;
56 bool dataAvailable = false;
57
58
59 QDomElement rootEl = document.documentElement();
60
61 cint64 queryNumber = 0;
62
63 QList<QDomElement> elementList;
64 elementList.append(rootEl);
65
66 while (!elementList.isEmpty()) {
67
68 QDomElement element = elementList.takeFirst();
69
70
71 if (element.hasAttribute("request-command")) {
72 QString statName = element.attribute("request-command");
73 ++queryNumber;
74 QString foundStatName;
75 if (statName == "Classify") {
76 foundStatName = QString("query-%1-classify-response-time").arg(queryNumber);
77 } else if (statName == "Realize") {
78 foundStatName = QString("query-%1-realize-response-time").arg(queryNumber);
79 } else if (statName == "IsKBSatisfiable") {
80 foundStatName = QString("query-%1-consistency-response-time").arg(queryNumber);
81 }
82 if (foundStatName == statName) {
83 dataAvailable = true;
84
85 QString statValueString = element.attribute("response-time","0");
86 bool validStatValue = false;
87 double statValue = statValueString.toDouble(&validStatValue);
88 if (validStatValue) {
89 doubleValue += statValue;
90 }
91 allRespTimeValid &= validStatValue;
92 }
93 }
94
95
96 if (element.hasAttribute("statistic-name")) {
97 QString foundStatName = element.attribute("statistic-name");
98 if (foundStatName == statName) {
99 dataAvailable = true;
100
101 QString statValueString = element.attribute("statistic-value","0");
102 bool validStatValue = false;
103 double statValue = statValueString.toDouble(&validStatValue);
104 if (validStatValue) {
105 doubleValue += statValue;
106 }
107 allRespTimeValid &= validStatValue;
108 }
109 }
110
111 if (element.tagName() == "Error") {
112 errorOccured = false;
113 }
114 QString timeoutString = element.attribute("timeout");
115 if (timeoutString == "1") {
116 timeoutOccured = true;
117 }
118
119 QDomElement childElement = element.firstChildElement();
120 while (!childElement.isNull()) {
121 elementList.append(childElement);
122 childElement = childElement.nextSiblingElement();
123 }
124 }
125 doubleEvalValue = new CReasonerEvaluationDoubleDataValue(doubleValue);
126 if (!dataAvailable) {
127 doubleEvalValue->setDataNotAvailableFlag();
128 }
129
130 if (mCacher) {
131 mCacher->addDataValueToCache(responseFileString,statName,doubleEvalValue);
132 }
133
134 }
135 return doubleEvalValue;
136 }
137
138
139
140
141 CReasonerEvaluationDataValue* CReasonerEvaluationStatisticsValueExtractor::extractEvaluationData(const QString& responseFileString) {
142 CReasonerEvaluationDataValue* evalValue = nullptr;
143
144 if (mCacher) {
145 evalValue = mCacher->getCachedDataValue(responseFileString,mStatName);
146 }
147
148 if (!evalValue) {
149
150 QFile responseFile(responseFileString);
151 if (responseFile.open(QIODevice::ReadOnly)) {
152 QDomDocument document;
153 document.setContent(&responseFile,false);
154 QDomElement rootEl = document.documentElement();
155 responseFile.close();
156
157 evalValue = extractSpecifiedStatisticsValueEvaluationData(document,responseFileString,mStatName);
158
159 for (QSet<QString>::const_iterator it = mStatNameSet->constBegin(), itEnd = mStatNameSet->constEnd(); it != itEnd; ++it) {
160 QString statName(*it);
161 if (statName != mStatName) {
162 extractSpecifiedStatisticsValueEvaluationData(document,responseFileString,statName);
163 }
164 }
165 }
166
167 }
168 if (evalValue) {
169 evalValue = evalValue->getCopy();
170 }
171 return evalValue;
172 }
173
174
175 }; // end namespace Evaluation
176
177 }; // end namespace Test
178
179 }; // end namespace Konclude