Search in sources :

Example 6 with WindowedAggregator

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

the class TestWindowedFunctions method testWindowedLast.

@Test
public void testWindowedLast() 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 WindowedLast();
    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 7 with WindowedAggregator

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

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

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

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

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