Multiply a constant value to the parameter of a parametric metric

I have a parametric metric with a parameter called maxValue.

var results = ValveTagModel.evalMetrics({
ids: ["my_id"],
expressions: ["rollingSumWithFloor(DiffValue, FloorValue, startValue, maxValue ) "],
interval: "DAY",
start: "2018-10-01",
end: "2019-01-01",
bindings:{  
		maxValue: 3,
		startValue: 0
         }
});

Which works fine, where rollingSumWithFloor is defined in MetricFunctionLibrary as:

rollingSumWithFloor: function(ts: Timeseries, floorValueTS: Timeseries, startValue: double, maxValue: double): Timeseries js server

Now I want to multiply a constant value to my parameter maxValue as follows:

var results = ValveTagModel.evalMetrics({
ids: ["my_id"],
expressions: ["rollingSumWithFloor(DiffValue, FloorValue, startValue, maxValue * 3 ) "],
interval: "DAY",
start: "2018-10-01",
end: "2019-01-01",
bindings:{  
		maxValue: 3,
		startValue: 0
         }
});

evaluating this metric I get the following error:

c3.love.exceptions.C3RuntimeException: java.lang.NoSuchMethodError: c3.love.expr.bytecode.OperatorLib.mul(Ljava/lang/Double;Ljava/lang/Integer;)Ljava/lang/Double;

However, as a workaround if I define a third parameter three, and use it as follows:

var results = ValveTagModel.evalMetrics({
ids: ["my_id"],
expressions: ["rollingSumWithFloor(DiffValue, FloorValue, startValue, maxValue * three ) "],
interval: "DAY",
start: "2018-10-01",
end: "2019-01-01",
bindings:{  
		maxValue: 3,
		startValue: 0,
        three: 3
         }
});

this evaluation now works.

This is strange that the second case leads to an error. Is this a bug?

I had a similar issue here Shift the evaluation of a metric to a specific period in the past

You should try to wrap your constant around number, i.e.

"rollingSumWithFloor(DiffValue, FloorValue, startValue, maxValue * number(3) ) "

@bachr That’s the first thing I tried :slight_smile: it doesn’t work with number() either.

I get this error:

Exception Details:
  Location:
    c3/love/expr/bytecode/Expr_968163271058474302_7020759768987315714.eval(Lc3/love/typesys/Obj;Lc3/love/timeseries/TimeInfo;)Ljava/lang/Object; @104: invokestatic
  Reason:
    Type 'java/lang/Number' (current frame, stack[4]) is not assignable to 'java/math/BigDecimal'
  Current Frame:
    bci: @104
    flags: { }
    locals: { 'c3/love/expr/bytecode/Expr_968163271058474302_7020759768987315714', 'c3/love/typesys/Obj', 'c3/love/timeseries/TimeInfo', 'c3/love/typesys/Arry', 'java/util/ArrayList' }
    stack: { 'c3/love/expr/bytecode/Expr_968163271058474302_7020759768987315714', 'c3/love/typesys/Arry', 'java/util/ArrayList', 'java/lang/Integer', 'java/lang/Number' }
  Bytecode:
    0x0000000: 2ab8 0051 4e2d bb00 5359 b700 553a 0419
  ...   
"

ok can you try to make both doubles, e.g. in the expression 3.0 and in the binding 3.0.

What bachir said, change 3 to 3.0 in the original expression.

That doesn’t make a difference. Tried that as well. Leads to the same error:

"Error: Error compiling class for expression:

Bad type on operand stack
Exception Details:
  Location:
    c3/love/expr/bytecode/Expr_8105746467320053813_5137476905377711601.eval(Lc3/love/typesys/Obj;Lc3/love/timeseries/TimeInfo;)Ljava/lang/Object; @94: invokestatic
  Reason:
    Type 'java/lang/Number' (current frame, stack[4]) is not assignable to 'java/math/BigDecimal'
  Current Frame:
    bci: @94
    flags: { }
    locals: { 'c3/love/expr/bytecode/Expr_8105746467320053813_5137476905377711601', 'c3/love/typesys/Obj', 'c3/love/timeseries/TimeInfo', 'c3/love/typesys/Arry', 'java/util/ArrayList' }
    stack: { 'c3/love/expr/bytecode/Expr_8105746467320053813_5137476905377711601', 'c3/love/typesys/Arry', 'java/util/ArrayList', 'java/lang/Integer', 'java/lang/Number' }
  Bytecode:
    0x0000000: 2ab8 0078 4e2d bb00 7a59 b700 7c3a 0419
    0x0000010: 0404 2ab4 0054 9f00 092a 2b2c b600 7e2a
  

@bachr This is similar error to what you got here: Shift the evaluation of a metric to a specific period in the past. Do you know which version of the server that fix was made to? @rohit.sureka?