Search in sources :

Example 31 with Period

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));
}
Also used : Group(com.axibase.tsd.api.model.series.query.transformation.group.Group) SeriesQuery(com.axibase.tsd.api.model.series.query.SeriesQuery) Period(com.axibase.tsd.api.model.Period) Aggregate(com.axibase.tsd.api.model.series.query.transformation.aggregate.Aggregate) Issue(io.qameta.allure.Issue) Test(org.testng.annotations.Test)

Example 32 with Period

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));
}
Also used : Group(com.axibase.tsd.api.model.series.query.transformation.group.Group) SeriesQuery(com.axibase.tsd.api.model.series.query.SeriesQuery) Period(com.axibase.tsd.api.model.Period) Aggregate(com.axibase.tsd.api.model.series.query.transformation.aggregate.Aggregate) Issue(io.qameta.allure.Issue) Test(org.testng.annotations.Test)

Example 33 with Period

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;
}
Also used : ArrayList(java.util.ArrayList) Period(com.axibase.tsd.api.model.Period) ArrayList(java.util.ArrayList) List(java.util.List) Aggregate(com.axibase.tsd.api.model.series.query.transformation.aggregate.Aggregate) AggregationInterpolate(com.axibase.tsd.api.model.series.query.transformation.AggregationInterpolate) AggregationType(com.axibase.tsd.api.model.series.query.transformation.aggregate.AggregationType)

Example 34 with Period

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());
}
Also used : Series(com.axibase.tsd.api.model.series.Series) SeriesQuery(com.axibase.tsd.api.model.series.query.SeriesQuery) Period(com.axibase.tsd.api.model.Period) Metric(com.axibase.tsd.api.model.metric.Metric) Aggregate(com.axibase.tsd.api.model.series.query.transformation.aggregate.Aggregate) BigDecimal(java.math.BigDecimal) Issue(io.qameta.allure.Issue) Test(org.testng.annotations.Test)

Example 35 with Period

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());
}
Also used : Series(com.axibase.tsd.api.model.series.Series) SeriesQuery(com.axibase.tsd.api.model.series.query.SeriesQuery) ZonedDateTime(java.time.ZonedDateTime) Period(com.axibase.tsd.api.model.Period) Metric(com.axibase.tsd.api.model.metric.Metric) Aggregate(com.axibase.tsd.api.model.series.query.transformation.aggregate.Aggregate) BigDecimal(java.math.BigDecimal) Issue(io.qameta.allure.Issue) Test(org.testng.annotations.Test)

Aggregations

Period (com.axibase.tsd.api.model.Period)63 Test (org.testng.annotations.Test)48 Issue (io.qameta.allure.Issue)44 SeriesQuery (com.axibase.tsd.api.model.series.query.SeriesQuery)39 Aggregate (com.axibase.tsd.api.model.series.query.transformation.aggregate.Aggregate)30 BigDecimal (java.math.BigDecimal)24 Group (com.axibase.tsd.api.model.series.query.transformation.group.Group)16 Series (com.axibase.tsd.api.model.series.Series)14 Rate (com.axibase.tsd.api.model.series.query.transformation.rate.Rate)11 AggregationInterpolate (com.axibase.tsd.api.model.series.query.transformation.AggregationInterpolate)10 PropertyQuery (com.axibase.tsd.api.model.property.PropertyQuery)7 Property (com.axibase.tsd.api.model.property.Property)6 MessageQuery (com.axibase.tsd.api.model.message.MessageQuery)5 MessageQuerySizeCheck (com.axibase.tsd.api.method.checks.MessageQuerySizeCheck)4 Message (com.axibase.tsd.api.model.message.Message)4 AggregationType (com.axibase.tsd.api.model.series.query.transformation.aggregate.AggregationType)3 ArrayList (java.util.ArrayList)3 Response (javax.ws.rs.core.Response)3 DataProvider (org.testng.annotations.DataProvider)3 Metric (com.axibase.tsd.api.model.metric.Metric)2