Search in sources :

Example 31 with SeriesOutput

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

the class TestWindowedFunctions method testWindowedMax.

@Test
public void testWindowedMax() 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 WindowedMax();
    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(4.4, 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 32 with SeriesOutput

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

the class TestWindowedFunctions method testWindowedMin.

@Test
public void testWindowedMin() 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 WindowedMin();
    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(2.2, 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 33 with SeriesOutput

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

the class TestWindowedFunctions method testDerivativeAggregator.

@Test
public void testDerivativeAggregator() 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 DerivativeFunction();
    rwa.init(new Object[] { 70, "smean" });
    SeriesOutput series = new SeriesOutput();
    series.setDataPoints(dps);
    series.setFp(true);
    List<DataPoint> result = rwa.apply(series).getDataPoints();
    // 1.65 and 3.85
    assertEquals(1, result.size());
    assertEquals(0.00003666666667 * 1000, result.get(0).getValue(), 0.01);
    System.out.println(result.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)

Example 34 with SeriesOutput

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

the class TestWindowedFunctions method testIntegralFunction.

@Test
public void testIntegralFunction() 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 IntegralFunction();
    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(9.9, 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 35 with SeriesOutput

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

the class TestTransformFunctions method testCubeRoot.

@Test
public void testCubeRoot() {
    Function f = new CbrtFunction();
    List<SeriesOutput> series = new ArrayList<>();
    SeriesOutput s = new SeriesOutput(Arrays.asList(new DataPoint(1L, 27), new DataPoint(1L, 64)));
    series.add(s);
    List<SeriesOutput> apply = f.apply(series);
    assertEquals(2, apply.get(0).getDataPoints().size());
    assertEquals(3, apply.get(0).getDataPoints().get(0).getLongValue());
    assertEquals(4, apply.get(0).getDataPoints().get(1).getLongValue());
}
Also used : Function(com.srotya.sidewinder.core.functions.list.Function) 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