Search in sources :

Example 6 with DataPoint

use of com.srotya.sidewinder.core.storage.DataPoint 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);
}
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 7 with DataPoint

use of com.srotya.sidewinder.core.storage.DataPoint 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);
}
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 8 with DataPoint

use of com.srotya.sidewinder.core.storage.DataPoint 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());
}
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 9 with DataPoint

use of com.srotya.sidewinder.core.storage.DataPoint 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());
}
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 10 with DataPoint

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

the class MeasurementOpsApi method getSeries.

public List<Number[]> getSeries(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, @PathParam(MEASUREMENT) String measurementName, @QueryParam("field") String valueFieldName, @DefaultValue("now-1h") @QueryParam(START_TIME) String startTime, @QueryParam(END_TIME) String endTime) {
    if (valueFieldName == null) {
        throw new BadRequestException("Must specify a value field");
    }
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long endTs = System.currentTimeMillis();
        long startTs = endTs;
        if (startTime.contains("now")) {
            String[] split = startTime.split("-");
            int offset = Integer.parseInt(split[1].charAt(0) + "");
            startTs = startTs - (offset * 3600 * 1000);
        } else {
            startTs = sdf.parse(startTime).getTime();
            endTs = sdf.parse(endTime).getTime();
        }
        List<Series> points = engine.queryDataPoints(dbName, measurementName, valueFieldName, startTs, endTs, null);
        List<Number[]> response = new ArrayList<>();
        for (Series entry : points) {
            for (DataPoint dataPoint : entry.getDataPoints()) {
                if (entry.isFp()) {
                    response.add(new Number[] { dataPoint.getLongValue(), dataPoint.getTimestamp() });
                } else {
                    response.add(new Number[] { dataPoint.getValue(), dataPoint.getTimestamp() });
                }
            }
        }
        return response;
    } catch (ItemNotFoundException e) {
        throw new NotFoundException(e);
    } catch (Exception e) {
        throw new InternalServerErrorException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) BadRequestException(javax.ws.rs.BadRequestException) IOException(java.io.IOException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) SimpleDateFormat(java.text.SimpleDateFormat) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException)

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