Interpolate (…) function example, please

#1

When I do c3ShowType(ExpressionEngineFunction), I see a function called: Interpolate described as:

Function to interpolate data within the given time series. Various forms of interpolation techniques: ZERO, LINEAR, PREVIOUS, NEXT and can be performed on MISSING, DATA (where = 0)

Can someone provide an example of how to invoke this function? Can’t seem to get a working example for myself.

Thanks

Paul

#2

After digging around in some same project code, I was able to answer my own question. Hope this helps others. This is an example of an analytic/metric that was written:

{
“id” : “WellMeasurementFluidLevel_PCPWell”,
“name” : “WellMeasurementFluidLevel”,
“srcType” : “PCPWell”,
“path” : “measurementSeries”,
“expression” : “interpolate(avg(avg(normalized.data.fluidLevel)), ‘LINEAR’, ‘MISSING’)”
}

#3

Here is another example I was able to work out, when declaring a new timeseries from records using tsDecl:

c3Viz(Patient.evalMetricsWithMetadata(
{    
    ids: ["123456"],
    expressions: ["Weight"],
    start: "2015-04-24T00:00:00",
    end: "2015-06-18T00:00:00",
    interval: "DAY"
},  SimpleMetric.array([{
	  	"id" : "Weight",
	  	"name" : "Weight",
	  	"srcType" : "Patient",
  	        "tsDecl" : {
                    "data" : "weight",
                    "treatment" : "AVG",
                    "start" : "dateEnteredUTC",
                    "value" : "weight"
                    "transform" : "interpolate(this, LINEAR, MISSING)"	
          }
    }])
))

In the above, we are declaring a new time series and asking the function to apply the transform/interpolation within the definition itself. So the first parameter is “this”. LINEAR means to apply linear interpolation and MISSING means to use linear interpolation only when data is missing between two real data points.

for more information on interpolate() function, see: c3ShowType(ExpressionEngineFunction)