Skip to content

Commit

Permalink
speed calculation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bartbutenaers committed Apr 1, 2017
1 parent e257ae8 commit 367b271
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion msg_speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ module.exports = function(RED) {

// 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 ...
var seconds = Math.round((currentTime - node.startTime) / 1000);
var seconds = Math.floor((currentTime - node.startTime) / 1000);
for(var i = 0; i < seconds; i++) {
// The total msg count is the sum of all message counts in the circular buffer. Instead of summing
// those continiously, 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 += node.msgCount;
node.totalMsgCount -= node.circularBuffer.get(node.bufferSize-1);
//console.log("node.msgCount = " + node.msgCount + " and node.totalMsgCount = " + node.totalMsgCount );

node.circularBuffer.enq(node.msgCount);

Expand Down Expand Up @@ -85,11 +86,14 @@ module.exports = function(RED) {
}

node.msgCount += 1;
//console.log("New msg arrived. node.msgCount = " + 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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "node-red-contrib-msg-speed",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "A Node Red node to measure the flow message speed",
"dependencies": {
"circular-buffer": "1.0.2",
Expand Down

0 comments on commit 367b271

Please sign in to comment.