Debugging Metrics
After developing metrics and evaluating them, often there may be issues. The plot may show an unexpected result, or may show zeros with missing data everywhere.
Data normalization
The first step in debugging is to ensure if the data is normalized. After loading a large chunk of data, normalization must be triggered manually for the first time. If this step is not taken, any metric using normalized data can return no value or no data.
If data is normalized, fetching on the measurement series Type can reveal the earliest and the latest to indicate the period that the data is normalized over. If the latest is before what is expected for the time range of the data, then that means part of the data is not normalized. Try normalizing that data first and then validating the metric again.
On that same measurement series Type, also confirm that the @tsannotation is present.
Example
To check if data is normalized on a specific SmartBulb and field, run the following command in console:
NormalizedTimeseriesPersisted.getId(SmartBulbMeasurementSeries.normalizedTimeseriesKey("SBMS_serialNo_SMBLB1", "power"));Metric implementation
A second place to check if the metric does not return the expected result is the expression, which could be quite complicated. In this scenario, use eval metric with metadata to break the complicated expression into several metrics to see if each step makes sense, and at which step it's not returning the correct result.
Confirm data path
Fetch data on the source Type by including the whole metric path to see if data is correctly linked. Additionally use the asOf option to fetch data as of a specific date.
As an example, assuming the average power for a smart bulb is calculated as:
{
"id": "AveragePower_SmartBulb",
"name": "AveragePower",
"srcType": "SmartBulb",
"description": "Average power over time of the smart bulb",
"path": "bulbMeasurements",
"expression": "avg(avg(normalized.data.power))"
}You can troubleshoot using these two options:
// Option 1
var spec = EvalMetricsSpec.make({
ids: ["SMBLB1"],
expressions: ["AveragePower"],
start: "2013-01-01",
end: "2013-03-01",
interval: "DAY"
});
// Option 2
SmartBulb.fetch({
filter: "id == 'SMBLB1'",
include: "bulbMeasurements.data.power",
asOf: "2013-01-01"
});