Search in sources :

Example 6 with QuantityData

use of org.n52.io.response.dataset.quantity.QuantityData in project series-rest-api by 52North.

the class DouglasPeuckerGeneralizer method recursiveGeneralize.

private QuantityValue[] recursiveGeneralize(QuantityData timeseries) {
    QuantityValue[] values = getValueArray(timeseries);
    QuantityValue startValue = getFirstValue(timeseries);
    QuantityValue endValue = getLastValue(timeseries);
    Line2D.Double line = createTendencyLine(startValue, endValue);
    // find the point of maximum distance to the line
    int index = 0;
    double maxDist = 0;
    double distance;
    // start and end value are not mentioned
    for (int i = 1; i < values.length - 1; i++) {
        QuantityValue timeseriesValue = values[i];
        distance = calculateDistance(line, timeseriesValue);
        if (distance > maxDist) {
            index = i;
            maxDist = distance;
        }
    }
    if (maxDist < toleranceValue) {
        return getValueArray(timeseries);
    } else {
        // split and handle both parts separately
        QuantityData generalizedData = new QuantityData();
        QuantityData firstPartToBeGeneralized = new QuantityData();
        QuantityData restPartToBeGeneralized = new QuantityData();
        firstPartToBeGeneralized.addValues(Arrays.copyOfRange(values, 0, index));
        restPartToBeGeneralized.addValues(Arrays.copyOfRange(values, index + 1, values.length));
        generalizedData.addValues(recursiveGeneralize(firstPartToBeGeneralized));
        generalizedData.addValues(recursiveGeneralize(restPartToBeGeneralized));
        return getValueArray(generalizedData);
    }
}
Also used : QuantityValue(org.n52.io.response.dataset.quantity.QuantityValue) Line2D(java.awt.geom.Line2D) QuantityData(org.n52.io.response.dataset.quantity.QuantityData)

Example 7 with QuantityData

use of org.n52.io.response.dataset.quantity.QuantityData in project series-rest-api by 52North.

the class QuantityCsvIoHandler method writeData.

private void writeData(DatasetOutput metadata, QuantityData series, OutputStream stream) throws IOException {
    String station = null;
    ParameterOutput platform = metadata.getSeriesParameters().getPlatform();
    if (platform == null) {
        TimeseriesMetadataOutput output = (TimeseriesMetadataOutput) metadata;
        station = output.getStation().getLabel();
    } else {
        station = platform.getLabel();
    }
    String phenomenon = metadata.getSeriesParameters().getPhenomenon().getLabel();
    String uom = metadata.getUom();
    for (QuantityValue timeseriesValue : series.getValues()) {
        String[] values = new String[getHeader().length];
        values[0] = station;
        values[1] = phenomenon;
        values[2] = uom;
        Long timestart = timeseriesValue.getTimestart();
        Long timeend = timeseriesValue.getTimestamp();
        values[3] = timestart != null ? new DateTime(timestart).toString() : null;
        values[4] = new DateTime(timeend).toString();
        values[5] = numberformat.format(timeseriesValue.getValue());
        writeCsvLine(csvEncode(values), stream);
    }
}
Also used : TimeseriesMetadataOutput(org.n52.io.response.dataset.TimeseriesMetadataOutput) QuantityValue(org.n52.io.response.dataset.quantity.QuantityValue) ParameterOutput(org.n52.io.response.ParameterOutput) DateTime(org.joda.time.DateTime)

Example 8 with QuantityData

use of org.n52.io.response.dataset.quantity.QuantityData in project series-rest-api by 52North.

the class FlotFormatter method createFlotSeries.

private FlotData createFlotSeries(QuantityData seriesToFormat) {
    FlotData flotSeries = new FlotData();
    flotSeries.setValues(formatSeries(seriesToFormat));
    QuantityDatasetMetadata metadata = seriesToFormat.getMetadata();
    if (metadata != null) {
        Map<String, QuantityData> referenceValues = metadata.getReferenceValues();
        for (String referenceValueId : referenceValues.keySet()) {
            QuantityData referenceValueData = metadata.getReferenceValues().get(referenceValueId);
            flotSeries.addReferenceValues(referenceValueId, formatSeries(referenceValueData));
        }
    }
    return flotSeries;
}
Also used : QuantityData(org.n52.io.response.dataset.quantity.QuantityData) QuantityDatasetMetadata(org.n52.io.response.dataset.quantity.QuantityDatasetMetadata)

Example 9 with QuantityData

use of org.n52.io.response.dataset.quantity.QuantityData in project series-rest-api by 52North.

the class FlotFormatter method formatSeries.

private List<Number[]> formatSeries(QuantityData timeseries) {
    List<Number[]> series = new ArrayList<>();
    for (QuantityValue currentValue : timeseries.getValues()) {
        List<Number> list = new ArrayList<>();
        list.add(currentValue.getTimestamp());
        list.add(currentValue.getValue());
        if (currentValue.isSetGeometry()) {
            Coordinate coordinate = currentValue.getGeometry().getCoordinate();
            list.add(coordinate.x);
            list.add(coordinate.y);
            if (!Double.isNaN(coordinate.z)) {
                list.add(coordinate.z);
            }
        }
        series.add(list.toArray(new Number[0]));
    }
    return series;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) QuantityValue(org.n52.io.response.dataset.quantity.QuantityValue) ArrayList(java.util.ArrayList)

Example 10 with QuantityData

use of org.n52.io.response.dataset.quantity.QuantityData in project series-rest-api by 52North.

the class FlotFormatter method format.

@Override
public FlotDataCollection format(DataCollection<QuantityData> toFormat) {
    FlotDataCollection flotDataCollection = new FlotDataCollection();
    for (String timeseriesId : toFormat.getAllSeries().keySet()) {
        QuantityData seriesToFormat = toFormat.getSeries(timeseriesId);
        FlotData series = createFlotSeries(seriesToFormat);
        flotDataCollection.addNewSeries(timeseriesId, series);
    }
    return flotDataCollection;
}
Also used : QuantityData(org.n52.io.response.dataset.quantity.QuantityData)

Aggregations

QuantityData (org.n52.io.response.dataset.quantity.QuantityData)14 QuantityValue (org.n52.io.response.dataset.quantity.QuantityValue)7 IOException (java.io.IOException)3 IoParseException (org.n52.io.IoParseException)3 QuantityDatasetMetadata (org.n52.io.response.dataset.quantity.QuantityDatasetMetadata)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 GeneralizingQuantityService (org.n52.io.quantity.generalize.GeneralizingQuantityService)2 DatasetOutput (org.n52.io.response.dataset.DatasetOutput)2 TvpDataCollection (org.n52.io.series.TvpDataCollection)2 Line2D (java.awt.geom.Line2D)1 File (java.io.File)1 Result (javax.xml.transform.Result)1 Source (javax.xml.transform.Source)1 Transformer (javax.xml.transform.Transformer)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 SAXResult (javax.xml.transform.sax.SAXResult)1