Search in sources :

Example 1 with WindowedMean

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());
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ChainFunction(com.srotya.sidewinder.core.functions.list.ChainFunction) ArrayList(java.util.ArrayList) WindowedAggregator(com.srotya.sidewinder.core.functions.list.WindowedAggregator) WindowedMean(com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 2 with WindowedMean

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());
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ChainFunction(com.srotya.sidewinder.core.functions.list.ChainFunction) ArrayList(java.util.ArrayList) WindowedAggregator(com.srotya.sidewinder.core.functions.list.WindowedAggregator) WindowedMean(com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Aggregations

WindowedMean (com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean)2 ChainFunction (com.srotya.sidewinder.core.functions.list.ChainFunction)2 WindowedAggregator (com.srotya.sidewinder.core.functions.list.WindowedAggregator)2 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)2 SeriesOutput (com.srotya.sidewinder.core.storage.SeriesOutput)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2