Search in sources :

Example 16 with QuantityData

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

the class QuantityIoFactory method createProcessChain.

@Override
public IoProcessChain<QuantityData> createProcessChain() {
    return new IoProcessChain<QuantityData>() {

        @Override
        public DataCollection<QuantityData> getData() {
            final boolean generalize = getParameters().isGeneralize();
            DataService<QuantityData> dataService = generalize ? new GeneralizingQuantityService(getDataService()) : getDataService();
            return dataService.getData(getRequestParameters());
        }

        @Override
        public DataCollection<?> getProcessedData() {
            String format = getParameters().getFormat();
            return FormatterFactory.createFormatterFactory(format).create().format(getData());
        }
    };
}
Also used : IoProcessChain(org.n52.io.IoProcessChain) GeneralizingQuantityService(org.n52.io.quantity.generalize.GeneralizingQuantityService) QuantityData(org.n52.io.response.dataset.quantity.QuantityData)

Example 17 with QuantityData

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

the class MultipleChartsRenderer method writeDataToChart.

@Override
public void writeDataToChart(DataCollection<QuantityData> data) {
    Map<String, QuantityData> allTimeseries = data.getAllSeries();
    List<? extends DatasetOutput> timeseriesMetadatas = getMetadataOutputs();
    int rendererCount = timeseriesMetadatas.size();
    for (int rendererIndex = 0; rendererIndex < timeseriesMetadatas.size(); rendererIndex++) {
        /*
             * For each index put data and its renderer configured to a particular style.
             *
             * As each timeseries may define its custom styling and different chart types we have to loop over
             * all timeseries to configure chart rendering.
             */
        DatasetOutput timeseriesMetadata = timeseriesMetadatas.get(rendererIndex);
        String timeseriesId = timeseriesMetadata.getId();
        StyleProperties style = getTimeseriesStyleFor(timeseriesId);
        QuantityData timeseriesData = allTimeseries.get(timeseriesId);
        String chartId = createChartId(timeseriesMetadata);
        ChartIndexConfiguration configuration = new ChartIndexConfiguration(chartId, rendererIndex);
        configuration.setData(timeseriesData, timeseriesMetadata, style);
        configuration.setRenderer(createRenderer(style));
        if (timeseriesData.hasReferenceValues()) {
            int referenceIndex = rendererCount;
            /*
                 * Configure timeseries reference value renderers with the same metadata and add it at the end
                 * of the plot's renderer list.
                 */
            QuantityDatasetMetadata metadata = timeseriesData.getMetadata();
            Map<String, QuantityData> referenceValues = metadata.getReferenceValues();
            for (Entry<String, QuantityData> referencedTimeseries : referenceValues.entrySet()) {
                String referenceTimeseriesId = referencedTimeseries.getKey();
                ReferenceValueOutput referenceOutput = getReferenceValue(referenceTimeseriesId, timeseriesMetadata);
                String referenceChartId = createChartId(timeseriesMetadata, referenceOutput.getLabel());
                QuantityData referenceData = referenceValues.get(referenceTimeseriesId);
                ChartIndexConfiguration referenceConfiguration = new ChartIndexConfiguration(referenceChartId, referenceIndex);
                StyleProperties referenceStyle = getTimeseriesStyleFor(timeseriesId, referenceTimeseriesId);
                referenceConfiguration.setReferenceData(referenceData, timeseriesMetadata, referenceStyle);
                referenceConfiguration.setRenderer(createRenderer(referenceStyle));
                referenceIndex++;
            }
        }
    }
}
Also used : ReferenceValueOutput(org.n52.io.response.dataset.ReferenceValueOutput) DatasetOutput(org.n52.io.response.dataset.DatasetOutput) StyleProperties(org.n52.io.request.StyleProperties) QuantityData(org.n52.io.response.dataset.quantity.QuantityData) QuantityDatasetMetadata(org.n52.io.response.dataset.quantity.QuantityDatasetMetadata)

Example 18 with QuantityData

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

the class HighchartFormatter method format.

@Override
public HighchartDataCollection format(DataCollection<QuantityData> toFormat) {
    HighchartDataCollection dataCollection = new HighchartDataCollection();
    for (String timeseriesId : toFormat.getAllSeries().keySet()) {
        QuantityData seriesToFormat = toFormat.getSeries(timeseriesId);
        HighchartData series = createHighchartSeries(timeseriesId, seriesToFormat);
        dataCollection.addNewSeries(timeseriesId, series);
        QuantityDatasetMetadata metadata = seriesToFormat.getMetadata();
        if (metadata != null) {
            Map<String, QuantityData> referenceValues = metadata.getReferenceValues();
            for (String referenceValueId : referenceValues.keySet()) {
                QuantityData timeseriesData = metadata.getReferenceValues().get(referenceValueId);
                HighchartData referenceSeries = createHighchartSeries(referenceValueId, timeseriesData);
                dataCollection.addNewSeries(referenceValueId, referenceSeries);
            }
        }
    }
    return dataCollection;
}
Also used : QuantityData(org.n52.io.response.dataset.quantity.QuantityData) QuantityDatasetMetadata(org.n52.io.response.dataset.quantity.QuantityDatasetMetadata)

Example 19 with QuantityData

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

the class GeneralizingQuantityService method logGeneralizationAmount.

private void logGeneralizationAmount(DataCollection<QuantityData> ungeneralizedData, DataCollection<QuantityData> generalizedData) {
    for (String timeseriesId : ungeneralizedData.getAllSeries().keySet()) {
        QuantityData originalTimeseries = ungeneralizedData.getSeries(timeseriesId);
        QuantityData generalizedTimeseries = generalizedData.getSeries(timeseriesId);
        int originalAmount = originalTimeseries.getValues().size();
        int generalizedAmount = generalizedTimeseries.getValues().size();
        LOGGER.debug("Generalized timeseries: {} (#{} --> #{}).", timeseriesId, originalAmount, generalizedAmount);
    }
}
Also used : QuantityData(org.n52.io.response.dataset.quantity.QuantityData)

Example 20 with QuantityData

use of org.n52.io.response.dataset.quantity.QuantityData 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)

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