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)
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<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);
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;
......
......@@ -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<double> value;
double mean;
double median;
double variance;
unsigned int averageWindow;
QwtArray<double> outputMs;
QwtArray<double> 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);
......
......@@ -63,6 +63,7 @@ listedCurves(new QList<QString>()),
curveLabels(new QMap<QString, QLabel*>()),
curveMeans(new QMap<QString, QLabel*>()),
curveMedians(new QMap<QString, QLabel*>()),
curveVariances(new QMap<QString, QLabel*>()),
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<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)
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)));
......
......@@ -109,6 +109,7 @@ protected:
QMap<QString, QLabel*>* curveLabels; ///< References to the curve labels
QMap<QString, QLabel*>* curveMeans; ///< References to the curve means
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
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