Aggregation in a week - the Return

#1

I return about the new metric evaluate interval week.

I can add in Facility.c3typ a func:


evaluateWeek: function(
_ aggregator: string enum(‘SUM’,‘AVG’,‘MIN’,‘MAX’)_
_ metric: MetricId,_
_ …_
_ ): string js server_

and in Facility.js:

function evaluateWeek(aggregator,metric, …) {

var expression = “DayOfWeek==1 ? window(aggregator,metric,1,7): (DayOfWeek==2 ? window(aggregator,metric,0,1) +window(aggregator,metric,1,6) : (DayOfWeek==3 ? window(aggregator,metric,-1,2)+window(aggregator,metric,1,5):(DayOfWeek==4 ? window(aggregator,metric,-2,3)+window(aggregator,metric,1,4) :(DayOfWeek==5 ? window(aggregator,metric,-3,4) +window(aggregator,metric,1,3):(DayOfWeek==6 ? window(aggregator,metric,-4,5) +window(aggregator,metric,1,2):(DayOfWeek==7 ? window(aggregator,metric,-5,6) +window(aggregator,metric,1,1) :0.0))))))”

}

etc etc

Here an example exp:

c3Viz(Facility.evalMetrics({start:‘2015-11-16T00:00:00.000Z’,end:‘2016-11-13T21:59:59.999Z’,ids:[‘15’], expressions:[“DayOfWeek==1 ? window(‘SUM’,energySpend,1,7): (DayOfWeek==2 ? window(‘SUM’,energySpend,0,1) +window(‘SUM’,energySpend,1,6) : (DayOfWeek==3 ? window(‘SUM’,energySpend,-1,2)+window(‘SUM’,energySpend,1,5):(DayOfWeek==4 ? window(‘SUM’,energySpend,-2,3)+window(‘SUM’,energySpend,1,4) :(DayOfWeek==5 ? window(‘SUM’,energySpend,-3,4) +window(‘SUM’,energySpend,1,3):(DayOfWeek==6 ? window(‘SUM’,energySpend,-4,5) +window(‘SUM’,energySpend,1,2):(DayOfWeek==7 ? window(‘SUM’,energySpend,-5,6) +window(‘SUM’,energySpend,1,1) :0.0))))))”], interval:‘DAY’}))

The question is:

I don’t have the var called aggregator because when i pass Comp Metric to my evalMetrics it depends by the simple associated. Is there a “sure”, scientific mode to extract automatically the time operator from metric?

For example for my EnergySpend is right to aggregate the days by SUM but if i have, for example, a metric based on Temperature i must to aggregate for AVG not for SUM. I talk about time aggregator.

Another solution can be to build a new table with a mapping between name metric and a string as aggreator.

New c3typ
string: metricname
string: enum(‘SUM’,‘AVG’,‘MIN’,‘MAX’)

Thanks a lot

0 Likes

#2

Have you tried using field variables of type Metric, in combination with field bindings of EvalMetricSpec? You could perhaps define variables named aggregator and compMetric, use them like window(aggregator, compMetric...) and bind aggregator to "AVG" and compMetric to energySpend when calling evalMetrics.

1 Like

#3

Analyzing the metrics for detecting the aggregator to use can be tricky as you may have a compound metric depending on two metrics one with SUM aggregation and the other with AVG or MIN. E.g.

m1 = AVG(speed)
m2 = SUM(hour)
m3 = m1 * m2

How would you aggregate this compound metric? the right answer depends on your business requirement.

You can build a table that maps a metric with a possible aggregator, but it’s better to just expose the aggregator variable and let the caller decide what aggregation is more suitable. Because for one purpose the user may want SUM but for another use case of the same metric he may want MAX.

1 Like