Search in sources :

Example 21 with Data

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

the class MultipleChartsRenderer method writeDataToChart.

@Override
public void writeDataToChart(DataCollection<Data<QuantityValue>> data) {
    Map<String, Data<QuantityValue>> 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 = getDatasetStyleFor(timeseriesId);
        Data<QuantityValue> 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.
                 */
            DatasetMetadata<QuantityValue> metadata = timeseriesData.getMetadata();
            Map<String, Data<QuantityValue>> referenceValues = metadata.getReferenceValues();
            for (Entry<String, Data<QuantityValue>> referencedTimeseries : referenceValues.entrySet()) {
                String referenceTimeseriesId = referencedTimeseries.getKey();
                ReferenceValueOutput<?> referenceOutput = getReferenceValue(referenceTimeseriesId, timeseriesMetadata);
                String referenceChartId = createChartId(timeseriesMetadata, referenceOutput.getLabel());
                Data<QuantityValue> 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 : Data(org.n52.io.response.dataset.Data) QuantityValue(org.n52.io.response.dataset.quantity.QuantityValue) StyleProperties(org.n52.io.request.StyleProperties)

Example 22 with Data

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

the class PDFReportGenerator method generateOutput.

public void generateOutput(DataCollection<Data<QuantityValue>> data) throws IoHandlerException {
    try {
        generateTimeseriesChart(data);
        generateTimeseriesMetadata();
    } catch (IOException e) {
        throw new IoHandlerException("Error handling (temp) file!", e);
    }
}
Also used : IoHandlerException(org.n52.io.handler.IoHandlerException) IOException(java.io.IOException)

Example 23 with Data

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

the class GeneralizerFactoryTest method when_nonDefaultAlgorithmConfig_then_factoryCreatesAppropriateGeneralizer.

@Test
public void when_nonDefaultAlgorithmConfig_then_factoryCreatesAppropriateGeneralizer() throws URISyntaxException {
    IoParameters nonDefaultConfig = IoParameters.createDefaults(getAlternativeConfigFile());
    Generalizer<Data<QuantityValue>> generalizer = GeneralizerFactory.createGeneralizer(nonDefaultConfig);
    assertThat(generalizer, IsInstanceOf.instanceOf(DouglasPeuckerGeneralizer.class));
}
Also used : DouglasPeuckerGeneralizer(org.n52.io.type.quantity.generalize.DouglasPeuckerGeneralizer) Data(org.n52.io.response.dataset.Data) IoParameters(org.n52.io.request.IoParameters) Test(org.junit.jupiter.api.Test)

Example 24 with Data

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

the class TimeseriesDataController method getData.

@RequestMapping(value = "/{timeseriesId}/getData", produces = Constants.APPLICATION_JSON, method = RequestMethod.GET)
public ModelAndView getData(HttpServletResponse response, @PathVariable String timeseriesId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE, required = false) String httpLocale, @RequestParam(required = false) MultiValueMap<String, String> request) {
    IoParameters parameters = createParameters(timeseriesId, request, httpLocale, response);
    checkAgainstTimespanRestriction(parameters.getTimespan());
    checkIfUnknownTimeseriesId(parameters, timeseriesId);
    response.setCharacterEncoding(DEFAULT_RESPONSE_ENCODING);
    response.setContentType(Constants.APPLICATION_JSON);
    // TODO add paging
    DataCollection<Data<QuantityValue>> seriesData = getTimeseriesData(parameters);
    DataCollection<?> formattedDataCollection = format(seriesData, parameters);
    if (parameters.isExpanded()) {
        return new ModelAndView().addObject(formattedDataCollection.getAllSeries());
    }
    Map<String, ?> allSeries = formattedDataCollection.getAllSeries();
    Object formattedTimeseries = allSeries.get(timeseriesId);
    return new ModelAndView().addObject(formattedTimeseries);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) Data(org.n52.io.response.dataset.Data) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with Data

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

the class TimeseriesDataController method processRawDataRequest.

private void processRawDataRequest(HttpServletResponse response, IoParameters parameters) {
    if (!timeseriesDataService.supportsRawData()) {
        throwNewRawDataQueryNotSupportedException();
    }
    final RawDataService rawDataService = timeseriesDataService.getRawDataService();
    try (InputStream inputStream = rawDataService.getRawData(parameters)) {
        response.setContentType(parameters.getFormat());
        IOUtils.copyLarge(inputStream, response.getOutputStream());
    } catch (IOException e) {
        throw new InternalServerException("Error while querying raw data", e);
    }
}
Also used : RawDataService(org.n52.series.spi.srv.RawDataService) InputStream(java.io.InputStream) InternalServerException(org.n52.web.exception.InternalServerException) IOException(java.io.IOException)

Aggregations

IoParameters (org.n52.io.request.IoParameters)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 Data (org.n52.io.response.dataset.Data)13 IOException (java.io.IOException)12 QuantityValue (org.n52.io.response.dataset.quantity.QuantityValue)11 HashMap (java.util.HashMap)6 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)6 QuantityData (org.n52.io.response.dataset.quantity.QuantityData)6 InputStream (java.io.InputStream)5 XmlObject (org.apache.xmlbeans.XmlObject)5 IoParseException (org.n52.io.IoParseException)5 File (java.io.File)4 Test (org.junit.Test)4 InternalServerException (org.n52.web.exception.InternalServerException)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 BigDecimal (java.math.BigDecimal)3 ElasticsearchAwareTest (org.n52.iceland.statistics.basetests.ElasticsearchAwareTest)3 ResultTimeClassifiedData (org.n52.io.format.ResultTimeClassifiedData)3 RawDataService (org.n52.series.spi.srv.RawDataService)3 DecodingException (org.n52.svalbard.decode.exception.DecodingException)3