GroveStreams
MikeMills private msg quote post Address this user
I've been asked a few times how to model a stream that increments values as they arrive. It could be a stream that measures total rainfall or a stream that measures the amount of feed livestock are consuming.

It's very simple to model. Here's how to track increments over each year (this stream will reset after each year back to zero):

Let's assume your measurement stream:
* Is a Regular stream
* Is of type FLOAT
* Has a rollup calendar assigned to it
* Your sensor feeds into this stream over a fixed cycle or at random times - it doesn't matter

Create a new Regular stream and derive it (from an expression) from the measurement stream's Annual SUM virtual stream. This new stream will report the incremental sum of each sample from the measurement stream and then reset back to zero at the beginning of the RollupCalendar year.

How does this work:
The incrementing stream is derived from the measurement stream's Annual SUM virtual stream. The derived stream will check to see if that stream's last sample datetime changes each time derivation runs (around once a minute) and if it does, it will assign itself the current value of that Annual Sum virtual stream. When the new years starts, the Annual SUM stream will start a new interval with a value of zero and thus the count starts over.

The only problem with this technique is that it will only work going forward as samples arrive. It will not derive properly over historical values as it will just grab the SUM value for the end of each year.


Post 1 IP   flag post
MikeMills private msg quote post Address this user
The above solution isn't very intuitive and has some potential use cases that can cause issues so we added an Counter option to a stream definition.




* Edit your component, select a stream and click the Constraints tab
* Check the Is Counter Stream option
* Optionally select a Reset Cycle and a Reset Value.

The Counter option will add new samples to the last non-gap value. The reset options will reset the counter to a defined amount as each new cycle is entered.

Editing historical samples is allowed and will not impact the following value or the tail value.
Post 2 IP   flag post
2968 2 2
Log in or sign up to compose a reply.