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  if (widget_el.isNull())
45  {
46  return false;
47  }
48  ui->spinBoxSamples->setValue(widget_el.attribute("value").toInt());
49  return true;
50 }
51 
52 std::optional<PJ::PlotData::Point> MovingRMS::calculateNextPoint(size_t index)
53 {
54  size_t buffer_size =
55  std::min(size_t(ui->spinBoxSamples->value()), size_t(dataSource()->size()));
56  if (buffer_size != _buffer.size())
57  {
58  _buffer.resize(buffer_size);
60  }
61 
62  const auto& p = dataSource()->at(index);
64 
65  while (_ring_view.size() < buffer_size)
66  {
68  }
69 
70  double total_sqr = 0;
71 
72  for (size_t i = 0; i < buffer_size; i++)
73  {
74  double val = _ring_view[i].y;
75  total_sqr += val * val;
76  }
77 
78  double time = p.x;
79 
80  PJ::PlotData::Point out = { time, sqrt(total_sqr / _ring_view.size()) };
81  return out;
82 }
MovingRMS::_widget
QWidget * _widget
Definition: moving_rms.h:44
MovingRMS::~MovingRMS
~MovingRMS() override
Definition: moving_rms.cpp:16
nonstd::span_lite::size
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span.hpp:1554
moving_rms.h
Ui
Definition: cheatsheet_dialog.h:6
mqtt_test.time
float time
Definition: mqtt_test.py:17
MovingRMS::MovingRMS
MovingRMS()
Definition: moving_rms.cpp:4
PJ::TimeseriesBase::Point
typename PlotDataBase< double, Value >::Point Point
Definition: timeseries.h:23
MovingRMS::xmlSaveState
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
nonstd::ring_span_lite::ring_span::size
size_type size() const nsrs_noexcept
Definition: ring_span.hpp:500
MovingRMS::_buffer
std::vector< PJ::PlotData::Point > _buffer
Definition: moving_rms.h:45
MovingRMS::optionsWidget
QWidget * optionsWidget() override
optionsWidget pointer to a persistent widget used to set the plugin options .
Definition: moving_rms.cpp:28
MovingRMS::calculateNextPoint
std::optional< PJ::PlotData::Point > calculateNextPoint(size_t index) override
Definition: moving_rms.cpp:52
MovingRMS::_ring_view
nonstd::ring_span_lite::ring_span< PJ::PlotData::Point > _ring_view
Definition: moving_rms.h:46
backward::Color::reset
@ reset
Definition: backward.hpp:3678
PJ::TransformFunction_SISO::dataSource
const PlotData * dataSource() const
Definition: transform_function.cpp:113
PJ::PlotDataBase::at
const Point & at(size_t index) const
Definition: plotdatabase.h:193
MovingRMS::xmlLoadState
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
Definition: moving_rms.cpp:41
MovingRMS
Definition: moving_rms.h:14
nonstd::ring_span_lite::ring_span::push_back
void push_back(value_type const &value)
Definition: ring_span.hpp:639
nonstd::ring_span_lite::ring_span
Definition: ring_span.hpp:432
MovingRMS::ui
Ui::MovingRMS * ui
Definition: moving_rms.h:42
MovingRMS::reset
void reset() override
Definition: moving_rms.cpp:22


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45