[PATCH] SINFO - Flow depth development - implemented exporters
Wald Commits
scm-commit at wald.intevation.org
Mon Mar 19 14:01:28 CET 2018
# HG changeset patch
# User gernotbelger
# Date 1521464481 -3600
# Node ID c40db8e8dcae8f1eb3e8cdc918a2f5a8b8593a5b
# Parent 1a8f19f3b7765cbbebbe16e1925f276ddb9ddcd3
SINFO - Flow depth development - implemented exporters
diff -r 1a8f19f3b776 -r c40db8e8dcae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoExporter.java Mon Mar 19 09:12:17 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoExporter.java Mon Mar 19 14:01:21 2018 +0100
@@ -83,6 +83,14 @@
}
}
+ /**
+ * Formats header with unit and label: msg [unit] (label)
+ */
+ protected final String msgUnitLabel(final String key, final String unit, final String label) {
+ final String msg = msg(key);
+ return String.format("%s [%s] (%s)", msg, unit, label);
+ }
+
@Override
protected final void writeCSVData(final CSVWriter writer) {
getLog().info("writeCSVData");
@@ -228,8 +236,12 @@
}
protected final void writeCSVSoundingMetadata(final CSVWriter writer, final BedHeightInfo sounding) {
+ writeCSVSoundingMetadata(writer, sounding, CSV_META_HEADER_SOUNDING);
+ }
+
+ protected final void writeCSVSoundingMetadata(final CSVWriter writer, final BedHeightInfo sounding, final String mainLabel) {
// "##METADATEN PEILUNG"
- writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING);
+ writeCSVMetaEntry(writer, mainLabel);
// "# Jahr der Peilung: "
writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_YEAR, Integer.toString(sounding.getYear()));
@@ -246,8 +258,12 @@
}
protected final void writeCSVWaterlevelMetadata(final CSVWriter writer, final WstInfo wst) {
+ writeCSVWaterlevelMetadata(writer, wst, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL);
+ }
+
+ protected final void writeCSVWaterlevelMetadata(final CSVWriter writer, final WstInfo wst, final String mainLabel) {
// "##METADATEN WASSERSPIEGELLAGE"
- writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL);
+ writeCSVMetaEntry(writer, mainLabel);
// "# Bezeichnung der Wasserspiegellage: "
writeCSVMetaEntry(writer, SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, wst.getLabel());
diff -r 1a8f19f3b776 -r c40db8e8dcae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculation.java Mon Mar 19 09:12:17 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculation.java Mon Mar 19 14:01:21 2018 +0100
@@ -180,10 +180,26 @@
}
}
- return new FlowDepthDevelopmentCalculationResult("", currentWstInfo, historicalWstInfo, currentSoundingInfo, historicalSoundingInfo,
+ final String label = buildLabel(currentWaterlevel, currentSoundingInfo, historicalWaterlevel, historicalSoundingInfo);
+
+ return new FlowDepthDevelopmentCalculationResult(label, currentWstInfo, historicalWstInfo, currentSoundingInfo, historicalSoundingInfo,
rows);
}
+ private String buildLabel(final WaterlevelData currentWaterlevel, final BedHeightInfo currentSounding, final WaterlevelData historicalWaterlevel,
+ final BedHeightInfo historicalSounding) {
+
+ return new StringBuilder(). //
+ append(currentWaterlevel.getName()). //
+ append('/'). //
+ append(historicalWaterlevel.getName()). //
+ append(" - "). //
+ append(currentSounding.getDescription()). //
+ append('/'). //
+ append(historicalSounding.getDescription()). //
+ toString();
+ }
+
/* REMARK: fetch ALL wst kms, because we need to determine the original reference gauge */
private WaterlevelData loadWaterlevel(final WstSoundingIdPair pair, final Calculation problems) {
final String wstId = pair.getWstId();
diff -r 1a8f19f3b776 -r c40db8e8dcae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculationResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculationResult.java Mon Mar 19 09:12:17 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculationResult.java Mon Mar 19 14:01:21 2018 +0100
@@ -60,4 +60,36 @@
public BedHeightInfo getHistoricalSounding() {
return this.historicalSounding;
}
+
+ public String getWaterlevelDifferenceLabel() {
+ return new StringBuilder(). //
+ append(this.currentWst.getLabel()). //
+ append(" - "). //
+ append(this.historicalWst.getLabel()). //
+ toString();
+ }
+
+ public String getBedHeightDifferenceLabel() {
+ return new StringBuilder(). //
+ append(this.currentSounding.getDescription()). //
+ append(" - "). //
+ append(this.historicalSounding.getDescription()). //
+ toString();
+ }
+
+ public String getFlowDepthCurrentLabel() {
+ return new StringBuilder(). //
+ append(this.currentWst.getLabel()). //
+ append(" - "). //
+ append(this.currentSounding.getDescription()). //
+ toString();
+ }
+
+ public String getFlowDepthHistoricalLabel() {
+ return new StringBuilder(). //
+ append(this.historicalWst.getLabel()). //
+ append(" - "). //
+ append(this.historicalSounding.getDescription()). //
+ toString();
+ }
}
\ No newline at end of file
diff -r 1a8f19f3b776 -r c40db8e8dcae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculationResults.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculationResults.java Mon Mar 19 09:12:17 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculationResults.java Mon Mar 19 14:01:21 2018 +0100
@@ -9,6 +9,8 @@
*/
package org.dive4elements.river.artifacts.sinfo.flowdepthdev;
+import java.util.List;
+
import org.apache.commons.lang.math.DoubleRange;
import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoCalculationResults;
import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
@@ -23,4 +25,15 @@
public FlowDepthDevelopmentCalculationResults(final String calcModeLabel, final String user, final RiverInfo river, final DoubleRange calcRange) {
super(calcModeLabel, user, river, calcRange);
}
+
+ /**
+ * We know that this type of results only has one result member, so we can directly access it.
+ */
+ public FlowDepthDevelopmentCalculationResult getResult() {
+ final List<FlowDepthDevelopmentCalculationResult> results = getResults();
+ if (results.size() < 1)
+ return null;
+
+ return results.get(0);
+ }
}
\ No newline at end of file
diff -r 1a8f19f3b776 -r c40db8e8dcae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentExporter.java Mon Mar 19 09:12:17 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentExporter.java Mon Mar 19 14:01:21 2018 +0100
@@ -29,6 +29,14 @@
// REMARK: must be public because its registered in generators.xml
public class FlowDepthDevelopmentExporter extends AbstractSInfoExporter<FlowDepthDevelopmentCalculationResult, FlowDepthDevelopmentCalculationResults> {
+ private static final String CSV_META_HEADER_SOUNDING_CURRENT = "sinfo.export.csv.meta.header.sounding.current";
+
+ private static final String CSV_META_HEADER_SOUNDING_HISTORICAL = "sinfo.export.csv.meta.header.sounding.historical";
+
+ private static final String CSV_META_HEADER_WATERLEVEL_CURRENT = "sinfo.export.csv.meta.header.waterlevel.current";
+
+ private static final String CSV_META_HEADER_WATERLEVEL_HISTORICAL = "sinfo.export.csv.meta.header.waterlevel.historical";
+
/** The log used in this exporter. */
private static Logger log = Logger.getLogger(FlowDepthDevelopmentExporter.class);
@@ -43,13 +51,10 @@
protected void writeCSVResultMetadata(final CSVWriter writer, final FlowDepthDevelopmentCalculationResults results,
final FlowDepthDevelopmentCalculationResult result) {
- // FIXME: distinguish header labels
- writeCSVSoundingMetadata(writer, result.getCurrentSounding());
- writeCSVWaterlevelMetadata(writer, result.getCurrentWst());
-
- // FIXME: distinguish header labels
- writeCSVSoundingMetadata(writer, result.getHistoricalSounding());
- writeCSVWaterlevelMetadata(writer, result.getHistoricalWst());
+ writeCSVSoundingMetadata(writer, result.getCurrentSounding(), CSV_META_HEADER_SOUNDING_CURRENT);
+ writeCSVWaterlevelMetadata(writer, result.getCurrentWst(), CSV_META_HEADER_WATERLEVEL_CURRENT);
+ writeCSVSoundingMetadata(writer, result.getHistoricalSounding(), CSV_META_HEADER_SOUNDING_HISTORICAL);
+ writeCSVWaterlevelMetadata(writer, result.getHistoricalWst(), CSV_META_HEADER_WATERLEVEL_HISTORICAL);
}
@Override
@@ -71,19 +76,21 @@
protected void writeCSVHeader(final CSVWriter writer, final FlowDepthDevelopmentCalculationResults results, final RiverInfo river) {
log.info("FlowDepthExporter.writeCSVHeader");
+ final FlowDepthDevelopmentCalculationResult result = results.getResult();
+
final Collection<String> header = new ArrayList<>(11);
header.add(msg(SInfoResultType.station.getCsvHeader()));
header.add(msgUnit(SInfoResultType.flowdepthDevelopment.getCsvHeader(), SInfoResultType.flowdepthDevelopment.getUnit()));
header.add(msgUnit(SInfoResultType.flowdepthDevelopmentPerYear.getCsvHeader(), SInfoResultType.flowdepthDevelopmentPerYear.getUnit()));
-
- // FIXME: add data-labels in header
- header.add(msgUnit(SInfoResultType.waterlevelDifference.getCsvHeader(), SInfoResultType.waterlevelDifference.getUnit()));
- header.add(msgUnit(SInfoResultType.bedHeightDifference.getCsvHeader(), SInfoResultType.bedHeightDifference.getUnit()));
-
- header.add(msgUnit(SInfoResultType.flowdepthCurrent.getCsvHeader(), SInfoResultType.flowdepthCurrent.getUnit()));
- header.add(msgUnit(SInfoResultType.flowdepthHistorical.getCsvHeader(), SInfoResultType.flowdepthHistorical.getUnit()));
-
+ header.add(msgUnitLabel(SInfoResultType.waterlevelDifference.getCsvHeader(), SInfoResultType.waterlevelDifference.getUnit(),
+ result.getWaterlevelDifferenceLabel()));
+ header.add(msgUnitLabel(SInfoResultType.bedHeightDifference.getCsvHeader(), SInfoResultType.bedHeightDifference.getUnit(),
+ result.getBedHeightDifferenceLabel()));
+ header.add(
+ msgUnitLabel(SInfoResultType.flowdepthCurrent.getCsvHeader(), SInfoResultType.flowdepthCurrent.getUnit(), result.getFlowDepthCurrentLabel()));
+ header.add(msgUnitLabel(SInfoResultType.flowdepthHistorical.getCsvHeader(), SInfoResultType.flowdepthHistorical.getUnit(),
+ result.getFlowDepthHistoricalLabel()));
header.add(msg(SInfoResultType.location.getCsvHeader()));
writer.writeNext(header.toArray(new String[header.size()]));
@@ -108,22 +115,12 @@
lines.add(row.exportValue(this.context, SInfoResultType.station));
- // FIXME
-
- // REMARK: null check as pdf will call this with null and in that case we show all columns (to avoid multiple jasper
- // FIXME: does not work like this: we may have several pairs of min/max; so we need to look at all of them?
- // templates)
- // if (result == null || result.getMinSounding() != null)
- lines.add(row.exportValue(this.context, SInfoResultType.flowdepthmin));
- // if (result == null || result.getMaxSounding() != null)
- lines.add(row.exportValue(this.context, SInfoResultType.flowdepthmax));
-
- lines.add(row.exportValue(this.context, SInfoResultType.waterlevel));
- lines.add(row.exportValue(this.context, SInfoResultType.discharge));
- lines.add(row.exportValue(this.context, SInfoResultType.waterlevelLabel));
- lines.add(row.exportValue(this.context, SInfoResultType.gaugeLabel));
- lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight));
- lines.add(row.exportValue(this.context, SInfoResultType.soundingLabel));
+ lines.add(row.exportValue(this.context, SInfoResultType.flowdepthDevelopment));
+ lines.add(row.exportValue(this.context, SInfoResultType.flowdepthDevelopmentPerYear));
+ lines.add(row.exportValue(this.context, SInfoResultType.waterlevelDifference));
+ lines.add(row.exportValue(this.context, SInfoResultType.bedHeightDifference));
+ lines.add(row.exportValue(this.context, SInfoResultType.flowdepthCurrent));
+ lines.add(row.exportValue(this.context, SInfoResultType.flowdepthHistorical));
lines.add(row.exportValue(this.context, SInfoResultType.location));
return lines.toArray(new String[lines.size()]);
@@ -140,17 +137,25 @@
/* general metadata */
super.addJRMetaDataDefaults(source, results);
+ final FlowDepthDevelopmentCalculationResult result = results.getResult();
+
/* column headings */
- // FIXME
source.addMetaData("station_header", SInfoResultType.station.getPdfHeader(this.context.getMeta()));
- source.addMetaData("flowdepthmin_header", SInfoResultType.flowdepthmin.getPdfHeader(this.context.getMeta()));
- source.addMetaData("flowdepthmax_header", SInfoResultType.flowdepthmax.getPdfHeader(this.context.getMeta()));
- source.addMetaData("waterlevel_header", SInfoResultType.waterlevel.getPdfHeader(this.context.getMeta()));
- source.addMetaData("discharge_header", SInfoResultType.discharge.getPdfHeader(this.context.getMeta()));
- source.addMetaData("waterlevel_name_header", SInfoResultType.waterlevelLabel.getPdfHeader(this.context.getMeta()));
- source.addMetaData("gauge_header", SInfoResultType.gaugeLabel.getPdfHeader(this.context.getMeta()));
- source.addMetaData("bedheight_header", SInfoResultType.meanBedHeight.getPdfHeader(this.context.getMeta()));
- source.addMetaData("sounding_name_header", SInfoResultType.soundingLabel.getPdfHeader(this.context.getMeta()));
+ source.addMetaData("flowdeptdevelopment_header", SInfoResultType.flowdepthDevelopment.getPdfHeader(this.context.getMeta()));
+ source.addMetaData("flowdeptdevelopmentperyear_header", SInfoResultType.flowdepthDevelopmentPerYear.getPdfHeader(this.context.getMeta()));
+
+ source.addMetaData("waterleveldifference_header", SInfoResultType.waterlevelDifference.getPdfHeader(this.context.getMeta()));
+ source.addMetaData("waterleveldifference_header_label", result.getWaterlevelDifferenceLabel());
+
+ source.addMetaData("bedheightdifference_header", SInfoResultType.bedHeightDifference.getPdfHeader(this.context.getMeta()));
+ source.addMetaData("bedheightdifference_header_label", result.getBedHeightDifferenceLabel());
+
+ source.addMetaData("flowdepthcurrent_header", SInfoResultType.flowdepthCurrent.getPdfHeader(this.context.getMeta()));
+ source.addMetaData("flowdepthcurrent_header_label", result.getFlowDepthCurrentLabel());
+
+ source.addMetaData("flowdepthhistorical_header", SInfoResultType.flowdepthHistorical.getPdfHeader(this.context.getMeta()));
+ source.addMetaData("flowdepthhistorical_header_label", result.getFlowDepthHistoricalLabel());
+
source.addMetaData("location_header", SInfoResultType.location.getPdfHeader(this.context.getMeta()));
}
diff -r 1a8f19f3b776 -r c40db8e8dcae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentState.java Mon Mar 19 09:12:17 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentState.java Mon Mar 19 14:01:21 2018 +0100
@@ -15,8 +15,12 @@
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.ChartArtifact;
import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.model.Calculation;
import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.DataFacet;
import org.dive4elements.river.artifacts.model.EmptyFacet;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.model.ReportFacet;
import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
import org.dive4elements.river.artifacts.states.DefaultState;
@@ -68,8 +72,11 @@
if (facets == null)
return res;
- // final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData();
- //
+ final FlowDepthDevelopmentCalculationResults results = (FlowDepthDevelopmentCalculationResults) res.getData();
+ final FlowDepthDevelopmentCalculationResult result = results.getResult();
+ if (result == null)
+ return res;
+
// /* add themes for chart, for each result */
// final List<FlowDepthCalculationResult> resultList = results.getResults();
// for (int index = 0; index < resultList.size(); index++) {
@@ -86,20 +93,13 @@
// facets.add(TkhProcessor.createTkhFacet(context, hash, this.id, result, index));
// }
// }
- //
- // if (!resultList.isEmpty()) {
- // final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id);
- // final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id);
- //
- // facets.add(csv);
- // facets.add(pdf);
- // }
- //
- // final Calculation report = res.getReport();
- //
- // if (report.hasProblems()) {
- // facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id));
- // }
+
+ facets.add(new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id));
+ facets.add(new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id));
+
+ final Calculation report = res.getReport();
+ if (report.hasProblems())
+ facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id));
return res;
}
diff -r 1a8f19f3b776 -r c40db8e8dcae artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties Mon Mar 19 09:12:17 2018 +0100
+++ b/artifacts/src/main/resources/messages.properties Mon Mar 19 14:01:21 2018 +0100
@@ -906,4 +906,16 @@
sinfo.export.flow_depth_minmax.csv.header.min = Minimale Flie\u00dftiefe
sinfo.export.flow_depth_minmax.csv.header.max = Maximale Flie\u00dftiefe
-waterlevelfetcher.missing = Failed to access waterlevel with id '{0}'
\ No newline at end of file
+waterlevelfetcher.missing = Failed to access waterlevel with id '{0}'
+
+sinfo.export.csv.meta.header.sounding.current = ##METADATEN PEILUNG aktuell
+sinfo.export.csv.meta.header.sounding.historical = ##METADATEN PEILUNG historisch
+sinfo.export.csv.meta.header.waterlevel.current = ##METADATEN WASSERSPIEGELLAGE aktuell
+sinfo.export.csv.meta.header.waterlevel.historical = ##METADATEN WASSERSPIEGELLAGE historisch
+
+sinfo.export.csv.header.flowdepth.development = Flie\u00dftiefenentwicklung
+sinfo.export.csv.header.flowdepth.development.per.year = Flie\u00dftiefenent-wicklung pro Jahr
+sinfo.export.csv.header.waterlevel.difference = \u0394WSPL
+sinfo.export.csv.header.mean_bed_height.difference = \u0394MSH
+sinfo.export.csv.header.flowdepth.current = Flie\u00dftiefe h-aktuell
+sinfo.export.csv.header.flowdepth.historical = Flie\u00dftiefe h-historisch
\ No newline at end of file
diff -r 1a8f19f3b776 -r c40db8e8dcae artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties Mon Mar 19 09:12:17 2018 +0100
+++ b/artifacts/src/main/resources/messages_de.properties Mon Mar 19 14:01:21 2018 +0100
@@ -906,4 +906,16 @@
sinfo.export.flow_depth_minmax.csv.header.min = Minimale Flie\u00dftiefe
sinfo.export.flow_depth_minmax.csv.header.max = Maximale Flie\u00dftiefe
-waterlevelfetcher.missing = Fehler beim Zugriff auf Wasserspiegel mit id '{0}'
\ No newline at end of file
+waterlevelfetcher.missing = Fehler beim Zugriff auf Wasserspiegel mit id '{0}'
+
+sinfo.export.csv.meta.header.sounding.current = ##METADATEN PEILUNG aktuell
+sinfo.export.csv.meta.header.sounding.historical = ##METADATEN PEILUNG historisch
+sinfo.export.csv.meta.header.waterlevel.current = ##METADATEN WASSERSPIEGELLAGE aktuell
+sinfo.export.csv.meta.header.waterlevel.historical = ##METADATEN WASSERSPIEGELLAGE historisch
+
+sinfo.export.csv.header.flowdepth.development = Flie\u00dftiefenentwicklung
+sinfo.export.csv.header.flowdepth.development.per.year = Flie\u00dftiefenent-wicklung pro Jahr
+sinfo.export.csv.header.waterlevel.difference = \u0394WSPL
+sinfo.export.csv.header.mean_bed_height.difference = \u0394MSH
+sinfo.export.csv.header.flowdepth.current = Flie\u00dftiefe h-aktuell
+sinfo.export.csv.header.flowdepth.historical = Flie\u00dftiefe h-historisch
\ No newline at end of file
More information about the Dive4Elements-commits
mailing list