Search in sources :

Example 51 with Series

use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.

the class TestChainFunction method testSingleFunction.

@Test
public void testSingleFunction() 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" });
    cf.init(new Function[] { rwa });
    List<Series> apply = cf.apply(seriesList);
    List<DataPoint> result = apply.get(0).getDataPoints();
    assertEquals(2, result.size());
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ReducingWindowedAggregator(com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ChainFunction(com.srotya.sidewinder.core.functions.multiseries.ChainFunction) ArrayList(java.util.ArrayList) Tag(com.srotya.sidewinder.core.filters.Tag) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 52 with Series

use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.

the class TestSingleValueAggregators method testMaxFunction.

@Test
public void testMaxFunction() {
    MaxFunction f = new MaxFunction();
    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.setFp(true);
    Series result = f.apply(series);
    assertEquals(4.4, result.getDataPoints().get(0).getValue(), 0);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 53 with Series

use of com.srotya.sidewinder.core.storage.Series 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)

Example 54 with Series

use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.

the class TestSingleValueAggregators method testFirstFunction.

@Test
public void testFirstFunction() {
    FirstFunction f = new FirstFunction();
    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(2.2, result.getDataPoints().get(0).getValue(), 0);
// List<long[]> data = new ArrayList<>();
// for(double d:values) {
// data.add(new long[] {ts, Double.doubleToLongBits(d)});
// }
// List<long[]> aggregatePoints = f.aggregatePoints(data, true);
// assertEquals(1, aggregatePoints.size());
// assertEquals(2.2, Double.longBitsToDouble(aggregatePoints.get(0)[1]), 0);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 55 with Series

use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.

the class TestSingleValueAggregators method testLastFunction.

@Test
public void testLastFunction() {
    LastFunction f = new LastFunction();
    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(4.4, result.getDataPoints().get(0).getValue(), 0);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Series (com.srotya.sidewinder.core.storage.Series)56 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)49 Test (org.junit.Test)47 ArrayList (java.util.ArrayList)37 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)21 IOException (java.io.IOException)18 LinkedHashMap (java.util.LinkedHashMap)16 HashMap (java.util.HashMap)15 Point (com.srotya.sidewinder.core.rpc.Point)13 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)13 File (java.io.File)13 ReducingWindowedAggregator (com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator)10 RejectException (com.srotya.sidewinder.core.storage.RejectException)10 StorageEngine (com.srotya.sidewinder.core.storage.StorageEngine)7 List (java.util.List)7 ByzantineWriter (com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter)6 Tag (com.srotya.sidewinder.core.filters.Tag)5 SimpleTagFilter (com.srotya.sidewinder.core.filters.SimpleTagFilter)4 Measurement (com.srotya.sidewinder.core.storage.Measurement)4 WriterServiceBlockingStub (com.srotya.sidewinder.core.rpc.WriterServiceGrpc.WriterServiceBlockingStub)3