Rounding timeseries values to a pre-defined number of decimals

#1

Here, my code:

var myInterval = 1000 * 60 * 60 * 2; // Hours in millisecond
var endFilter = new DateTime(); // NOW
var startFilter = new DateTime(endFilter-myInterval);
var timeRange = TimeRange.make({start:startFilter, end:endFilter});
	
var asset = 'myAsset';
var latestValuePowerOnOffMetric = CompoundMetric.make(
		{
		  "id": "GetRoundedValues",
		  "name": "GetRoundedValues",
		  "expression" : "round(MyCompoundMetric, 2)",
		  "description": "Get the values from 'MyCompoundMetric' rounded to the second decimal."
		} 
	);

	temp = "GetRoundedValues";

	var rounded= MyType.evalMetricsWithMetadata(
		{
			start: timeRange.start,
		    end: timeRange.end,
		    ids:[asset],
		    interval: "SECOND",
			expressions:[temp]
		}
		, [latestValuePowerOnOffMetric]);

c3Viz(rounded)

If I use the expression: "round(MyCompoundMetric)" without definining the scale, I get no error but the result is rounded to 0th decimal, i.e. the Unit and this is the unwanted behavior.

On the contrary, if I set "expression" : "round(MyCompoundMetric, 2)" I obtain the following error:

java.lang.NoSuchMethodError: c3.love.expr.bytecode.TsFuncLib.round(Lc3/love/timeseries/LazyTimeseries;Ljava/lang/Double;)Lc3/love/timeseries/LazyTimeseries;\n\tat

I do need to round my values becouse in same specific cases in which I expect to have 0.1 in my dashboard, I obtain something like this: 0.10000000000000

I searched for documentation here: c3ShowType(ExpressionEngineFunction)

0 Likes

#2

What version of c3server is this being run this on? (Check by running c3Grid(Cluster.hosts()) and looking for the numeric version under the ‘pkgName’ field) This is something that is fixed in a release of c3server 7.9.

0 Likes

#3

Thank you for your anwser, amlsf.

The versions I’m working on is:

  • Production: c3-server-7.8.5.23-1
  • Development: c3-server-7.8.8.68-1

Therefore, should we wait for newer version (7.9++) to fix this behaviour, shouldn’t?

Regards,
Riccardo

0 Likes

#4

@rghera This has already been fixed in the v7.9 version and we should validate once we upgrade

0 Likes