Search in sources :

Example 1 with ReduceFunction

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

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

the class TestSingleValueAggregators method testSumAggregator.

@Test
public void testSumAggregator() {
    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 SumFunction();
    SeriesOutput series = new SeriesOutput();
    series.setFp(true);
    series.setDataPoints(dps);
    SeriesOutput result = sva.apply(series);
    assertEquals(11, 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);
    result = sva.apply(series);
    assertEquals(15, 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) Test(org.junit.Test)

Aggregations

ReduceFunction (com.srotya.sidewinder.core.functions.list.ReduceFunction)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