Getting associated timestamp of max value on time series


#1

Is there a way to create a metric that returns the time series timestamp that equals the max?

For example, if I have this compound metric below that gets the maximum hourly value:

c3.CompoundMetric(
                      id="MaxLoadbyDay",
                      name="MaxLoadbyDay",
                      expression="max(eval('HOUR', ElectricityConsumptionInterval))"
                 )

And run the spec:

spec = c3.EvalMetricsSpec(expressions='MaxLoadbyDay',
                         interval='DAY',
                         start=start,
                         end=end)

Is there a compound metric that I can create that will return the corresponding timestamp (or the hour that it occurs) that matches the max value of each day?


#2

Not sure if you still need an answer,
You can try a CompoundMetric with the following expression:

max(eval("HOUR", (ElectricityConsumptionInterval == eval("MAX","DAY", max(eval("HOUR", ElectricityConsumptionInterval)))) * timeComponent("HOUR", ElectricityConsumptionInterval)))

The key function is timeComponent