moving_rms.cpp
Go to the documentation of this file.
1 #include "moving_rms.h"
2 #include "ui_moving_rms.h"
3 
5  : ui(new Ui::MovingRMS)
6  , _widget(new QWidget())
7  , _buffer(1)
8  , _ring_view(_buffer.begin(), _buffer.end())
9 {
10  ui->setupUi(_widget);
11 
12  connect(ui->spinBoxSamples, qOverload<int>(&QSpinBox::valueChanged), this,
13  [=](int) { emit parametersChanged(); });
14 }
15 
17 {
18  delete ui;
19  delete _widget;
20 }
21 
23 {
24  _buffer.clear();
26 }
27 
29 {
30  return _widget;
31 }
32 
33 bool MovingRMS::xmlSaveState(QDomDocument& doc, QDomElement& parent_element) const
34 {
35  QDomElement widget_el = doc.createElement("options");
36  widget_el.setAttribute("value", ui->spinBoxSamples->value());
37  parent_element.appendChild(widget_el);
38  return true;
39 }
40 
41 bool MovingRMS::xmlLoadState(const QDomElement& parent_element)
42 {
43  QDomElement widget_el = parent_element.firstChildElement("options");
44  ui->spinBoxSamples->setValue(widget_el.attribute("value").toInt());
45  return true;
46 }
47 
48 std::optional<PJ::PlotData::Point> MovingRMS::calculateNextPoint(size_t index)
49 {
50  size_t buffer_size =
51  std::min(size_t(ui->spinBoxSamples->value()), size_t(dataSource()->size()));
52  if (buffer_size != _buffer.size())
53  {
54  _buffer.resize(buffer_size);
56  }
57 
58  const auto& p = dataSource()->at(index);
60 
61  while (_ring_view.size() < buffer_size)
62  {
64  }
65 
66  double total_sqr = 0;
67 
68  for (size_t i = 0; i < buffer_size; i++)
69  {
70  double val = _ring_view[i].y;
71  total_sqr += val * val;
72  }
73 
74  double time = p.x;
75 
76  PJ::PlotData::Point out = { time, sqrt(total_sqr / _ring_view.size()) };
77  return out;
78 }
QWidget * _widget
Definition: moving_rms.h:39
nonstd::ring_span_lite::ring_span< PJ::PlotData::Point > _ring_view
Definition: moving_rms.h:41
virtual size_t size() const
Definition: plotdatabase.h:182
Ui::MovingRMS * ui
Definition: moving_rms.h:37
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
Definition: moving_rms.cpp:41
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
Definition: moving_rms.cpp:33
void reset() override
Definition: moving_rms.cpp:22
typename PlotDataBase< double, Value >::Point Point
Definition: timeseries.h:23
float time
Definition: mqtt_test.py:17
const Point & at(size_t index) const
Definition: plotdatabase.h:192
~MovingRMS() override
Definition: moving_rms.cpp:16
QWidget * optionsWidget() override
optionsWidget pointer to a persistent widget used to set the plugin options .
Definition: moving_rms.cpp:28
size_type size() const nsrs_noexcept
Definition: ring_span.hpp:468
const PlotData * dataSource() const
std::vector< PJ::PlotData::Point > _buffer
Definition: moving_rms.h:40
std::optional< PJ::PlotData::Point > calculateNextPoint(size_t index) override
Definition: moving_rms.cpp:48
void push_back(value_type const &value)
Definition: ring_span.hpp:605


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:38