use of com.axibase.tsd.api.model.Period in project atsd-api-test by axibase.
the class SeriesQueryGroupExampleTest method testExampleSumGroupToAggregation.
@Issue("2995")
@Test(description = "https://github.com/axibase/atsd-docs/blob/master/api/data/series/group.md#group-aggregation")
public void testExampleSumGroupToAggregation() throws Exception {
SeriesQuery query = prepareDefaultQuery("2016-06-25T08:00:00Z", "2016-06-25T08:01:00Z");
query.setGroup(new Group(GroupType.SUM, new Period(1, TimeUnit.MILLISECOND), 0));
query.setAggregate(new Aggregate(AggregationType.COUNT, new Period(10, TimeUnit.SECOND), 1));
List<Sample> expectedSamples = Arrays.asList(Sample.ofDateInteger("2016-06-25T08:00:00.000Z", 2), Sample.ofDateInteger("2016-06-25T08:00:10.000Z", 2), Sample.ofDateInteger("2016-06-25T08:00:30.000Z", 1), Sample.ofDateInteger("2016-06-25T08:00:40.000Z", 1), Sample.ofDateInteger("2016-06-25T08:00:50.000Z", 1));
List<Series> groupedSeries = querySeriesAsList(query);
assertEquals("Response should contain only one series", 1, groupedSeries.size());
List<Sample> givenSamples = groupedSeries.get(0).getData();
final String actual = jacksonMapper.writeValueAsString(givenSamples);
final String expected = jacksonMapper.writeValueAsString(expectedSamples);
assertTrue("Grouped series do not match to expected", compareJsonString(expected, actual));
}
use of com.axibase.tsd.api.model.Period in project atsd-api-test by axibase.
the class SeriesQueryGroupExampleTest method testExampleSumGroupAggregation.
@Issue("2995")
@Test(description = "https://github.com/axibase/atsd-docs/blob/master/api/data/series/group.md#group-aggregation")
public void testExampleSumGroupAggregation() throws Exception {
final Period period = new Period(10, TimeUnit.SECOND);
SeriesQuery query = prepareDefaultQuery("2016-06-25T08:00:00Z", "2016-06-25T08:01:00Z");
query.setGroup(new Group(GroupType.SUM, period));
query.setAggregate(new Aggregate(AggregationType.SUM, period));
List<Sample> expectedSamples = Arrays.asList(Sample.ofDateInteger("2016-06-25T08:00:00.000Z", 15), Sample.ofDateInteger("2016-06-25T08:00:10.000Z", 21), Sample.ofDateInteger("2016-06-25T08:00:30.000Z", 16), Sample.ofDateInteger("2016-06-25T08:00:40.000Z", 20), Sample.ofDateInteger("2016-06-25T08:00:50.000Z", 19));
List<Series> groupedSeries = querySeriesAsList(query);
assertEquals("Response should contain only one series", 1, groupedSeries.size());
List<Sample> givenSamples = groupedSeries.get(0).getData();
final String actual = jacksonMapper.writeValueAsString(givenSamples);
final String expected = jacksonMapper.writeValueAsString(expectedSamples);
assertTrue("Grouped series do not match to expected", compareJsonString(expected, actual));
}
use of com.axibase.tsd.api.model.Period in project atsd-api-test by axibase.
the class SeriesQueryTransformationWithDifferentForecastTest method generateAggregationSet.
private List<Aggregate> generateAggregationSet() {
List<Aggregate> aggregates = new ArrayList<>();
List<List<AggregationType>> setsAggregationType = Arrays.asList(Arrays.asList(AggregationType.AVG, AggregationType.SUM, AggregationType.FIRST), Arrays.asList(AggregationType.AVG, AggregationType.SUM, AggregationType.FIRST, AggregationType.DETAIL));
Period period = new Period(AGGREGATION_PERIOD_COUNT, TimeUnit.MINUTE, PeriodAlignment.START_TIME);
AggregationInterpolate interp = new AggregationInterpolate(AggregationInterpolateType.LINEAR, true);
for (List<AggregationType> setAggregationType : setsAggregationType) {
aggregates.add(new Aggregate().setPeriod(period).setInterpolate(interp).setTypes(setAggregationType));
}
return aggregates;
}
use of com.axibase.tsd.api.model.Period in project atsd-api-test by axibase.
the class SeriesInsertTest method testDoubleAggregatePrecision.
@Issue("2871")
@Test
public void testDoubleAggregatePrecision() throws Exception {
String entityName = "e-double-3";
String metricName = "m-double-3";
BigDecimal number = new BigDecimal("0.6083333332");
final long t = MILLS_TIME;
Metric metric = new Metric(metricName);
metric.setDataType(DataType.DOUBLE);
MetricMethod.createOrReplaceMetricCheck(metric);
Series series = new Series(entityName, null);
series.setMetric(metricName);
for (int i = 0; i < 12; i++) {
String isoDate = Util.ISOFormat(t + i * 5000);
series.addSamples(Sample.ofDateDecimal(isoDate, number));
}
assertSame("Failed to insert small decimal series", Response.Status.Family.SUCCESSFUL, Util.responseFamily(insertSeries(Collections.singletonList(series))));
assertSeriesExisting(series);
SeriesQuery seriesQuery = new SeriesQuery(series.getEntity(), series.getMetric(), t, t + 1 + 11 * 5000);
seriesQuery.setAggregate(new Aggregate(AggregationType.SUM, new Period(1, TimeUnit.MINUTE)));
List<Series> seriesList = querySeriesAsList(seriesQuery);
assertEquals("Stored small double value incorrect", new BigDecimal("7.299999998400001"), seriesList.get(0).getData().get(0).getValue());
}
use of com.axibase.tsd.api.model.Period in project atsd-api-test by axibase.
the class SeriesInsertTest method testBigDecimalAggregatePrecision.
@Issue("2871")
@Test
public void testBigDecimalAggregatePrecision() throws Exception {
String entityName = "e-decimal-2";
String metricName = "m-decimal-2";
BigDecimal number = new BigDecimal("0.6083333332");
ZonedDateTime dateTime = ZonedDateTime.parse(Mocks.ISO_TIME);
Metric metric = new Metric(metricName);
metric.setDataType(DataType.DECIMAL);
MetricMethod.createOrReplaceMetricCheck(metric);
Series series = new Series(entityName, null);
series.setMetric(metricName);
for (int i = 0; i < 12; i++) {
series.addSamples(Sample.ofDateDecimal(dateTime.plusSeconds(5 * i).toString(), number));
}
assertSame("Failed to insert small decimal series", Response.Status.Family.SUCCESSFUL, Util.responseFamily(insertSeries(Collections.singletonList(series))));
assertSeriesExisting(series);
SeriesQuery seriesQuery = new SeriesQuery(series.getEntity(), series.getMetric(), dateTime.format(DateTimeFormatter.ISO_INSTANT), dateTime.plusMinutes(1).format(DateTimeFormatter.ISO_INSTANT));
seriesQuery.setAggregate(new Aggregate(AggregationType.SUM, new Period(1, TimeUnit.MINUTE)));
List<Series> seriesList = querySeriesAsList(seriesQuery);
assertEquals("Stored small decimal value incorrect", new BigDecimal("7.2999999984"), seriesList.get(0).getData().get(0).getValue());
}
Aggregations