use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.
the class TestChainFunction method testTwoFunctions.
@Test
public void testTwoFunctions() throws Exception {
Series series = new Series("cpu", "test", Arrays.asList(new Tag("t", "1"), new Tag("t", "2")));
List<DataPoint> dps = new ArrayList<>();
long baseTs = 1486617103629L;
for (int i = 0; i < 4; i++) {
dps.add(new DataPoint(baseTs + 30_000 * i, 1));
}
series.setDataPoints(dps);
series.setFp(false);
List<Series> seriesList = Arrays.asList(series);
ChainFunction cf = new ChainFunction();
ReducingWindowedAggregator rwa = new WindowedMean();
rwa.init(new Object[] { 70, "smean" });
ReducingWindowedAggregator rwa2 = new WindowedMean();
rwa2.init(new Object[] { 200, "smean" });
cf.init(new Function[] { rwa, rwa2 });
List<Series> apply = cf.apply(seriesList);
List<DataPoint> result = apply.get(0).getDataPoints();
assertEquals(1, result.size());
assertEquals(1, result.get(0).getLongValue());
}
use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.
the class TestSingleValueAggregators method testMinFunction.
@Test
public void testMinFunction() {
MinFunction f = new MinFunction();
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));
}
Series series = new Series();
series.setDataPoints(dps);
Series result = f.apply(series);
assertEquals(1.1, result.getDataPoints().get(0).getValue(), 0);
}
use of com.srotya.sidewinder.core.storage.Series 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.storage.Series in project sidewinder by srotya.
the class TestSingleValueAggregators method testLastFunctionLong.
@Test
public void testLastFunctionLong() {
LastFunction f = new LastFunction();
long[] values = { 2, 1, 3, 4 };
List<DataPoint> dps = new ArrayList<>();
long ts = System.currentTimeMillis();
for (long d : values) {
dps.add(MiscUtils.buildDataPoint(ts, d));
}
Series series = new Series();
series.setDataPoints(dps);
Series result = f.apply(series);
assertEquals(4, result.getDataPoints().get(0).getLongValue());
}
use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.
the class TestSingleValueAggregators method testMinFunctionLong.
@Test
public void testMinFunctionLong() {
MinFunction f = new MinFunction();
long[] values = { 2, 1, 3, 4 };
List<DataPoint> dps = new ArrayList<>();
long ts = System.currentTimeMillis();
for (long d : values) {
dps.add(MiscUtils.buildDataPoint(ts, d));
}
Series series = new Series();
series.setDataPoints(dps);
Series result = f.apply(series);
assertEquals(1, result.getDataPoints().get(0).getLongValue());
}
Aggregations