Fork me on GitHub

while

Equivalent to a while loop that runs while the first argument is true. Restarts the loop when the argument is false.

Oftentimes, you don’t really want all of the raw data from your stream. You are usually interested in timed aggregations or other such things. This is the main use case of the while transform.

This transform performs a while loop on its second argument while its first argument is true. When the first argument becomes false, it returns the resulting datapoint, and begins the next loop.

This allows summing up datapoints over specified time periods. For example, day==next:day is true if the current datapoint and next datapoint in the stream ave timestamps from the same day.

This allows you to write a transform performing an aggregation per day:

while(day==next:day, sum)

The above transform loops through datapoints while they come from the same day, and sums their values. Once the next datapoint is a different day than the current one, it ends the while loop, and returns the sum, giving the sum of all datapoints that day. It then starts a loop for the next day.

The transform can also be used for smoothing. Suppose you want to smooth your data every three datapoints:

while(count%3!=0, mean)

This returns the mean of every consecutive three datapoints, making it easy to do a basic smoothing procedure.

Advanced Usage

The transform can also be used to implement error bars:

while(day==next:day, {"max": max, "min": min, "mean": mean})

This transform returns the mean, max and min datapoint for the day all at once, allowing to plot with error bars.


Transform Details

One-To-OneStatelessPeekInput SchemaOutput Schema
TrueFalseFalse

Arguments

#DescriptionOptionalConstantHijackedDefault
1The statement to check for truthFalseFalseFalse
2pipe to run, and to reset when the first arg is falseFalseFalseTrue

This Site

Contribute

ConnectorDB is a very new open-source project. If you are a designer/developer or ML enthusiast, head on over to the connectordb github, where you can choose which part of ConnectorDB you want to contribute towards! Pull requests or bug reports are welcome!