use of com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean in project sidewinder by srotya.
the class TestChainFunction method testTwoFunctions.
@Test
public void testTwoFunctions() throws Exception {
SeriesOutput series = new SeriesOutput("cpu", "test", Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("1").build(), Tag.newBuilder().setTagKey("t").setTagValue("2").build()));
List<DataPoint> dps = new ArrayList<>();
long baseTs = 1486617103629L;
for (int i = 0; i < 4; i++) {
dps.add(new DataPoint(baseTs + 30_000 * i, 1));
}
series.setDataPoints(dps);
series.setFp(false);
List<SeriesOutput> seriesList = Arrays.asList(series);
ChainFunction cf = new ChainFunction();
WindowedAggregator rwa = new WindowedMean();
rwa.init(new Object[] { 70, "smean" });
WindowedAggregator rwa2 = new WindowedMean();
rwa2.init(new Object[] { 200, "smean" });
cf.init(new Function[] { rwa, rwa2 });
List<SeriesOutput> apply = cf.apply(seriesList);
List<DataPoint> result = apply.get(0).getDataPoints();
assertEquals(1, result.size());
assertEquals(1, result.get(0).getLongValue());
}
use of com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean in project sidewinder by srotya.
the class TestChainFunction method testSingleFunction.
@Test
public void testSingleFunction() throws Exception {
SeriesOutput series = new SeriesOutput("cpu", "test", Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("1").build(), Tag.newBuilder().setTagKey("t").setTagValue("2").build()));
List<DataPoint> dps = new ArrayList<>();
long baseTs = 1486617103629L;
for (int i = 0; i < 4; i++) {
dps.add(new DataPoint(baseTs + 30_000 * i, 1));
}
series.setDataPoints(dps);
series.setFp(false);
List<SeriesOutput> seriesList = Arrays.asList(series);
ChainFunction cf = new ChainFunction();
WindowedAggregator rwa = new WindowedMean();
rwa.init(new Object[] { 70, "smean" });
cf.init(new Function[] { rwa });
List<SeriesOutput> apply = cf.apply(seriesList);
List<DataPoint> result = apply.get(0).getDataPoints();
assertEquals(2, result.size());
}
Aggregations