Creating Expression Engine Function and Add to Window

#1

This can be resolved by supplying the types and .js file used to create “SD” and add it to the “window” function as an aggregation.

'…rolling(‘SD…’

  "expression": "avg(eval('DAY', rolling('SD', identity(1, 'day'), WellJobIsPumpFlushWater), EarliestTubingIsInsertedDate))" 

Below is my progress to add correlation coefficient to the same library (MetricFunctionLibrary )

SimpleCorrelationMetricLibrary.c3typ

    type SimpleCorrelationMetricLibrary mixes MetricFunctionLibrary {
    
    /**
     * Calculates correlation across inputs
     *
     * @param Y
     *           The dependant variable of interest.
     * @param x
     *           The independant variable that is believed to have some causality on Y.
     * 
     * @return Pearson R score for measure of correlation.
     */

    simpleCorrelation: function( Y:Timeseries,
                                 x: Timeseries
                                              ): Timeseries py server




  }

Also is there a global function for the js server that returns a time series object seen in other posts?
If so please share so a python equivalent can be developed.

SimpleCorrelationMetricLibrary.py

import numpy as np
import functools as fc


def simpleCorrelation(Y,x):

	try:
		indi = list(reduce(lambda x, y: x + y, Y.items()))
		depen = list(reduce(lambda x, y: x + y, x.items()))
	except NameError:
		indi = list(fc.reduce(lambda x, y: x + y, Y.items()))
		depen = list(fc.reduce(lambda x, y: x + y, x.items()))		
	
	# print (indi[1])
	a = (np.corrcoef(indi[1], depen[1]))

	flat_list = [item for sublist in a for item in sublist]
	r = (flat_list[1])
	

	return TimeSeries(r)

Testing the Expression in DS server

GasWaterCorrelation = c3.CompoundMetric(
    id ="GasWaterCorrelation",
    name="GasWaterCorrelation",
    expression="simpleCorrelation(WellMeasurementGasRate, WellMeasurementWaterRate)"
)

spec = c3.EvalMetricsSpec(
#     ids = ["COM022","COM032", "CNS110"],
        ids = ["COM022"],
    expressions = ["WellMeasurementWaterRate","WellMeasurementGasRate","GasWaterCorrelation"],
    start = "2017-01-01",
    end = "2017-02-01",
    interval = "DAY"
)

emr = c3.OilGasWell.evalMetric(spec, [GasWaterCorrelation])

calling emr (shown above) object produces the following (shown below).
So as someone who has never seen the source code of the platform and using the above metrics I can only assume that the c3 code is selecting “WellMeasurementWaterRate”: + “WellMeasurementGasRate”: and passing them into SimpleCorrelationMetricLibrary.py but what that data looks like is a complete mystery and due to passing it into a function blind writing code to manipulate or calculate etc is not a trivial task.

> emr
> { "type": { "name": "EvalMetricsResult"}, 
    "result": {"COM022": {"WellMeasurementWaterRate": {
                "m_missing": [100, 
                    100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,
                    100,100,100,100,100,100,100,100,100,100,100,100,100,100,100
                ], 
                "m_interval": "DAY", 
                "m_timeZone": "NONE", 
                "m_end": "2017-02-01T00:00:00", 
                "m_start": "2017-01-01T00:00:00", 
                "type": "NormTimeseriesDouble"
            }, 

            "WellMeasurementGasRate": {
                "m_missing": [100, 
                    100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,
                    100,100,100,100,100,100,100,100,100,100,100,100,100,100,100
                ], 
                "m_interval": "DAY", 
                "m_timeZone": "NONE", 
                "m_end": "2017-02-01T00:00:00", 
                "m_start": "2017-01-01T00:00:00", 
                "type": "NormTimeseriesDouble"
            }
        }
    }
}

The python function above has been written in terms of expecting to receive a dictionary(unlikely).
So the question is what is my function receiving ? (json object?)

 {"WellMeasurementGasRate": {
            "m_missing": [100, 
                100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,
                100,100,100,100,100,100,100,100,100,100,100,100,100,100,100
            ] } }

furthermore how to mix to window?

All steps I am attempting to complete have been done for all aggregation functions that belong to rolling window.

Python Equivalent for returning time series object
Varying size window