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++;
}
}
}
}
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);
}
}
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));
}
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);
}
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);
}
}
Aggregations