diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index 7c119fde42539236f0537d829e5a868d51618445..9532b1ce970f1dd06f00fb034207bdb26ea2d7e0 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -198,6 +198,14 @@ double LinechartPlot::getMedian(QString id) return data.value(id)->getMedian(); } +/** + * @param id curve identifier + */ +double LinechartPlot::getVariance(QString id) +{ + return data.value(id)->getVariance(); +} + int LinechartPlot::getAverageWindow() { return averageWindowSize; @@ -743,8 +751,9 @@ TimeSeriesData::TimeSeriesData(QwtPlot* plot, QString friendlyName, quint64 plot maxValue(DBL_MIN), zeroValue(0), count(0), - mean(0.00), - median(0.00), + mean(0.0), + median(0.0), + variance(0.0), averageWindow(50) { this->plot = plot; @@ -802,6 +811,14 @@ void TimeSeriesData::append(quint64 ms, double value) medianList.append(this->value[count-i]); } mean = mean / static_cast(qMin(averageWindow,static_cast(count))); + + this->variance = 0; + for (unsigned int i = 0; (i < averageWindow) && (((int)count - (int)i) >= 0); ++i) + { + this->variance += (this->value[count-i] - mean) * (this->value[count-i] - mean); + } + this->variance = this->variance / static_cast(qMin(averageWindow,static_cast(count))); + qSort(medianList); if (medianList.count() > 2) @@ -901,6 +918,14 @@ double TimeSeriesData::getMedian() return median; } +/** + * @return the variance + */ +double TimeSeriesData::getVariance() +{ + return variance; +} + double TimeSeriesData::getCurrentValue() { return lastValue; diff --git a/src/ui/linechart/LinechartPlot.h b/src/ui/linechart/LinechartPlot.h index 60f12542d8dbd3e1e36ad9049e4e58460419385f..7f2c8970faf756010dbbe2a3e6a634b7cb61e5f0 100644 --- a/src/ui/linechart/LinechartPlot.h +++ b/src/ui/linechart/LinechartPlot.h @@ -132,6 +132,8 @@ public: double getMean(); /** @brief Get the short-term median */ double getMedian(); + /** @brief Get the short-term variance */ + double getVariance(); /** @brief Get the current value */ double getCurrentValue(); void setZeroValue(double zeroValue); @@ -166,6 +168,7 @@ private: QwtArray value; double mean; double median; + double variance; unsigned int averageWindow; QwtArray outputMs; QwtArray outputValue; @@ -208,6 +211,8 @@ public: double getMean(QString id); /** @brief Get the short-term median of a curve */ double getMedian(QString id); + /** @brief Get the short-term variance of a curve */ + double getVariance(QString id); /** @brief Get the last inserted value */ double getCurrentValue(QString id); diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index 2133660f43613ba78de8b4873f3570e025b81a05..fe28b335fde72c3601c3ecdb48a9bee59e92d4cd 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -63,6 +63,7 @@ listedCurves(new QList()), curveLabels(new QMap()), curveMeans(new QMap()), curveMedians(new QMap()), +curveVariances(new QMap()), curveMenu(new QMenu(this)), logFile(new QFile()), logindex(1), @@ -268,6 +269,13 @@ void LinechartWidget::refresh() // str.sprintf("%+.2f", activePlot->getMedian(k.key())); // k.value()->setText(str); // } + QMap::iterator l; + for (l = curveVariances->begin(); l != curveVariances->end(); ++l) + { + // Variance + str.sprintf("%+.5f", activePlot->getVariance(l.key())); + l.value()->setText(str); + } } @@ -388,6 +396,7 @@ QWidget* LinechartWidget::createCurveItem(QString curve) QLabel* label; QLabel* value; QLabel* mean; + QLabel* variance; form->setAutoFillBackground(false); horizontalLayout = new QHBoxLayout(form); horizontalLayout->setSpacing(5); @@ -437,6 +446,12 @@ QWidget* LinechartWidget::createCurveItem(QString curve) // curveMedians->insert(curve, median); // horizontalLayout->addWidget(median); + // Variance + variance = new QLabel(form); + variance->setNum(0.00); + curveVariances->insert(curve, variance); + horizontalLayout->addWidget(variance); + /* Color picker QColor color = QColorDialog::getColor(Qt::green, this); if (color.isValid()) { @@ -453,6 +468,7 @@ QWidget* LinechartWidget::createCurveItem(QString curve) horizontalLayout->setStretchFactor(value, 50); horizontalLayout->setStretchFactor(mean, 50); // horizontalLayout->setStretchFactor(median, 50); + horizontalLayout->setStretchFactor(variance, 50); // Connect actions QObject::connect(checkBox, SIGNAL(clicked(bool)), this, SLOT(takeButtonClick(bool))); diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h index 5ce13eb55c191eaeb2057243e4e8ffa9b53d9956..d14269c6dd472779d1dc287904f6a566fb756f76 100644 --- a/src/ui/linechart/LinechartWidget.h +++ b/src/ui/linechart/LinechartWidget.h @@ -109,6 +109,7 @@ protected: QMap* curveLabels; ///< References to the curve labels QMap* curveMeans; ///< References to the curve means QMap* curveMedians; ///< References to the curve medians + QMap* curveVariances; ///< References to the curve variances QWidget* curvesWidget; ///< The QWidget containing the curve selection button QVBoxLayout* curvesWidgetLayout; ///< The layout for the curvesWidget QWidget