Search in sources :

Example 1 with WindowedAggregator

use of com.srotya.sidewinder.core.functions.list.WindowedAggregator 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 WindowedAggregator

use of com.srotya.sidewinder.core.functions.list.WindowedAggregator 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)

Example 3 with WindowedAggregator

use of com.srotya.sidewinder.core.functions.list.WindowedAggregator in project sidewinder by srotya.

the class TestWindowedFunctions method testWindowedFirst.

@Test
public void testWindowedFirst() throws Exception {
    double[] values = { 1.1, 3.3, 2.2, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = 1486617103629L;
    for (int i = 0; i < values.length; i++) {
        double d = values[i];
        ts = ts + (30_000);
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    WindowedAggregator rwa = new WindowedFirst();
    rwa.init(new Object[] { 70, "smean" });
    SeriesOutput series = new SeriesOutput();
    series.setDataPoints(dps);
    series.setFp(true);
    List<DataPoint> result = rwa.apply(series).getDataPoints();
    assertEquals(2, result.size());
    assertEquals(1.1, result.get(0).getValue(), 0);
    assertEquals(3.3, result.get(1).getValue(), 0);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) WindowedAggregator(com.srotya.sidewinder.core.functions.list.WindowedAggregator) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 4 with WindowedAggregator

use of com.srotya.sidewinder.core.functions.list.WindowedAggregator in project sidewinder by srotya.

the class TestWindowedFunctions method testWindowedMean.

@Test
public void testWindowedMean() throws Exception {
    double[] values = { 1.1, 2.2, 3.3, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = 1486617103629L;
    for (int i = 0; i < values.length; i++) {
        double d = values[i];
        ts = ts + (30_000);
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    WindowedAggregator rwa = new WindowedMean();
    rwa.init(new Object[] { 70, "smean" });
    SeriesOutput series = new SeriesOutput();
    series.setDataPoints(dps);
    series.setFp(true);
    List<DataPoint> result = rwa.apply(series).getDataPoints();
    assertEquals(2, result.size());
    assertEquals(1.1, result.get(0).getValue(), 0);
    assertEquals(3.3, result.get(1).getValue(), 0.001);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) WindowedAggregator(com.srotya.sidewinder.core.functions.list.WindowedAggregator) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 5 with WindowedAggregator

use of com.srotya.sidewinder.core.functions.list.WindowedAggregator in project sidewinder by srotya.

the class TestWindowedFunctions method testDerivativeAggregator2.

@Test
public void testDerivativeAggregator2() throws Exception {
    long[] values = { 1, 4, 1, 4, 1 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = 1486617103629L;
    for (int i = 0; i < values.length; i++) {
        long d = values[i];
        ts = ts + (10_000);
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    WindowedAggregator rwa = new DerivativeFunction();
    rwa.init(new Object[] { 20, "smean" });
    SeriesOutput series = new SeriesOutput();
    series.setDataPoints(dps);
    series.setFp(false);
    SeriesOutput result = rwa.apply(series);
    assertEquals(1, result.getDataPoints().size());
    assertEquals(false, result.isFp());
    assertEquals(0, result.getDataPoints().get(0).getValue() * 1000, 0.01);
    System.out.println(result.getDataPoints().get(0).getValue() * 1000 + "\t" + ts);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) WindowedAggregator(com.srotya.sidewinder.core.functions.list.WindowedAggregator) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Aggregations

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