Search in sources :

Example 6 with DatasetOutput

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

the class ChartIoHandler method formatTitle.

protected String formatTitle(DatasetOutput metadata, String title) {
    SeriesParameters parameters = metadata.getSeriesParameters();
    Object[] varargs = { // index important to reference in config!
    parameters.getPlatform().getLabel(), parameters.getPhenomenon().getLabel(), parameters.getProcedure().getLabel(), parameters.getCategory().getLabel(), parameters.getOffering().getLabel(), parameters.getFeature().getLabel(), parameters.getService().getLabel(), metadata.getUom() };
    try {
        return String.format(title, varargs);
    } catch (Exception e) {
        String datasetId = metadata.getId();
        LOGGER.info("Couldn't format title while prerendering dataset '{}'", datasetId, e);
        // return template as fallback
        return title;
    }
}
Also used : SeriesParameters(org.n52.io.response.dataset.SeriesParameters) IoParseException(org.n52.io.IoParseException) IOException(java.io.IOException)

Example 7 with DatasetOutput

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

the class ChartIoHandler method createRangeLabel.

protected String createRangeLabel(DatasetOutput timeseriesMetadata) {
    SeriesParameters parameters = timeseriesMetadata.getSeriesParameters();
    ParameterOutput phenomenon = parameters.getPhenomenon();
    StringBuilder uom = new StringBuilder();
    uom.append(phenomenon.getLabel());
    String uomLabel = timeseriesMetadata.getUom();
    if (uomLabel != null && !uomLabel.isEmpty()) {
        uom.append(" [").append(uomLabel).append("]");
    }
    return uom.toString();
}
Also used : SeriesParameters(org.n52.io.response.dataset.SeriesParameters) ParameterOutput(org.n52.io.response.ParameterOutput)

Example 8 with DatasetOutput

use of org.n52.io.response.dataset.DatasetOutput 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 9 with DatasetOutput

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

the class MultipleChartsRenderer method createChartId.

private String createChartId(DatasetOutput metadata, String referenceId) {
    ParameterOutput feature = metadata.getSeriesParameters().getFeature();
    StringBuilder timeseriesLabel = new StringBuilder();
    timeseriesLabel.append(feature.getLabel());
    if (referenceId != null) {
        timeseriesLabel.append(", ").append(referenceId);
    }
    timeseriesLabel.append(" (").append(createRangeLabel(metadata)).append(")");
    return timeseriesLabel.toString();
}
Also used : ParameterOutput(org.n52.io.response.ParameterOutput)

Example 10 with DatasetOutput

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

the class ChartIoHandler method getTitleForSingle.

private String getTitleForSingle(RequestStyledParameterSet config, String template) {
    String[] timeseries = config.getDatasets();
    if (timeseries != null && timeseries.length > 0) {
        String timeseriesId = timeseries[0];
        DatasetOutput metadata = getTimeseriesMetadataOutput(timeseriesId);
        if (metadata != null) {
            return formatTitle(metadata, template);
        }
    }
    return template;
}
Also used : DatasetOutput(org.n52.io.response.dataset.DatasetOutput)

Aggregations

DatasetOutput (org.n52.io.response.dataset.DatasetOutput)4 ParameterOutput (org.n52.io.response.ParameterOutput)3 SeriesParameters (org.n52.io.response.dataset.SeriesParameters)3 IOException (java.io.IOException)2 IoParameters (org.n52.io.request.IoParameters)2 RequestStyledParameterSet (org.n52.io.request.RequestStyledParameterSet)2 StyleProperties (org.n52.io.request.StyleProperties)2 QuantityData (org.n52.io.response.dataset.quantity.QuantityData)2 TimeSeries (org.n52.oxf.DocumentStructureType.TimeSeries)2 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 IoParseException (org.n52.io.IoParseException)1 RenderingConfig (org.n52.io.PrerenderingJobConfig.RenderingConfig)1 ChartDimension (org.n52.io.quantity.img.ChartDimension)1 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)1 ReferenceValueOutput (org.n52.io.response.dataset.ReferenceValueOutput)1 TimeseriesMetadataOutput (org.n52.io.response.dataset.TimeseriesMetadataOutput)1 QuantityDatasetMetadata (org.n52.io.response.dataset.quantity.QuantityDatasetMetadata)1 QuantityValue (org.n52.io.response.dataset.quantity.QuantityValue)1