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);
}
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);
}
}
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);
}
Aggregations