Intial Commit
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/.msg_speed.js.swp
generated
vendored
Normal file
37
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
jspm_packages
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
201
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
93
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/README.md
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
# node-red-contrib-msg-speed
|
||||
A Node Red node for measuring flow message speed.
|
||||
|
||||
## Install
|
||||
Run the following npm command in your Node-RED user directory (typically ~/.node-red):
|
||||
```
|
||||
npm install node-red-contrib-msg-speed
|
||||
```
|
||||
## How it works
|
||||
This node will count all messages that arrive at the input port, and calculate the message speed *every second*.
|
||||
|
||||
For example when the frequency is 'minute', it will count all the messages received in the *last minute*:
|
||||
|
||||

|
||||
|
||||
A second later, the calculation is repeated: again the messages received in the last minute will be counted.
|
||||
|
||||

|
||||
|
||||
The measurement interval is like a **moving window**, that is being moved every second.
|
||||
|
||||
The process continues this way, while the moving window is discarding old messages and taking into account new messages:
|
||||
|
||||

|
||||
|
||||
## Output message
|
||||
+ First output: The message speed information will be send to the first output port as `msg.payload`. This payload could be visualised e.g. in a dashboard graph:
|
||||
|
||||

|
||||
|
||||
An extra `msg.frequency` field is also available (containing 'sec', 'min', 'hour').
|
||||
+ Second output (since version 0.0.5): The original input message will be forwarded to this output port, which allows the speed node to be ***chained*** for better performance:
|
||||
|
||||

|
||||
|
||||
In this example we have created a single *chain of nodes*: the decoder gets images from a camera, calculates the speed and detects number plates in the images. The original input message is passed through all the nodes, which improves performance since the large image doesn't need to be copied to new messages.
|
||||
|
||||
The same result could be achieved (in versions < 0.0.5) by using a second wire after the decoder node:
|
||||
|
||||

|
||||
|
||||
In the latter flow, Node-Red will copy the original input message to send a *cloned message* to the speed node. This means that the original image also will be cloned, which has a negative impact on performance...
|
||||
## Node status
|
||||
The message speed will be displayed as node status, in the flow editor:
|
||||
|
||||

|
||||
|
||||
```
|
||||
[{"id":"a50d24c0.afaf38","type":"function","z":"47b91ceb.38a754","name":"Msg factory","func":"// Repeat the msg every 50 milliseconds\nvar repeatInterval = 50;\n\nvar interval = setInterval(function() {\n var counter = context.get('counter') || 0;\n counter = counter + 1;\n \n node.send({topic: 'mytopic_' + counter});\n \n if(counter >= 3000) {\n clearInterval(interval);\n counter = 0;\n }\n \n context.set('counter', counter);\n \n}, repeatInterval); \n\nreturn null;","outputs":1,"noerr":0,"x":453.76568603515625,"y":435.00000762939453,"wires":[["6e086760.71f778"]]},{"id":"da8aea7d.805558","type":"inject","z":"47b91ceb.38a754","name":"","topic":"","payload":"Start","payloadType":"str","repeat":"","crontab":"","once":false,"x":277.7657165527344,"y":435.00000762939453,"wires":[["a50d24c0.afaf38"]]},{"id":"6e086760.71f778","type":"msg-speed","z":"47b91ceb.38a754","name":"","frequency":"min","estimation":false,"ignore":false,"x":650.765625,"y":434.75,"wires":[["a5677c9a.dd884"]]},{"id":"a5677c9a.dd884","type":"ui_chart","z":"47b91ceb.38a754","name":"Messages per minute","group":"1a7f6b0.0560695","order":7,"width":0,"height":0,"label":"Messages per minute","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"Messages per minute","ymin":"0","ymax":"80","removeOlder":"5","removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"x":868.5312423706055,"y":434.5429382324219,"wires":[[],[]]},{"id":"1a7f6b0.0560695","type":"ui_group","z":"","name":"Performance","tab":"18b10517.00400b","disp":true,"width":"6"},{"id":"18b10517.00400b","type":"ui_tab","z":"","name":"Performance","icon":"show_chart"}]
|
||||
```
|
||||
|
||||
During the startup period the message count will be displayed orange:
|
||||
|
||||

|
||||
|
||||
And when 'ignore speed during startup' is active, the node status will indicate this during the startup period:
|
||||
|
||||

