tsDecl or expression on TimeseriesDataPoint

#1

My data is stored with the TimeseriesDataPoint type. I want to create a simple metric to extract the time series. I tried both tsDecl and expression. Can anyone explain what the thought process should be when determining which one to use?

SimpleMetric.make({
    id: 'x_ItemFacility',
    name: 'x',
    srcType: 'ItemFacility',
    path: 'inventory',
    tsDecl: {
        data: "data",
        start: "start",
        end:'end',
        treatment: "PREVIOUS",
        value: 'quantity'
  })

SimpleMetric.make({
    id: 'y_ItemFacility',
    name: 'y',
    srcType: 'ItemFacility',
    path: 'inventory',
    expression: 'previous(normalized.data.quantity)'
})


0 Likes

#2

@qiwei.li

Using the normalized version simply looks up the value for the time series from the cached values (aka normalized) and returns the value to the user.

The TSDecl version is mainly for converting points that have not previously gone through normalization and needs to be converted to a time series on the fly. This involves fetching of the raw objects EVERYTIME the tsDecl metric is evaluated. Underneath they go through the same engine to convert the value to a Timeseries but in tsDecl we are generating this series on the fly without storing any thing.

Normalized version is almost always preferred since it avoids raw data fetch and the data retrieval is extremely fast as well.

1 Like

#3

and according to me here is the workflow I would try:

  1. Try using expression

  2. If not possible try using TsDecl

  3. If not possible try using ActionDecl (and ask PLAT because if you have to use ActionDecl there may be a platform feature missing)

Note: This has nothing todo with normalizable or not.

@rohit.sureka do you agree?

2 Likes

#4

@romain.juban yes that order is the right way to approaching choice of metric.

0 Likes