Expression Capabilities:
Expression examples (Derivation will not occur if the expression returns a result data type that cannot be converted to the derived stream's data type):

When does derivation occur?
GroveStream's will periodically detect (usually every few seconds) when all dependent stream intervals have arrived before doing a derivation. By default, all dependents must have data arrive since the last derivation for derivation to occur. Derivation will also occur if the advanced setting Perform derivation when is set to Any dependent values have arrived and at least one dependent value arrives since the last derivation. Derivation of an interval may be performed several times depending on the size of the interval and the size of its dependent intervals. If new (not updated) dependent intervals arrive and fall within the interval time range being derived, then the derived interval will be calculated with the new interval values. The algorithm for this is a bit complicated as an interval might be derived from another derived variable which is derived from smaller intervals. GroveStreams tracks the smallest dependent interval size end datetime and uses that value within the algorithm to determine interval derivation.

Example: A derived stream has one day cycles but its dependents are one hour cycles. The dependent one hour cycles arrive at different times. The derivation engine will update the derived one day interval several times during a day - whenever all dependent one hour intervals exist for an hour that hasn't been used in a prior derivation. 

A stream has three internal datetimes: start, end and completed. Start is the start datetime of the first interval in the store. End is the end datetime of the last interval in the store. Completed datetimes are used for derivation and are the earliest completed datetime of all dependent streams. If a stream is not a derived stream then its end datetime will be equal to its completed datetime.

Derivation occurs for a stream when all of its dependent streams have completed datetimes that are less than the derived streams' completed datetime (unless Any dependent values have arrived is selected then only one needs to be less). Once a derived interval's end datetime is less than or equal to the streams' completed datetime the derived interval enters a "closed" state. It will not be derived again and derivation moves on to the next set of intervals in the cycle. 

Although a derived interval in a "closed" state will not be re-derived but it can be changed via the API or from within the GroveStreams user interface just like any other stream. To force a derivation on "closed" intervals, delete all interval data from a derived stream and the derivation engine will recalculate it all. Not auto deriving "closed" intervals avoids doing dependency tree look-ups every time an interval value changes (as feeds are uploaded). GroveStreams is all about performance and we feel this limitation is acceptable to keep performance high.

Cycles and Functions
A stream can be derived from other streams with different cycle sizes. If the dependent stream's cycle is smaller it will be rolled up to match the size of the derivation stream. The smaller cycle must be able to rollup evenly into the derived interval (1 second into 10 second is an even rollup - 7 second into 1 minute is uneven). The cycle function will be used for the rollup method. If the dependent stream's cycle is larger then the dependent interval with an end datetime that falls within the derived interval will be used.

You can optionally leave the cycle blank (or set to automatic in the user interface). When it is left blank, GroveStreams will select a cycle for you and perform an on-the-fly rollup if needed.

Cycles and Functions are ignored for point stream dependents.

Expressions
Expressions are composed of variables which are stream. If a variable is an interval stream then the user can choose the interval offset for that variable. For example, if an hourly interval with a time span of 2:00 pm to 3:00 pm is being calculated a dependent variables' offset can be set to -1 and that variables' data for time span 1:00 pm to 2:00 will be used in the calculation. Offsets are useful for things like rolling averages.

Example of a Derived Stream Expression that calculates one second 3 pt rolling averages from Component1.Stream1.

Variables:

Variable
Offset
Type
Stream/Characteristic
Cycle
Cycle Function
n
0
Stream
Component1.Stream1
Second
-
n_minus_1
-1
Stream
Component1.Stream1 Second -
n_minus_2 -2
Stream Component1.Stream1 Second -

Expression:

(n + n_minus_1 + n_minus_2) / 3