|
||||
|
||||
## Startup period
|
||||
The speed is being calculated every second. As a result there will be a startup period, when the frequency is minute or hour (respectively a startup period of 60 seconds or 3600 seconds).
|
||||
For example when the speed is 1 message per second, this corresponds to a speed of 60 messages per minute. However during the first minute the speed will be incomplete:
|
||||
+ After the first second, the speed is 1 message per minute
|
||||
+ After the second, the speed is 2 messages per minute
|
||||
+ ...
|
||||
+ After one minute, the speed is 60 messages msg per minute
|
||||
|
||||
This means the speed will increase during the startup period, to reach the final value:
|
||||
|
||||

|
||||
|
||||
## Node configuration
|
||||
|
||||
### Frequency
|
||||
The frequency ('second', 'minute', 'hour') defines the interval length of the moving window.
|
||||
|
||||
Caution: long intervals (like 'hour' since version **0.0.4**) will take more memory to store all the intermediate speed calculations (i.e. one calculation per second).
|
||||
|
||||
### Estimate speed (during startup period) - Since version 0.0.3
|
||||
During the startup period, the calculated speed will be incorrect. When estimation is activated, the final speed will be estimated during the startup period (using linear interpolation). The graph will start from zero immediately to an estimation of the final value:
|
||||
|
||||

