Debian Codegraph @

Source/Test/Analyse/CMinMaxAvgLimitedCountValueAnalyser.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 "CMinMaxAvgLimitedCountValueAnalyser.h"
22
23
24 namespace Konclude {
25
26 namespace Test {
27
28 namespace Analyse {
29
30
31 CMinMaxAvgLimitedCountValueAnalyser::CMinMaxAvgLimitedCountValueAnalyser(qint64 valueLimit) {
32 valLimit = valueLimit;
33 }
34
35
36
37 CMinMaxAvgLimitedCountValueAnalyser::~CMinMaxAvgLimitedCountValueAnalyser() {
38 }
39
40
41
42 CMinMaxAvgLimitedCountValueAnalyser *CMinMaxAvgLimitedCountValueAnalyser::setValueLimit(qint64 valueLimit) {
43 valLimit = valueLimit;
44 return this;
45 }
46
47 qint64 CMinMaxAvgLimitedCountValueAnalyser::getValueLimit() {
48 return valLimit;
49 }
50
51
52
53
54 CValueAnalyser *CMinMaxAvgLimitedCountValueAnalyser::analyseValue(double douVal) {
55 if (valCount > 0) {
56 valCount++;
57 maxVal = qMax(douVal,maxVal);
58 minVal = qMin(douVal,minVal);
59 avgVal = avgVal + (1./(valCount+1.)) * (douVal - avgVal);
60 } else {
61 avgVal = douVal;
62 minVal = douVal;
63 maxVal = douVal;
64 valCount++;
65 }
66 values.prepend(douVal);
67
68 if (valCount > valLimit) {
69 double lastVal = values.takeLast();
70 avgVal = avgVal - (1./(valCount-1.)) * (lastVal - avgVal);
71 valCount--;
72 if (lastVal == minVal || lastVal == maxVal) {
73 // search new min and max
74 double newMin = 1.7976931348623158e+308;
75 double newMax = -1.7976931348623158e+307;
76 for (QLinkedList<double>::const_iterator it = values.begin(); it != values.end(); ++it) {
77 double val = (*it);
78 newMax = qMax(val,newMax);
79 newMin = qMin(val,newMin);
80 }
81 minVal = newMin;
82 maxVal = newMax;
83 }
84 }
85
86 if (!valCountAnaVal) {
87 valCountAnaVal = new CIntegerAnalyseValue(valCount);
88 maxValAnaVal = new CDoubleAnalyseValue(maxVal);
89 minValAnaVal = new CDoubleAnalyseValue(minVal);
90 avgValAnaVal = new CDoubleAnalyseValue(avgVal);
91 } else {
92 valCountAnaVal->parseFromInteger(valCount);
93 maxValAnaVal->parseFromDouble(maxVal);
94 minValAnaVal->parseFromDouble(minVal);
95 avgValAnaVal->parseFromDouble(avgVal);
96 }
97 return this;
98 }
99
100
101
102
103 }; // end namespace Analyse
104
105 }; // end namespace Test
106
107 }; // end namespace Konclude