Search in sources :

Example 6 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput 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 7 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput 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 8 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.

the class TestSingleValueAggregators method testMinFunction.

@Test
public void testMinFunction() {
    MinFunction f = new MinFunction();
    double[] values = { 2.2, 1.1, 3.3, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = System.currentTimeMillis();
    for (double d : values) {
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    SeriesOutput series = new SeriesOutput();
    series.setDataPoints(dps);
    SeriesOutput result = f.apply(series);
    assertEquals(1.1, result.getDataPoints().get(0).getValue(), 0);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) Test(org.junit.Test)

Example 9 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.

the class TestSingleValueAggregators method testMeanAggregator.

@Test
public void testMeanAggregator() {
    double[] values = { 2.2, 1.1, 3.3, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = System.currentTimeMillis();
    for (double d : values) {
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    ReduceFunction sva = new MeanFunction();
    SeriesOutput series = new SeriesOutput();
    series.setFp(true);
    series.setDataPoints(dps);
    SeriesOutput result = sva.apply(series);
    assertEquals(2.75, result.getDataPoints().get(0).getValue(), 0.01);
    dps.clear();
    long[] vals = { 1, 2, 3, 4, 5 };
    for (long l : vals) {
        dps.add(MiscUtils.buildDataPoint(ts, l));
    }
    series.setFp(false);
    for (int p = 0; p < 1000; p++) {
        result = sva.apply(series);
    }
    assertEquals(3, result.getDataPoints().get(0).getLongValue(), 0.01);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) ReduceFunction(com.srotya.sidewinder.core.functions.list.ReduceFunction) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 10 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.

the class TestSingleValueAggregators method testLastFunctionLong.

@Test
public void testLastFunctionLong() {
    LastFunction f = new LastFunction();
    long[] values = { 2, 1, 3, 4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = System.currentTimeMillis();
    for (long d : values) {
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    SeriesOutput series = new SeriesOutput();
    series.setDataPoints(dps);
    SeriesOutput result = f.apply(series);
    assertEquals(4, result.getDataPoints().get(0).getLongValue());
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) Test(org.junit.Test)

Aggregations

SeriesOutput (com.srotya.sidewinder.core.storage.SeriesOutput)40 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)35 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)31 WindowedAggregator (com.srotya.sidewinder.core.functions.list.WindowedAggregator)10 Function (com.srotya.sidewinder.core.functions.list.Function)7 IOException (java.io.IOException)6 TagFilter (com.srotya.sidewinder.core.filters.TagFilter)4 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)4 Tag (com.srotya.sidewinder.core.rpc.Tag)3 WriterServiceBlockingStub (com.srotya.sidewinder.core.rpc.WriterServiceGrpc.WriterServiceBlockingStub)3 BadRequestException (javax.ws.rs.BadRequestException)3 NotFoundException (javax.ws.rs.NotFoundException)3 WindowedMean (com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean)2 ChainFunction (com.srotya.sidewinder.core.functions.list.ChainFunction)2 ReduceFunction (com.srotya.sidewinder.core.functions.list.ReduceFunction)2 Point (com.srotya.sidewinder.core.rpc.Point)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 List (java.util.List)2