Search in sources :

Example 1 with ReduceFunction

use of com.srotya.sidewinder.core.functions.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();
    Series series = new Series();
    series.setFp(true);
    series.setDataPoints(dps);
    Series 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 : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) ReduceFunction(com.srotya.sidewinder.core.functions.ReduceFunction) Test(org.junit.Test)

Example 2 with ReduceFunction

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

the class ReducingWindowedAggregator method init.

@Override
public void init(Object[] args) throws Exception {
    super.init(args);
    String aggregatorName = "smean";
    if (args.length > 1) {
        aggregatorName = args[1].toString();
    }
    @SuppressWarnings("unchecked") Class<ReduceFunction> lookupFunction = (Class<ReduceFunction>) FunctionTable.get().lookupFunction(aggregatorName);
    if (lookupFunction == null) {
        throw new IllegalArgumentException("Invalid aggregation function:" + aggregatorName);
    }
    try {
        ReduceFunction tmp = lookupFunction.newInstance();
        this.aggregator = (ReduceFunction) tmp;
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("Invalid aggregation function:" + aggregatorName);
    }
}
Also used : ReduceFunction(com.srotya.sidewinder.core.functions.ReduceFunction)

Example 3 with ReduceFunction

use of com.srotya.sidewinder.core.functions.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();
    Series series = new Series();
    series.setFp(true);
    series.setDataPoints(dps);
    Series 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);
    result = sva.apply(series);
    assertEquals(3, result.getDataPoints().get(0).getLongValue(), 0.01);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) ReduceFunction(com.srotya.sidewinder.core.functions.ReduceFunction) Test(org.junit.Test)

Aggregations

ReduceFunction (com.srotya.sidewinder.core.functions.ReduceFunction)3 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)2 Series (com.srotya.sidewinder.core.storage.Series)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2