node-red-nodes icon indicating copy to clipboard operation
node-red-nodes copied to clipboard

Andowinger add median

Open andowinger opened this issue 2 years ago • 7 comments

Types of changes

  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)

Proposed changes

https://discourse.nodered.org/t/feature-request-smooth-add-median-filter-to-node-red-node-smooth/60359

Checklist

  • [x] I have read the contribution guidelines
  • [x] For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • [ ] I have run grunt to verify the unit tests pass
  • [ ] I have added suitable unit tests to cover the new/changed functionality

andowinger avatar Mar 27 '22 21:03 andowinger

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: andowinger (4508c3f67bed70fb2669c2e29f944dbf22707a7d, 262976efc44bbe1810b3c50534f52db9931468fb, 7567d9f532f0abd59e2fecfcbcf496f1c309fdf4)

Added "median" option to the Smooth function filters

andowinger avatar Mar 27 '22 21:03 andowinger

Looks good - would be great if you could add some tests to tests/function/17-smooth_spec.js as well... Thanks

dceejay avatar Mar 27 '22 22:03 dceejay

Looks good - would be great if you could add some tests to tests/function/17-smooth_spec.js as well... Thanks

Ok, I will try to do that soon

andowinger avatar Mar 28 '22 18:03 andowinger

@dceejay I added a test, but I don't know how to run the test: At least installing the two required modules and running a node .\17-smooth_spec.js didnot work since describe is not defined. I guess I would need to install a real test environment or something. If you could run it or give guidance what I am missing out, this would be great.

andowinger avatar Apr 10 '22 20:04 andowinger

Hi @andowinger - If you have mocha installed you should be able to run (at the top directory level of the overall project) mocha test/function/smooth/17-smooth_spec.js to run the tests for this node - you should get an output like


  smooth node
    ✓ should be loaded with correct defaults
    ✓ should average over a number of inputs
    ✓ should average over a number of inputs using median
    ✓ should average over a number of inputs - another property - foo
    ✓ should be able to be reset
    ✓ should be able to be reset - while using another property - foo
    ✓ should output max over a number of inputs
    ✓ should output min over a number of inputs
    ✓ should output standard deviation over a number of inputs
    ✓ should do a low pass filter over a number of inputs
    ✓ should do a high pass filter over a number of inputs
    ✓ ignore msg with non numeric payload (55ms)
    ✓ ignore msg with no payload (53ms)
    ✓ should average over a number of inputs on different topics
    ✓ should average over different topics if asked
    ✓ should reduce the number of messages by averaging if asked
    ✓ should reduce the number of messages by max value, if asked
    ✓ should reduce the number of messages by min value, if asked


  18 passing (313ms)

Then optionally you could run grunt (you may need to sudo npm i -g grunt-cli to install it) - to run all the tests in the project.

dceejay avatar Apr 11 '22 22:04 dceejay

Hey @dceejay I get this error message:

  1. smooth node "before each" hook for "should be loaded with correct defaults": TypeError: Cannot read property 'init' of undefined at NodeTestHelper.startServer (node_modules\node-red-node-test-helper\index.js:315:19) at Context. (test\function\smooth\17-smooth_spec.js:10:16) at processImmediate (internal/timers.js:461:21)

  2. smooth node "after each" hook for "should be loaded with correct defaults": TypeError: Cannot read property 'clearRegistry' of undefined at NodeTestHelper.unload (node_modules\node-red-node-test-helper\index.js:283:24) at Context. (test\function\smooth\17-smooth_spec.js:14:16) at processImmediate (internal/timers.js:461:21)

I am using node with Windows. I guess I should set up a VM with a Linux distribution and retry it... I will do this within the next few days - except that you now by any chance the reason for this error and how to fix it.

andowinger avatar Apr 21 '22 12:04 andowinger