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