Search in sources :

Example 1 with TvpDataCollection

use of org.n52.io.TvpDataCollection in project series-rest-api by 52North.

the class DouglasPeuckerGeneralizer method generalize.

@Override
public DataCollection<QuantityData> generalize(DataCollection<QuantityData> data) throws GeneralizerException {
    TvpDataCollection<QuantityData> generalizedDataCollection = new TvpDataCollection<>();
    for (String timeseriesId : data.getAllSeries().keySet()) {
        QuantityData timeseries = data.getSeries(timeseriesId);
        generalizedDataCollection.addNewSeries(timeseriesId, generalize(timeseries));
    }
    return generalizedDataCollection;
}
Also used : TvpDataCollection(org.n52.io.series.TvpDataCollection) QuantityData(org.n52.io.response.dataset.quantity.QuantityData)

Example 2 with TvpDataCollection

use of org.n52.io.TvpDataCollection in project series-rest-api by 52North.

the class PDFReportGenerator method addDataTable.

private void addDataTable(TimeSeries timeseries, TimeseriesMetadataOutput metadata, TvpDataCollection<QuantityData> dataCollection) {
    TableType dataTable = timeseries.addNewTable();
    // TODO add language context
    dataTable.setLeftColHeader("Date");
    dataTable.setRightColHeader(createValueTableHeader(metadata));
    QuantityData data = dataCollection.getSeries(metadata.getId());
    for (QuantityValue valueEntry : data.getValues()) {
        Entry entry = dataTable.addNewEntry();
        // TODO update TableType schema to allow start/end time
        entry.setTime(new DateTime(valueEntry.getTimestamp()).toString());
        entry.setValue(Double.toString(valueEntry.getValue()));
    }
}
Also used : Entry(org.n52.oxf.TableType.Entry) TableType(org.n52.oxf.TableType) QuantityValue(org.n52.io.response.dataset.quantity.QuantityValue) QuantityData(org.n52.io.response.dataset.quantity.QuantityData) DateTime(org.joda.time.DateTime)

Example 3 with TvpDataCollection

use of org.n52.io.TvpDataCollection in project series-rest-api by 52North.

the class LargestTriangleThreeBucketsGeneralizerTest method when_quotientHasNonterminatingDecimals_then_noArithmeticExceptionIsThrown.

@Test
public void when_quotientHasNonterminatingDecimals_then_noArithmeticExceptionIsThrown() throws GeneralizerException {
    // https://github.com/52North/series-rest-api/issues/446
    TvpDataCollection<Data<QuantityValue>> collection = new TvpDataCollection<>();
    collection.addNewSeries("test", getData(10000));
    long threshold = 100L;
    IoParameters defaults = IoParameters.createDefaults().extendWith("threshold", Long.toString(threshold));
    Generalizer<Data<QuantityValue>> generalizer = new LargestTriangleThreeBucketsGeneralizer(defaults);
    DataCollection<Data<QuantityValue>> generalizedData = generalizer.generalize(collection);
    assertThat(generalizedData.getSeries("test").size(), Is.is(threshold));
}
Also used : TvpDataCollection(org.n52.io.TvpDataCollection) LargestTriangleThreeBucketsGeneralizer(org.n52.io.type.quantity.generalize.LargestTriangleThreeBucketsGeneralizer) Data(org.n52.io.response.dataset.Data) IoParameters(org.n52.io.request.IoParameters) Test(org.junit.jupiter.api.Test)

Example 4 with TvpDataCollection

use of org.n52.io.TvpDataCollection in project series-rest-api by 52North.

the class LargestTriangleThreeBucketsGeneralizer method generalize.

@Override
public DataCollection<QuantityData> generalize(DataCollection<QuantityData> data) throws GeneralizerException {
    TvpDataCollection<QuantityData> generalizedDataCollection = new TvpDataCollection<>();
    for (String timeseriesId : data.getAllSeries().keySet()) {
        QuantityData timeseries = data.getSeries(timeseriesId);
        QuantityData generalizedTimeseries = generalize(timeseries);
        generalizedTimeseries.setMetadata(timeseries.getMetadata());
        generalizedDataCollection.addNewSeries(timeseriesId, generalizedTimeseries);
    }
    return generalizedDataCollection;
}
Also used : TvpDataCollection(org.n52.io.series.TvpDataCollection) QuantityData(org.n52.io.response.dataset.quantity.QuantityData)

Example 5 with TvpDataCollection

use of org.n52.io.TvpDataCollection in project series-rest-api by 52North.

the class PDFReportGenerator method addDataTable.

private void addDataTable(TimeSeries timeseries, TimeseriesMetadataOutput metadata, TvpDataCollection<Data<QuantityValue>> dataCollection) {
    TableType dataTable = timeseries.addNewTable();
    // TODO add language context
    dataTable.setLeftColHeader("Date");
    dataTable.setRightColHeader(createValueTableHeader(metadata));
    Data<QuantityValue> data = dataCollection.getSeries(metadata.getId());
    for (QuantityValue valueEntry : data.getValues()) {
        Entry entry = dataTable.addNewEntry();
        // TODO update TableType schema to allow start/end time
        entry.setTime(new DateTime(valueEntry.getTimestamp()).toString());
        BigDecimal value = valueEntry.getValue();
        entry.setValue(value != null ? value.toString() : null);
    }
}
Also used : Entry(org.n52.oxf.TableType.Entry) TableType(org.n52.oxf.TableType) QuantityValue(org.n52.io.response.dataset.quantity.QuantityValue) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal)

Aggregations

QuantityData (org.n52.io.response.dataset.quantity.QuantityData)3 DateTime (org.joda.time.DateTime)2 QuantityValue (org.n52.io.response.dataset.quantity.QuantityValue)2 TvpDataCollection (org.n52.io.series.TvpDataCollection)2 TableType (org.n52.oxf.TableType)2 Entry (org.n52.oxf.TableType.Entry)2 BigDecimal (java.math.BigDecimal)1 Test (org.junit.jupiter.api.Test)1 TvpDataCollection (org.n52.io.TvpDataCollection)1 IoParameters (org.n52.io.request.IoParameters)1 Data (org.n52.io.response.dataset.Data)1 LargestTriangleThreeBucketsGeneralizer (org.n52.io.type.quantity.generalize.LargestTriangleThreeBucketsGeneralizer)1