How to evaluate or stored calc based on normalized time series rather than non-normalized time series data

This works

MyType.evaluate({ filter: "id=='MY_TEST_ID'", projection: 'latestValue(myTimeSeriesHeader[0].data.value)'}).tuples[0]

This doesn’t

MyType.evaluate({ filter: "id=='MY_TEST_ID'", projection: 'latestValue(myTimeSeriesHeader[0].normalized.data.value)'}).tuples[0]

start’ must be specified for timeseries evaluation.

Currently in order to evaluate anything with timeseries you have to provide start/end/interval. Since stored calcs don’t provide a way to pass those information today, its not possible to do this in a stored calc.

However in evaluate you can:
MyType.evaluate({ filter: "id=='MY_TEST_ID'", projection: 'latestValue(myTimeSeriesHeader[0].data.value)', timeRangeStart: "YOUR_START", timeRangeEnd: "YOUR_END", interval:"YOUR_INTERVAL"}).tuples[0]

@rohit.sureka What would be the suggestion for storing the latest value of a timeseries? Currently we do a stored calc based on the raw data (i.e. latestValue(header.data.value)) but this is a problem when there are two data points with the same timestamp but different data versions. Because of the data version the normalized data is correct but using the raw data it is hit and miss which of the two values would be stored in the stored calc field.

Bump bump bump bump bump bump.

may be you can cache your simple metric latestValue(header.data.value)

@brett.thompson @karlbloedorn first off, were you guys able to try what Rohit mentioned above with normalized data by providing start, end and interval?

MyType.evaluate({ filter: “id==‘MY_TEST_ID’”, projection: ‘latestValue(myTimeSeriesHeader[0].normalized.data.value)’, timeRangeStart: “YOUR_START”, timeRangeEnd: “YOUR_END”, interval:“YOUR_INTERVAL”}).tuples[0]
[/quote]

If that works then instead of using stored calc, which doesn’t currently support this evaluation, you could create an adhoc method to recalculate/evaluate this expression whenever you need in the form of a callback and persist the result just like a stored calc would.

@brett.thompson @karlbloedorn The workaround is to add a CUSTOM expression engine function (supported in v7.9 and later) on a type which does the evaluation above and returns you the right value. Once you have that you will be able to use that function in the stored calc expression

Custom expression engine function!!?? Excuse me!!?? can i write stored calc that evaluates a metric and stores it in a field!!?? Can i have a stored calc that invalidates based on time moving forward?

2 Likes

Metrics as fields! Metrics as fields!

2 Likes

@rohit.sureka Where would I find documentation on custom expression engine functions?

See ExpressionEngineFunction Type documentation

Custom expression engine function!!?? Excuse me!!?? can i write stored calc that evaluates a metric and stores it in a field!!??

  • Yes

Can i have a stored calc that invalidates based on time moving forward?

  • Invalidation will follow the exact same rule as for any other expression engine function
1 Like