GroveStreams
rdallen private msg quote post Address this user
I have spent many hours attempting to get a derived stream working properly, but failing.
I have two components: Lets call them A and B. Each has a latitude and longitude (common stream - values come in randomly).
I want to run a simple calculation on them, comparing the difference.

I created a derived stream, and set it to calculate whenever any value comes in.
I set the Function for the variables to be "Last" - I figure this should use the last value that came in.
My formula for this example is quite simple:

if(isNull(lat1),0,lat1)-if(isNull(lat2),0,lat2)

If component A's stream is updated (lat1), then the calculation runs, but lat2 is NULL. If component B's stream is updated, lat1 is then NULL.

How do I force it to use the last value? Using the Function "Last" doesn't seem to do it.

As an aside, if I have two streams identically named (but different components), and I add them as variables, in the main screen there is no way to determine which is which, as the component name isn't given.
Post 1 IP   flag post
MikeMills private msg quote post Address this user
The Function is used in combination with a cycle. If all of your streams (the dependents and the result) are Regular streams, then the Function is ignored. The function tells the engine what to do when more than one sample falls within a single cycle being derived.

Try this:
Set each dependent's cycle to Year and then set the Cycle to Last. This will grab the last sample uploaded in the current year.


"As an aside, if I have two streams identically named (but different components), and I add them as variables, in the main screen there is no way to determine which is which, as the component name isn't given." - click the dropdown menu on the column header and choose to add the component name to the dependent grid.
Post 2 IP   flag post
rdallen private msg quote post Address this user
Thank you Mike. Your explanation has helped me understand how it works.

I tried your suggestion, and can confirm it worked. From my testing, it seems that this solution will only store a single value, and date it 1/1/2016 0:00:00. Any future values overwrite.
So it is effectively a point stream. In the end, I actually made it a point stream.

Fortunately for my needs this is fine (and actually preferable).
Post 3 IP   flag post
MikeMills private msg quote post Address this user
There are other "recipes" for this too. Let me know if you (or another user) need more derivation solutions.
Post 4 IP   flag post
2965 4 4
Log in or sign up to compose a reply.