Commit cfce88d5 authored by lm's avatar lm

Added variance calculation to plot window

parent e45ffc80
...@@ -198,6 +198,14 @@ double LinechartPlot::getMedian(QString id) ...@@ -198,6 +198,14 @@ double LinechartPlot::getMedian(QString id)
return data.value(id)->getMedian(); return data.value(id)->getMedian();
} }
/**
* @param id curve identifier
*/
double LinechartPlot::getVariance(QString id)
{
return data.value(id)->getVariance();
}
int LinechartPlot::getAverageWindow() int LinechartPlot::getAverageWindow()
{ {
return averageWindowSize; return averageWindowSize;
...@@ -743,8 +751,9 @@ TimeSeriesData::TimeSeriesData(QwtPlot* plot, QString friendlyName, quint64 plot ...@@ -743,8 +751,9 @@ TimeSeriesData::TimeSeriesData(QwtPlot* plot, QString friendlyName, quint64 plot
maxValue(DBL_MIN), maxValue(DBL_MIN),
zeroValue(0), zeroValue(0),
count(0), count(0),
mean(0.00), mean(0.0),
median(0.00), median(0.0),
variance(0.0),
averageWindow(50) averageWindow(50)
{ {
this->plot = plot; this->plot = plot;
...@@ -802,6 +811,14 @@ void TimeSeriesData::append(quint64 ms, double value) ...@@ -802,6 +811,14 @@ void TimeSeriesData::append(quint64 ms, double value)
medianList.append(this->value[count-i]); medianList.append(this->value[count-i]);
} }
mean = mean / static_cast<double>(qMin(averageWindow,static_cast<unsigned int>(count))); mean = mean / static_cast<double>(qMin(averageWindow,static_cast<unsigned int>(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<double>(qMin(averageWindow,static_cast<unsigned int>(count)));
qSort(medianList); qSort(medianList);
if (medianList.count() > 2) if (medianList.count() > 2)
...@@ -901,6 +918,14 @@ double TimeSeriesData::getMedian() ...@@ -901,6 +918,14 @@ double TimeSeriesData::getMedian()
return median; return median;
} }
/**
* @return the variance
*/
double TimeSeriesData::getVariance()
{
return variance;
}
double TimeSeriesData::getCurrentValue() double TimeSeriesData::getCurrentValue()
{ {
return lastValue; return lastValue;
......
...@@ -132,6 +132,8 @@ public: ...@@ -132,6 +132,8 @@ public:
double getMean(); double getMean();
/** @brief Get the short-term median */ /** @brief Get the short-term median */
double getMedian(); double getMedian();
/** @brief Get the short-term variance */
double getVariance();
/** @brief Get the current value */ /** @brief Get the current value */
double getCurrentValue(); double getCurrentValue();
void setZeroValue(double zeroValue); void setZeroValue(double zeroValue);
...@@ -166,6 +168,7 @@ private: ...@@ -166,6 +168,7 @@ private:
QwtArray<double> value; QwtArray<double> value;
double mean; double mean;
double median; double median;
double variance;
unsigned int averageWindow; unsigned int averageWindow;
QwtArray<double> outputMs; QwtArray<double> outputMs;
QwtArray<double> outputValue; QwtArray<double> outputValue;
...@@ -208,6 +211,8 @@ public: ...@@ -208,6 +211,8 @@ public:
double getMean(QString id); double getMean(QString id);
/** @brief Get the short-term median of a curve */ /** @brief Get the short-term median of a curve */
double getMedian(QString id); double getMedian(QString id);
/** @brief Get the short-term variance of a curve */
double getVariance(QString id);
/** @brief Get the last inserted value */ /** @brief Get the last inserted value */
double getCurrentValue(QString id); double getCurrentValue(QString id);
......
...@@ -63,6 +63,7 @@ listedCurves(new QList<QString>()), ...@@ -63,6 +63,7 @@ listedCurves(new QList<QString>()),
curveLabels(new QMap<QString, QLabel*>()), curveLabels(new QMap<QString, QLabel*>()),
curveMeans(new QMap<QString, QLabel*>()), curveMeans(new QMap<QString, QLabel*>()),
curveMedians(new QMap<QString, QLabel*>()), curveMedians(new QMap<QString, QLabel*>()),
curveVariances(new QMap<QString, QLabel*>()),
curveMenu(new QMenu(this)), curveMenu(new QMenu(this)),
logFile(new QFile()), logFile(new QFile()),
logindex(1), logindex(1),
...@@ -268,6 +269,13 @@ void LinechartWidget::refresh() ...@@ -268,6 +269,13 @@ void LinechartWidget::refresh()
// str.sprintf("%+.2f", activePlot->getMedian(k.key())); // str.sprintf("%+.2f", activePlot->getMedian(k.key()));
// k.value()->setText(str); // k.value()->setText(str);
// } // }
QMap<QString, QLabel*>::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) ...@@ -388,6 +396,7 @@ QWidget* LinechartWidget::createCurveItem(QString curve)
QLabel* label; QLabel* label;
QLabel* value; QLabel* value;
QLabel* mean; QLabel* mean;
QLabel* variance;
form->setAutoFillBackground(false); form->setAutoFillBackground(false);
horizontalLayout = new QHBoxLayout(form); horizontalLayout = new QHBoxLayout(form);
horizontalLayout->setSpacing(5); horizontalLayout->setSpacing(5);
...@@ -437,6 +446,12 @@ QWidget* LinechartWidget::createCurveItem(QString curve) ...@@ -437,6 +446,12 @@ QWidget* LinechartWidget::createCurveItem(QString curve)
// curveMedians->insert(curve, median); // curveMedians->insert(curve, median);
// horizontalLayout->addWidget(median); // horizontalLayout->addWidget(median);
// Variance
variance = new QLabel(form);
variance->setNum(0.00);
curveVariances->insert(curve, variance);
horizontalLayout->addWidget(variance);
/* Color picker /* Color picker
QColor color = QColorDialog::getColor(Qt::green, this); QColor color = QColorDialog::getColor(Qt::green, this);
if (color.isValid()) { if (color.isValid()) {
...@@ -453,6 +468,7 @@ QWidget* LinechartWidget::createCurveItem(QString curve) ...@@ -453,6 +468,7 @@ QWidget* LinechartWidget::createCurveItem(QString curve)
horizontalLayout->setStretchFactor(value, 50); horizontalLayout->setStretchFactor(value, 50);
horizontalLayout->setStretchFactor(mean, 50); horizontalLayout->setStretchFactor(mean, 50);
// horizontalLayout->setStretchFactor(median, 50); // horizontalLayout->setStretchFactor(median, 50);
horizontalLayout->setStretchFactor(variance, 50);
// Connect actions // Connect actions
QObject::connect(checkBox, SIGNAL(clicked(bool)), this, SLOT(takeButtonClick(bool))); QObject::connect(checkBox, SIGNAL(clicked(bool)), this, SLOT(takeButtonClick(bool)));
......
...@@ -109,6 +109,7 @@ protected: ...@@ -109,6 +109,7 @@ protected:
QMap<QString, QLabel*>* curveLabels; ///< References to the curve labels QMap<QString, QLabel*>* curveLabels; ///< References to the curve labels
QMap<QString, QLabel*>* curveMeans; ///< References to the curve means QMap<QString, QLabel*>* curveMeans; ///< References to the curve means
QMap<QString, QLabel*>* curveMedians; ///< References to the curve medians QMap<QString, QLabel*>* curveMedians; ///< References to the curve medians
QMap<QString, QLabel*>* curveVariances; ///< References to the curve variances
QWidget* curvesWidget; ///< The QWidget containing the curve selection button QWidget* curvesWidget; ///< The QWidget containing the curve selection button
QVBoxLayout* curvesWidgetLayout; ///< The layout for the curvesWidget QWidget QVBoxLayout* curvesWidgetLayout; ///< The layout for the curvesWidget QWidget
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment