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