Search in sources :

Example 11 with DataPoint

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

the class ReducingWindowedAggregator method apply.

@Override
public final List<DataPoint> apply(SortedMap<Long, List<DataPoint>> map, boolean isFp) {
    List<DataPoint> reducedDataPoints = new ArrayList<>();
    for (Entry<Long, List<DataPoint>> entry : map.entrySet()) {
        DataPoint aggregate = new DataPoint();
        aggregator.aggregateToSingle(entry.getValue(), aggregate, isFp);
        aggregate.setTimestamp(entry.getKey());
        reducedDataPoints.add(aggregate);
    }
    if (reducedDataPoints.size() > 0) {
        return aggregateAfterReduction(reducedDataPoints, isFp);
    } else {
        return reducedDataPoints;
    }
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with DataPoint

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

the class WindowedFunction method apply.

@Override
public Series apply(Series t) {
    Series output = new Series(t.getMeasurementName(), t.getValueFieldName(), t.getTags());
    output.setFp(t.isFp());
    SortedMap<Long, List<DataPoint>> map = new TreeMap<>();
    for (DataPoint dataPoint : t.getDataPoints()) {
        try {
            long bucket = (dataPoint.getTimestamp() / getTimeWindow()) * getTimeWindow();
            List<DataPoint> list = map.get(bucket);
            if (list == null) {
                list = new ArrayList<>();
                map.put(bucket, list);
            }
            list.add(dataPoint);
        } catch (Exception e) {
            System.err.println("Exception :" + getTimeWindow());
        }
    }
    output.setDataPoints(apply(map, t.isFp()));
    return output;
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 13 with DataPoint

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

the class SignalProcessingFunctions method dpListToArray.

public static double[] dpListToArray(List<DataPoint> dp, boolean isFp) {
    int len = nextPowerOf2(dp.size());
    double[] ary = new double[(int) Math.pow(2, len)];
    for (int i = 0; i < dp.size(); i++) {
        DataPoint dataPoint = dp.get(i);
        if (isFp) {
            ary[i] = dataPoint.getValue();
        } else {
            ary[i] = dataPoint.getLongValue();
        }
    }
    return ary;
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) DataPoint(com.srotya.sidewinder.core.storage.DataPoint)

Example 14 with DataPoint

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

the class TestByzantineReadWrite method testPredicateFilter.

@Test
public void testPredicateFilter() throws IOException {
    ByteBuffer buf = ByteBuffer.allocateDirect(1024 * 1024 * 10);
    ByzantineWriter writer = new ByzantineWriter();
    writer.configure(new HashMap<>(), buf, true, startOffset, true);
    long ots = System.currentTimeMillis();
    writer.setHeaderTimestamp(ots);
    int limit = 1_000_000;
    for (int i = 0; i < limit; i++) {
        writer.addValue(ots + i * 1000, i);
    }
    Reader reader = writer.getReader();
    reader.setTimePredicate(new GreaterThanEqualsPredicate(ots + 1000));
    int c = 0;
    assertEquals(limit, reader.getPairCount());
    try {
        for (int i = 0; i < limit; i++) {
            DataPoint pair = reader.readPair();
            if (pair != null) {
                assertEquals(ots + i * 1000, pair.getTimestamp());
                assertEquals(i, pair.getLongValue());
                c++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    assertEquals(limit - 1, c);
    reader = writer.getReader();
    reader.setValuePredicate(new GreaterThanEqualsPredicate(1000));
    c = 0;
    assertEquals(limit, reader.getPairCount());
    try {
        for (int i = 0; i < limit; i++) {
            DataPoint pair = reader.readPair();
            if (pair != null) {
                assertEquals(ots + i * 1000, pair.getTimestamp());
                assertEquals(i, pair.getLongValue());
                c++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    try {
        reader.readPair();
        fail("Must throw end of stream exception");
    } catch (RejectException e) {
    }
    try {
        reader.read();
        fail("Must throw end of stream exception");
    } catch (RejectException e) {
    }
    assertEquals(limit - 1000, c);
    assertEquals(limit, reader.getCounter());
    reader = writer.getReader();
    reader.setTimePredicate(new GreaterThanEqualsPredicate(ots + 1000));
    c = 0;
    assertEquals(limit, reader.getPairCount());
    try {
        for (int i = 0; i < limit; i++) {
            long[] pair = reader.read();
            if (pair != null) {
                assertEquals(ots + i * 1000, pair[0]);
                assertEquals(i, pair[1]);
                c++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    assertEquals(limit - 1, c);
    reader = writer.getReader();
    reader.setValuePredicate(new GreaterThanEqualsPredicate(1000));
    c = 0;
    assertEquals(limit, reader.getPairCount());
    try {
        for (int i = 0; i < limit; i++) {
            long[] pair = reader.read();
            if (pair != null) {
                assertEquals(ots + i * 1000, pair[0]);
                assertEquals(i, pair[1]);
                c++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    assertEquals(limit - 1000, c);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Reader(com.srotya.sidewinder.core.storage.compression.Reader) RejectException(com.srotya.sidewinder.core.storage.RejectException) GreaterThanEqualsPredicate(com.srotya.sidewinder.core.predicates.GreaterThanEqualsPredicate) ByteBuffer(java.nio.ByteBuffer) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) IOException(java.io.IOException) RejectException(com.srotya.sidewinder.core.storage.RejectException) RollOverException(com.srotya.sidewinder.core.storage.compression.RollOverException) Test(org.junit.Test)

Example 15 with DataPoint

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

the class TestByzantineReadWrite method testReadWriteDataPoints.

@Test
public void testReadWriteDataPoints() throws IOException {
    ByteBuffer buf = ByteBuffer.allocateDirect(1024);
    Writer writer = new ByzantineWriter();
    writer.configure(new HashMap<>(), buf, true, startOffset, false);
    long ts = System.currentTimeMillis();
    writer.setHeaderTimestamp(ts);
    for (int i = 0; i < 100; i++) {
        writer.addValue(ts + i * 10, i);
    }
    Reader reader = writer.getReader();
    for (int i = 0; i < 100; i++) {
        DataPoint pair = reader.readPair();
        assertEquals(ts + i * 10, pair.getTimestamp());
        assertEquals(i, pair.getLongValue());
    }
    for (int i = 0; i < 100; i++) {
        DataPoint dp = new DataPoint(1000 + ts + i * 10, i);
        writer.write(dp);
    }
    reader = writer.getReader();
    for (int i = 0; i < 200; i++) {
        DataPoint pair = reader.readPair();
        assertEquals(ts + i * 10, pair.getTimestamp());
        assertEquals(i % 100, pair.getLongValue());
    }
    System.out.println("Compression Ratio:" + writer.getCompressionRatio());
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Reader(com.srotya.sidewinder.core.storage.compression.Reader) ByteBuffer(java.nio.ByteBuffer) Writer(com.srotya.sidewinder.core.storage.compression.Writer) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Aggregations

DataPoint (com.srotya.sidewinder.core.storage.DataPoint)67 Test (org.junit.Test)52 Series (com.srotya.sidewinder.core.storage.Series)40 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)16 Reader (com.srotya.sidewinder.core.storage.compression.Reader)13 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)12 ByteBuffer (java.nio.ByteBuffer)11 ReducingWindowedAggregator (com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator)10 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)10 RejectException (com.srotya.sidewinder.core.storage.RejectException)9 File (java.io.File)9 Point (com.srotya.sidewinder.core.rpc.Point)8 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)8 List (java.util.List)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Tag (com.srotya.sidewinder.core.filters.Tag)5 Writer (com.srotya.sidewinder.core.storage.compression.Writer)5 ByzantineWriter (com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter)4