Search in sources :

Example 21 with Series

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

the class TestTransformFunctions method testSquareRoot.

@Test
public void testSquareRoot() {
    Function f = new SqrtFunction();
    List<Series> series = new ArrayList<>();
    Series s = new Series(Arrays.asList(new DataPoint(1L, 9), new DataPoint(1L, 16)));
    series.add(s);
    List<Series> apply = f.apply(series);
    assertEquals(2, apply.get(0).getDataPoints().size());
    assertEquals(3, apply.get(0).getDataPoints().get(0).getLongValue());
    assertEquals(4, apply.get(0).getDataPoints().get(1).getLongValue());
}
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 22 with Series

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

the class TestWindowedFunctions method testDerivativeAggregator.

@Test
public void testDerivativeAggregator() throws Exception {
    double[] values = { 1.1, 2.2, 3.3, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = 1486617103629L;
    for (int i = 0; i < values.length; i++) {
        double d = values[i];
        ts = ts + (30_000);
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    ReducingWindowedAggregator rwa = new DerivativeFunction();
    rwa.init(new Object[] { 70, "smean" });
    Series series = new Series();
    series.setDataPoints(dps);
    series.setFp(true);
    List<DataPoint> result = rwa.apply(series).getDataPoints();
    // 1.65 and 3.85
    assertEquals(1, result.size());
    assertEquals(0.00003666666667 * 1000, result.get(0).getValue(), 0.01);
    System.out.println(result.get(0).getValue() * 1000 + "\t" + ts);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ReducingWindowedAggregator(com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 23 with Series

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

the class TestWindowedFunctions method testWindowedMean.

@Test
public void testWindowedMean() throws Exception {
    double[] values = { 1.1, 2.2, 3.3, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = 1486617103629L;
    for (int i = 0; i < values.length; i++) {
        double d = values[i];
        ts = ts + (30_000);
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    ReducingWindowedAggregator rwa = new WindowedMean();
    rwa.init(new Object[] { 70, "smean" });
    Series series = new Series();
    series.setDataPoints(dps);
    series.setFp(true);
    List<DataPoint> result = rwa.apply(series).getDataPoints();
    assertEquals(2, result.size());
    assertEquals(1.1, result.get(0).getValue(), 0);
    assertEquals(3.3, result.get(1).getValue(), 0.001);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ReducingWindowedAggregator(com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 24 with Series

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

the class TestWindowedFunctions method testWindowedFirst.

@Test
public void testWindowedFirst() throws Exception {
    double[] values = { 1.1, 3.3, 2.2, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = 1486617103629L;
    for (int i = 0; i < values.length; i++) {
        double d = values[i];
        ts = ts + (30_000);
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    ReducingWindowedAggregator rwa = new WindowedFirst();
    rwa.init(new Object[] { 70, "smean" });
    Series series = new Series();
    series.setDataPoints(dps);
    series.setFp(true);
    List<DataPoint> result = rwa.apply(series).getDataPoints();
    assertEquals(2, result.size());
    assertEquals(1.1, result.get(0).getValue(), 0);
    assertEquals(3.3, result.get(1).getValue(), 0);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ReducingWindowedAggregator(com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 25 with Series

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

the class TestWindowedFunctions method testDerivativeAggregator2.

@Test
public void testDerivativeAggregator2() throws Exception {
    long[] values = { 1, 4, 1, 4, 1 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = 1486617103629L;
    for (int i = 0; i < values.length; i++) {
        long d = values[i];
        ts = ts + (10_000);
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    ReducingWindowedAggregator rwa = new DerivativeFunction();
    rwa.init(new Object[] { 20, "smean" });
    Series series = new Series();
    series.setDataPoints(dps);
    series.setFp(false);
    Series result = rwa.apply(series);
    assertEquals(1, result.getDataPoints().size());
    assertEquals(false, result.isFp());
    assertEquals(0, result.getDataPoints().get(0).getValue() * 1000, 0.01);
    System.out.println(result.getDataPoints().get(0).getValue() * 1000 + "\t" + ts);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ReducingWindowedAggregator(com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) 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