use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.
the class JEXLExpressionEngineTest method performExpression.
private double[] performExpression(String expression, Map<String, Object> constants) throws ExpressionException {
// Build a simple request with the given expression
QueryRequest request = new QueryRequest();
Source constant = new Source();
constant.setLabel("x");
request.setSources(Lists.newArrayList(constant));
Expression exp = new Expression();
exp.setLabel("y");
exp.setExpression(expression);
request.setExpressions(Lists.newArrayList(exp));
// Build the fetch results with known values
final int N = 100;
long[] timestamps = new long[N];
double[] xValues = new double[N];
for (int i = 0; i < N; i++) {
timestamps[i] = i * 1000;
xValues[i] = Double.valueOf(i);
}
Map<String, double[]> values = Maps.newHashMap();
values.put("x", xValues);
FetchResults results = new FetchResults(timestamps, values, 1, constants);
// Use the engine to evaluate the expression
jexlExpressionEngine.applyExpressions(request, results);
// Retrieve the results
return results.getColumns().get("y");
}
Aggregations