private static void setInterpolator(Map<String, List<String>> queryParams, MetricDataQueryBuilder builder) { Interpolator interpolator = null; if (queryParams.containsKey(INTERPOLATE)) { String interpolatorType = queryParams.get(INTERPOLATE).get(0); // timeLimit used in case there is a big gap in the data and we don't want to interpolate points. // the limit defines how big the gap has to be in seconds before we just say they're all zeroes. long timeLimit = queryParams.containsKey(MAX_INTERPOLATE_GAP) ? Long.parseLong(queryParams.get(MAX_INTERPOLATE_GAP).get(0)) : Long.MAX_VALUE; if (STEP_INTERPOLATOR.equals(interpolatorType)) { interpolator = new Interpolators.Step(timeLimit); } else if (LINEAR_INTERPOLATOR.equals(interpolatorType)) { interpolator = new Interpolators.Linear(timeLimit); } } builder.setInterpolator(interpolator); }
private static void setInterpolator(Map<String, List<String>> queryParams, MetricDataQueryBuilder builder) { Interpolator interpolator = null; if (queryParams.containsKey(INTERPOLATE)) { String interpolatorType = queryParams.get(INTERPOLATE).get(0); // timeLimit used in case there is a big gap in the data and we don't want to interpolate points. // the limit defines how big the gap has to be in seconds before we just say they're all zeroes. long timeLimit = queryParams.containsKey(MAX_INTERPOLATE_GAP) ? Long.parseLong(queryParams.get(MAX_INTERPOLATE_GAP).get(0)) : Long.MAX_VALUE; if (STEP_INTERPOLATOR.equals(interpolatorType)) { interpolator = new Interpolators.Step(timeLimit); } else if (LINEAR_INTERPOLATOR.equals(interpolatorType)) { interpolator = new Interpolators.Linear(timeLimit); } } builder.setInterpolator(interpolator); }
private Interpolator getInterpolator(String interpolator, long timeLimit) { if (PARAM_STEP_INTERPOLATOR.equals(interpolator)) { return new Interpolators.Step(timeLimit); } else if (PARAM_LINEAR_INTERPOLATOR.equals(interpolator)) { return new Interpolators.Linear(timeLimit); } return null; }
new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 5, 2, 5, 3, 4, 4, 4, 5, 3))), new Interpolators.Linear()); new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 100, 2, 200, 3, 300, 4, 400, 5, 500))), new Interpolators.Linear());
@Test public void testBigSlopeLinearInterpolator() { Interpolator interpolator = new Interpolators.Linear(); TimeValue start = new TimeValue(1, 100); TimeValue end = new TimeValue(5, 500); Assert.assertEquals(100, interpolator.interpolate(start, end, 1)); Assert.assertEquals(200, interpolator.interpolate(start, end, 2)); Assert.assertEquals(300, interpolator.interpolate(start, end, 3)); Assert.assertEquals(400, interpolator.interpolate(start, end, 4)); Assert.assertEquals(500, interpolator.interpolate(start, end, 5)); }
private Interpolator getInterpolator(String interpolator, long timeLimit) { if (PARAM_STEP_INTERPOLATOR.equals(interpolator)) { return new Interpolators.Step(timeLimit); } else if (PARAM_LINEAR_INTERPOLATOR.equals(interpolator)) { return new Interpolators.Linear(timeLimit); } return null; }
@Test public void testSmallSlopeLinearInterpolator() { Interpolator interpolator = new Interpolators.Linear(); TimeValue start = new TimeValue(1, 5); TimeValue end = new TimeValue(5, 3); Assert.assertEquals(5, interpolator.interpolate(start, end, 1)); Assert.assertEquals(5, interpolator.interpolate(start, end, 2)); Assert.assertEquals(4, interpolator.interpolate(start, end, 3)); Assert.assertEquals(4, interpolator.interpolate(start, end, 4)); Assert.assertEquals(3, interpolator.interpolate(start, end, 5)); }