Error with Simple Metric

#1

We get this error message when we try to evaluate a simple metric

{
“id”: “AverageSpeed_Flight”,
“name”: “AverageSpeed”,
“description”: “Metric that aggregate the Miles per Hour for a Flight”,
“srcType”: “Flight”,
“path”: “flightMeasurementSeries”,
“expression”: “avg(normalized.data.mph)”
}

"CompoundMetricEvaluator error CompoundMetricEvaluator error c3.love.exceptions.C3RuntimeException: MetricEngine error : Simple Metric Evaluation failed. metric=AverageSpeed,srcId=r1,srcType=Flight,start=2016-01-02T00:00:00.000,end=2016-01-03T00:00:00.000,interval=MINUTE,because=MetricEvaluator error ‘Failed to eval expression with bindings for srcId: r1’,me_srcType=’-type-Flight.Flight’,me_srcId=‘r1’,me_metricName=‘AverageSpeed’,me_projection=‘avg(normalized.data.mph)’,me_start=2016-01-02T00:00:00.000,me_end=2016-01-03T00:00:00.000,me_grain=MINUTE,me_timezone=NONE,me_unitId=null,c3.love.exceptions.C3RuntimeException: DataLoaderImpl Error : Call to fetchNormalizedData failed : Field direction in type FlightMeasurement isn’t an enum field. No value mappings exist.↵ at c3.service.metric.MetricUtils.throwError(MetricUtils.java:987)↵ at

The code is provisionned and the data is loaded on https://airline1.c3-e.com/static/console/

0 Likes

#2

Hey Arnoud,

The clue to the solution is in this part of the error message:

call to fetchNormalizedData failed : Field direction in type FlightMeasurement isn’t an enum field. No value mappings exist.

This is trying to tell you that normalization of the data failed when encountering the “direction” field on type FlightMeasurement. As you can imagine, normalization of unconstrained Strings is quite difficult if not impossible.

Unfortunately, the solution to this problem is a little ugly. Basically, you have to use the @ts annotation to tell the NormalizationEngine how to normalize your string field. You want to have a rule for converting from your string into numbers, which allows normal normalization to occur. Treatment “previous” makes the most sense in this case. This is the syntax you’re looking for:

type FlightMeasurement {

@ts(treatment=‘previous’,
valueMappings=[ValueMapping(value = ‘north’, code = 1), ValueMapping(value = ‘south’, code = 2), ValueMapping(value = ‘east’, code = 3), ValueMapping(value = ‘west’, code = 4)])
status: string enum(‘north’, ‘south’, ‘east’, ‘west’)

}

2 Likes

#3

Thanks Riley,

Probably 301 stuff ;).
But it makes sense, thx again!

0 Likes

#4

Indeed, normalizable strings is a bit of a strange use case. In a real application i would recommend something more like:

type FlightMeasurement {

// Degrees from north (0 - 365)
direction: double

}

0 Likes