use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class DouglasPeuckerGeneralizer method generalize.
private Data<QuantityValue> generalize(Data<QuantityValue> timeseries) throws GeneralizerException {
QuantityValue[] originalValues = getValueArray(timeseries);
if ((originalValues.length < 3) || (toleranceValue <= 0)) {
return timeseries;
}
if ((maxEntries != -1) && (originalValues.length > maxEntries)) {
throw new GeneralizerException("Maximum number of entries exceeded (" + originalValues.length + ">" + maxEntries + ")!");
}
Data<QuantityValue> generalizedTimeseries = new Data<>(timeseries.getMetadata());
QuantityValue[] generalizedValues = recursiveGeneralize(timeseries);
generalizedTimeseries.addValues(generalizedValues);
// add first element if new list is empty
if (generalizedValues.length == 0) /* && originalValues.length > 0*/
{
generalizedTimeseries.addNewValue(originalValues[0]);
}
// add the last one if not already contained!
if (generalizedValues.length > 0) /* && originalValues.length > 0*/
{
QuantityValue lastOriginialValue = originalValues[originalValues.length - 1];
QuantityValue lastGeneralizedValue = generalizedValues[generalizedValues.length - 1];
if (!lastGeneralizedValue.getTimestamp().equals(lastOriginialValue.getTimestamp())) {
generalizedTimeseries.addNewValue(lastOriginialValue);
}
}
return generalizedTimeseries;
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class ChartIoHandler method encodeAndWriteTo.
@Override
public void encodeAndWriteTo(DataCollection<Data<QuantityValue>> data, OutputStream stream) throws IoParseException {
try {
writeDataToChart(data);
ImageIO.write(createImage(), mimeType.getFormatName(), stream);
} catch (IOException e) {
throw new IoParseException("Could not write image to output stream.", e);
}
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class PDFReportGenerator method encodeAndWriteTo.
@Override
public void encodeAndWriteTo(DataCollection<Data<QuantityValue>> data, OutputStream stream) throws IoHandlerException {
try {
generateOutput(data);
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.build(document.newInputStream());
URI baseURI = new File(".").toURI();
FopFactory fopFactory = new FopFactoryBuilder(baseURI).setConfiguration(cfg).build();
final String mimeType = Constants.APPLICATION_PDF;
Fop fop = fopFactory.newFop(mimeType, stream);
// FopFactory fopFactory = FopFactory.newInstance(cfg);
// Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
// FopFactory fopFactory = fopFactoryBuilder.build();
// Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
// Create PDF via XSLT transformation
TransformerFactory transFact = TransformerFactory.newInstance();
StreamSource transformationRule = getTransforamtionRule();
Transformer transformer = transFact.newTransformer(transformationRule);
Source source = new StreamSource(document.newInputStream());
Result result = new SAXResult(fop.getDefaultHandler());
if (LOGGER.isDebugEnabled()) {
try {
File tempFile = File.createTempFile(TEMP_FILE_PREFIX, ".xml");
StreamResult debugResult = new StreamResult(tempFile);
transformer.transform(source, debugResult);
String xslResult = XmlObject.Factory.parse(tempFile).xmlText();
LOGGER.debug("xsl-fo input (locale '{}'): {}", i18n.getTwoDigitsLanguageCode(), xslResult);
} catch (IOException | TransformerException | XmlException e) {
LOGGER.error("Could not debug XSL result output!", e);
}
}
// XXX debug, diagram is not embedded
transformer.transform(source, result);
} catch (FOPException e) {
throw new IoParseException("Failed to create Formatting Object Processor (FOP)", e);
} catch (ConfigurationException e) {
throw new IoParseException("Failed to read config for Formatting Object Processor (FOP)", e);
} catch (TransformerConfigurationException e) {
throw new IoParseException("Invalid transform configuration. Inspect xslt!", e);
} catch (TransformerException e) {
throw new IoParseException("Could not generate PDF report!", e);
}
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class PDFReportGenerator method addDataTable.
private void addDataTable(TimeSeries timeseries, TimeseriesMetadataOutput metadata, TvpDataCollection<Data<QuantityValue>> dataCollection) {
TableType dataTable = timeseries.addNewTable();
// TODO add language context
dataTable.setLeftColHeader("Date");
dataTable.setRightColHeader(createValueTableHeader(metadata));
Data<QuantityValue> data = dataCollection.getSeries(metadata.getId());
for (QuantityValue valueEntry : data.getValues()) {
Entry entry = dataTable.addNewEntry();
// TODO update TableType schema to allow start/end time
entry.setTime(new DateTime(valueEntry.getTimestamp()).toString());
BigDecimal value = valueEntry.getValue();
entry.setValue(value != null ? value.toString() : null);
}
}
use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.
the class PDFReportGenerator method generateTimeseriesMetadata.
private void generateTimeseriesMetadata() {
for (DatasetOutput<?> metadata : getAllDatasetMetadatas()) {
TimeSeries timeseries = addTimeseries(metadata);
// addDataTable(timeseries, metadata, data);
addMetadata(timeseries, metadata);
}
}
Aggregations