|
||||
|
||||
Caution: estimation is very useful if the message rate is stable. However when the message rate is very unpredictable, the estimation will result in incorrect values. In the latter case it might be advised to enable 'ignore speed during startup'.
|
||||
|
||||
### Ignore speed (during startup period) - Since version 0.0.3
|
||||
During the startup period, the calculated speed will be incorrect. When ignoring speed is activated, no messages will be send on the output port during the startup period. This way it can be avoided that faulty speed values are generated.
|
||||
|
||||
Moreover during the startup period no node status would be displayed.
|
||||
|
||||
## Use cases
|
||||
* Trigger an alarm e.g. when the message rate drops to 0 messages per minute.
|
||||
* Performance measurement, e.g. track the number of images per second (received from a camera).
|
||||
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/icons/speed.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 417 B |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/Startup.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/estimation.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/speed1.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 6.7 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/speed2.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/speed3.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/speed4.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/speed_chain.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/speed_chart.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/speed_parallel.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 8.5 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/startup_ignored.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/images/startup_status.png
generated
vendored
Normal file
|
After Width: | Height: | Size: 15 KiB |
72
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/msg_speed.html
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<!--
|
||||
Copyright 2017, Bart Butenaers
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<script type="text/x-red" data-template-name="msg-speed">
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-frequency"><i class="fa fa-random"></i> Frequency</label>
|
||||
<select id="node-input-frequency">
|
||||
<option value="sec">Second</option>
|
||||
<option value="min">Minute</option>
|
||||
<option value="hour">Hour</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input type="checkbox" id="node-input-estimation" style="display: inline-block; width: auto; vertical-align: top;">
|
||||
<label for="node-input-estimation" style="width: auto">Estimate speed during startup period</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input type="checkbox" id="node-input-ignore" style="display: inline-block; width: auto; vertical-align: top;">
|
||||
<label for="node-input-ignore" style="width: auto">Ignore speed during startup period</label>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="msg-speed">
|
||||
<p>A node to measure the flow message speed.</p>
|
||||
<p><strong>Frequency</strong></p>
|
||||
<p>The speed will be measured at the specified frequency.
|
||||
E.g. frequency 'hour' means that (every second) the average speed of the previous hour will be calculated.</p>
|
||||
<p><strong>Estimate speed</strong></p>
|
||||
<p>In case estimation is disabled, the speed will be incorrect during the startup period.
|
||||
E.g. when every second 1 message arrives, the calculated speed will only be correct after the first minute has passed.
|
||||
When estimation is enabled, the final speed will be estimated during the startup interval (in this example during the first minute).
|
||||
This setting is useless when frequency is 'second' (which has no startup period) or when the 'ignore speed' checkbox is selected.</p>
|
||||
<p><strong>Ignore speed</strong></p>
|
||||
<p>When speed is ignored during the startup period, no messages will be send to the output port during the startup period.
|
||||
Moreover, the node status (in the flow editor) will not display the calculated speed.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType("msg-speed", {
|
||||
category: "performance",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
frequency: {value:"sec"},
|
||||
estimation: {value:false},
|
||||
ignore: {value:false},
|
||||
},
|
||||
color:"#e2d96e",
|
||||
inputs: 1,
|
||||
outputs: 2,
|
||||
outputLabels: ["speed","input msg"],
|
||||
icon: "speed.png",
|
||||
label: function() {
|
||||
return this.name || "msg-speed";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name ? "node_label_italic" : "";
|
||||
},
|
||||
});
|
||||
</script>
|
||||
175
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/msg_speed.js
generated
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* Copyright 2017 Bart Butenaers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var CircularBuffer = require("circular-buffer");
|
||||
var Math = require("mathjs");
|
||||
|
||||
function speed(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
this.estimationStartup = config.estimation || false;
|
||||
this.ignoreStartup = config.ignore || false;
|
||||
|
||||
// The buffer size depends on the frequency
|
||||
switch(config.frequency) {
|
||||
case 'sec':
|
||||
this.bufferSize = 1;
|
||||
break;
|
||||
case 'min':
|
||||
this.bufferSize = 60;
|
||||
break;
|
||||
case 'hour':
|
||||
this.bufferSize = 60 * 60;
|
||||
break;
|
||||
default:
|
||||
this.bufferSize = 1; // Default 'sec'
|
||||
}
|
||||
|
||||
this.circularBuffer = new CircularBuffer(this.bufferSize);
|
||||
|
||||
this.frequency = config.frequency || 'sec';
|
||||
this.msgCount = 0;
|
||||
this.prevStartup = false;
|
||||
this.prevTotalMsgCount = 0;
|
||||
this.totalMsgCount = 0;
|
||||
this.startTime = null; // When the first (unprocessed) message has arrived
|
||||
this.endTime = null; // When the last (unprocessed) message has arrived
|
||||
this.timer = null;
|
||||
|
||||
var analyse = function() {
|
||||
if (node.startTime == null) {
|
||||
node.startTime = new Date().getTime();
|
||||
}
|
||||
|
||||
// Register the time when the last message has arrived (or when the last timer was called, when no message has arrived)
|
||||
node.endTime = new Date().getTime();
|
||||
|
||||
// Calculate the time interval (in seconds) since the first (unprocessed) message has arrived
|
||||
var seconds = (node.endTime - node.startTime) / 1000;
|
||||
var remainder = (seconds - Math.floor(seconds)) * 1000;
|
||||
seconds = Math.floor(seconds);
|
||||
|
||||
// Correct the end time with the remainder, since the time interval since the last message (until now) is skipped in the current calculation.
|
||||
// Otherwise timeslices will get behind, and the curve would have some overshoot (at startup) period before reaching the final speed.
|
||||
node.endTime -= remainder;
|
||||
|
||||
//console.log(seconds + " seconds between " + new Date(node.startTime).toISOString().slice(11, 23) + " and " + new Date(node.endTime).toISOString().slice(11, 23));
|
||||
|
||||
// Store the message count (of the previous second) in the circular buffer. However the timer can be
|
||||
// delayed, so make sure this is done for EVERY second since the last time we got here ...
|
||||
// 10 images/2,5 seconds = 240 images/second
|
||||
for(var i = 0; i < seconds; i++) {
|
||||
var original = node.totalMsgCount;
|
||||
// In the first second we store (the count of) all received messages, except the last one (that has been received in the next second).
|
||||
// In the next second we store that remaining (single) last message. In all later seconds (of this loop) we will store 0.
|
||||
var added = (i == 0) ? Math.max(0, node.msgCount - 1) : Math.max(0, node.msgCount);
|
||||
|
||||
// Check the content of the tail buffer cell (before it is being removed by inserting a new cell at the head), if available already
|
||||
var removed = (node.circularBuffer.size() >= node.bufferSize) ? node.circularBuffer.get(node.bufferSize-1) : 0;
|
||||
|
||||
// The total msg count is the sum of all message counts in the circular buffer. Instead of summing all those
|
||||
// buffer cells continiously (over and over again), we will update the sum together with the buffer content.
|
||||
// Sum = previous sum + message count of last second (which is going to be added to the buffer)
|
||||
// - message count of the first second (which is going to be removed from the buffer).
|
||||
node.totalMsgCount = original + added - removed;
|
||||
//console.log(node.totalMsgCount + " = " + original + " + " + added + " - " + removed);
|
||||
|
||||
// Store the new count in the circular buffer (which will also trigger deletion of the oldest cell at the buffer trail)
|
||||
node.circularBuffer.enq(added);
|
||||
|
||||
var totalMsgCount = node.totalMsgCount;
|
||||
var startup = false;
|
||||
|
||||
// Do a linear interpolation if required (only relevant in the startup period)
|
||||
if (node.circularBuffer.size() < node.circularBuffer.capacity()) {
|
||||
startup = true;
|
||||
|
||||
if (node.estimationStartup == true && node.circularBuffer.size() > 0) {
|
||||
totalMsgCount = Math.floor(totalMsgCount * node.circularBuffer.capacity() / node.circularBuffer.size());
|
||||
}
|
||||
}
|
||||
|
||||
// Update the status in the editor with the last message count (only if it has changed), or when switching between startup and real
|
||||
if (node.prevTotalMsgCount != node.totalMsgCount || node.prevStartup != startup) {
|
||||
// Show startup speed values in orange, and real values in green
|
||||
if (startup == true) {
|
||||
if (node.ignoreStartup == true) {
|
||||
node.status({fill:"yellow",shape:"ring",text:" start ignored" });
|
||||
}
|
||||
else {
|
||||
node.status({fill:"yellow",shape:"ring",text:" " + totalMsgCount + "/" + node.frequency });
|
||||
}
|
||||
}
|
||||
else {
|
||||
node.status({fill:"green",shape:"dot",text:" " + totalMsgCount + "/" + node.frequency });
|
||||
}
|
||||
node.prevTotalMsgCount = totalMsgCount;
|
||||
}
|
||||
|
||||
// Send a message on the first output port, when not ignored during the startup period
|
||||
if (node.ignoreStartup == false || startup == false) {
|
||||
node.send([{ payload: totalMsgCount, frequency: node.frequency }, null]);
|
||||
}
|
||||
|
||||
node.prevStartup = startup;
|
||||
|
||||
// The message count that has already been added, shouldn't be added again the next second
|
||||
node.msgCount = Math.max(0, node.msgCount - added);
|
||||
}
|
||||
|
||||
if (seconds > 0) {
|
||||
// Our new second starts at the end of the previous second
|
||||
node.startTime = node.endTime;
|
||||
}
|
||||
}
|
||||
|
||||
var node = this;
|
||||
|
||||
this.on("input", function(msg) {
|
||||
if (node.timer) {
|
||||
// An msg has arrived during the specified (timeout) interval, so remove the (timeout) timer.
|
||||
clearInterval(node.timer);
|
||||
}
|
||||
|
||||
node.msgCount += 1;
|
||||
//console.log("New msg arrived resulting in a message count of " + node.msgCount );
|
||||
|
||||
analyse();
|
||||
|
||||
// Register a new timer (with a timeout interval of 1 second), in case no msg should arrive during the next second.
|
||||
node.timer = setInterval(function() {
|
||||
//console.log("Timer called. node.msgCount = " + node.msgCount );
|
||||
|
||||
// Seems no msg has arrived during the last second, so register a zero count
|
||||
analyse();
|
||||
}, 1000);
|
||||
|
||||
// Send the original message on the second output port
|
||||
node.send([null, msg]);
|
||||
});
|
||||
|
||||
this.on("close",function() {
|
||||
if (node.timer) {
|
||||
// Stop the previous timer, to avoid having multiple timers running in parallel after a redeploy.
|
||||
clearInterval(node.timer);
|
||||
}
|
||||
node.status({});
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("msg-speed", speed);
|
||||
};
|
||||
58
nodered/rootfs/data/node_modules/node-red-contrib-msg-speed/package.json
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"_from": "node-red-contrib-msg-speed@0.0.5",
|
||||
"_id": "node-red-contrib-msg-speed@0.0.5",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-0rvNnZ49VZBbp6pcbfrKrvhJku8=",
|
||||
"_location": "/node-red-contrib-msg-speed",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "node-red-contrib-msg-speed@0.0.5",
|
||||
"name": "node-red-contrib-msg-speed",
|
||||
"escapedName": "node-red-contrib-msg-speed",
|
||||
"rawSpec": "0.0.5",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.0.5"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/node-red-contrib-msg-speed/-/node-red-contrib-msg-speed-0.0.5.tgz",
|
||||
"_shasum": "d2bbcd9d9e3d55905ba7aa5c6dfacaaef84992ef",
|
||||
"_spec": "node-red-contrib-msg-speed@0.0.5",
|
||||
"_where": "/data",
|
||||
"author": {
|
||||
"name": "Bart Butenaers"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/bartbutenaers/node-red-contrib-msg-speed/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"circular-buffer": "1.0.2",
|
||||
"mathjs": "3.9.3"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A Node Red node to measure the flow message speed",
|
||||
"homepage": "https://github.com/bartbutenaers/node-red-contrib-msg-speed",
|
||||
"keywords": [
|
||||
"node-red",
|
||||
"speed",
|
||||
"rate",
|
||||
"count"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"name": "node-red-contrib-msg-speed",
|
||||
"node-red": {
|
||||
"nodes": {
|
||||
"msg-speed": "msg_speed.js"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/bartbutenaers/node-red-contrib-msg-speed.git"
|
||||
},
|
||||
"version": "0.0.5"
|
||||
}
|
||||