[Dive4elements-commits] [PATCH 05 of 12] Update PDF/CSV export for discharge curves
Wald Commits
scm-commit at wald.intevation.org
Wed Jun 12 17:47:18 CEST 2013
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1371046256 -7200
# Node ID 40c77429319d34b4500986d86e229204608a6e48
# Parent 152e1ba8e5bdfe00fc88967f1ffc26421d6c1a5e
Update PDF/CSV export for discharge curves
- Unit is now dynamic, also adds gauge and datum
- Chose output unit depending on weather we are at a gauge or not
diff -r 152e1ba8e5bd -r 40c77429319d artifacts/doc/conf/jasper/computed-discharge.jasper
Binary file artifacts/doc/conf/jasper/computed-discharge.jasper has changed
diff -r 152e1ba8e5bd -r 40c77429319d artifacts/doc/conf/jasper/computed-discharge_en.jasper
Binary file artifacts/doc/conf/jasper/computed-discharge_en.jasper has changed
diff -r 152e1ba8e5bd -r 40c77429319d artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsJRDataSource.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsJRDataSource.java Wed Jun 12 16:07:28 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsJRDataSource.java Wed Jun 12 16:10:56 2013 +0200
@@ -90,12 +90,18 @@
else if ("gauge".equals(fieldName)) {
value = metaData.get("gauge");
}
+ else if ("datum".equals(fieldName)) {
+ value = metaData.get("datum");
+ }
else if ("calculation".equals(fieldName)) {
value = metaData.get("calculation");
}
else if ("differences".equals(fieldName)) {
value = metaData.get("differences");
}
+ else if ("wUnit".equals(fieldName)) {
+ value = metaData.get("wUnit");
+ }
else if ("km".equals(fieldName)) {
value = data.get(index)[0];
}
diff -r 152e1ba8e5bd -r 40c77429319d artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveExporter.java Wed Jun 12 16:07:28 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveExporter.java Wed Jun 12 16:10:56 2013 +0200
@@ -40,11 +40,14 @@
import org.dive4elements.river.artifacts.access.RangeAccess;
import org.dive4elements.river.artifacts.model.CalculationResult;
import org.dive4elements.river.artifacts.model.GaugesFactory;
+import org.dive4elements.river.artifacts.model.WQ;
import org.dive4elements.river.artifacts.model.WQKms;
import org.dive4elements.river.artifacts.model.WKmsJRDataSource;
import org.dive4elements.river.artifacts.resources.Resources;
import org.dive4elements.river.model.Gauge;
+import org.dive4elements.river.model.River;
+
import org.dive4elements.river.utils.RiverUtils;
import org.dive4elements.river.utils.Formatter;
@@ -68,10 +71,17 @@
public static final String DEFAULT_CSV_Q_HEADER = "Q [m\u00b3/s]";
public static final String PDF_HEADER_MODE = "export.computed.discharge.pdf.mode";
+ public static final String PDF_HEADER_CALC_MODE = "export.computed.discharge.pdf.calc.mode";
public static final String JASPER_FILE = "export.computed.discharge.pdf.file";
protected List<WQKms> data;
+ protected String wUnit;
+ protected String riverUnit;
+ protected String gaugeName;
+ protected double gaugeDatum;
+ protected boolean isCalculated;
+
public void init(Document request, OutputStream out, CallContext context) {
logger.debug("ComputedDischargeCurveExporter.init");
@@ -87,19 +97,58 @@
if (d instanceof CalculationResult) {
d = ((CalculationResult)d).getData();
}
+ WQKms referenceWQ = null; // used for gauge / unit observations
if (d instanceof WQKms[]){
data.addAll(Arrays.asList((WQKms [])d));
- return;
+ // If there is a unit mix in this list
+ // we are screwed anyway.
+ referenceWQ = ((WQKms[])d)[0];
}
else if (d instanceof WQKms) {
data.add((WQKms)d);
+ referenceWQ = (WQKms)d;
+ } else {
+ logger.warn("Can't add data for export. Unkown data type " +
+ d.getClass().getName());
return;
}
- logger.warn("Can't add data for csv export. Unkown data type " +
- d.getClass().getName());
+ logger.debug("Andre 1");
+ if (referenceWQ != null) {
+ wUnit = referenceWQ.getWUnit();
+ D4EArtifact arti = (D4EArtifact)master;
+ River river = RiverUtils.getRiver(arti);
+ riverUnit = river.getWstUnit().getName();
+ RangeAccess rangeAccess = new RangeAccess(arti);
+
+ double[] kms = rangeAccess.getKmRange();
+
+ Gauge gauge = river.determineGaugeByPosition(kms[0]);
+ logger.debug("Kms 0: " + kms[0]);
+ if (Math.abs(kms[0] - gauge.getStation().doubleValue()) < 1e-4) {
+ logger.debug("At Gauge");
+ gaugeName = gauge.getName();
+ gaugeDatum = gauge.getDatum().doubleValue();
+
+ // Assumption is that values at a gauge that are in the meter
+ // reference system are calculated.
+ isCalculated = wUnit.equals("m");
+
+ // Now convert the data to cm because we are at gauge
+ List<WQKms> newData = new ArrayList<WQKms>();
+ for (WQKms d2: data) {
+ newData.add(new WQKms(d2.getKms(),
+ WQ.getFixedWQforExportAtGauge((WQ)d2, gauge.getDatum())));
+ }
+ data = newData; // All hail the garbage collector
+ wUnit = "cm";
+ logger.debug("Setting gauge / datum to: " + gaugeName + " / " + gaugeDatum);
+ } else {
+ gaugeName = "";
+ gaugeDatum = Double.NaN;
+ }
+ }
}
-
protected void writeCSVData(CSVWriter writer) {
logger.info("ComputedDischargeCurveExporter.writeData");
@@ -128,21 +177,11 @@
protected void writeCSVHeader(CSVWriter writer) {
logger.debug("ComputedDischargeCurveExporter.writeCSVHeader");
- String unit = RiverUtils.getRiver((D4EArtifact) master).getWstUnit().getName();
RangeAccess access = new RangeAccess((D4EArtifact)master);
double[] km = access.getLocations();
String header =
- msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit });
+ msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { wUnit });
- if (km != null) {
- List<Gauge>gauges = GaugesFactory.getGauges(access.getRiver());
- for (Gauge g: gauges) {
- if (Math.abs(g.getStation().doubleValue() - km[0]) < 0.0001d) {
- header = "W [cm]";
- break;
- }
- }
- }
writer.writeNext(new String[] {
header,
msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER)
@@ -156,6 +195,9 @@
* @return the number formatter for W values.
*/
protected NumberFormat getWFormatter() {
+ if (wUnit.equals("cm")) {
+ return Formatter.getFormatter(context, 0, 0);
+ }
return Formatter.getComputedDischargeW(context);
}
@@ -210,6 +252,13 @@
CallMeta meta = context.getMeta();
D4EArtifact flys = (D4EArtifact) master;
+ source.addMetaData("gauge", gaugeName);
+ if (!Double.isNaN(gaugeDatum)) {
+ NumberFormat mf = Formatter.getMeterFormat(context);
+ source.addMetaData("datum", mf.format(gaugeDatum) + " " + riverUnit);
+ } else {
+ source.addMetaData("datum", "");
+ }
source.addMetaData ("river", RiverUtils.getRivername(flys));
@@ -218,14 +267,23 @@
source.addMetaData("date", df.format(new Date()));
+ source.addMetaData("wUnit", wUnit.equals("m") ? riverUnit : "cm");
+
RangeAccess rangeAccess = new RangeAccess(flys);
double[] kms = rangeAccess.getKmRange();
source.addMetaData("range", String.valueOf(kms[0]));
- source.addMetaData("calculation", Resources.getMsg(
- locale,
- PDF_HEADER_MODE,
- "Computed Discharge"));
+ if (isCalculated) {
+ source.addMetaData("calculation", Resources.getMsg(
+ locale,
+ PDF_HEADER_CALC_MODE,
+ "Computed Discharge"));
+ } else {
+ source.addMetaData("calculation", Resources.getMsg(
+ locale,
+ PDF_HEADER_MODE,
+ "Discharge"));
+ }
}
protected void addWQData(WKmsJRDataSource source) {
diff -r 152e1ba8e5bd -r 40c77429319d artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties Wed Jun 12 16:07:28 2013 +0200
+++ b/artifacts/src/main/resources/messages.properties Wed Jun 12 16:10:56 2013 +0200
@@ -339,7 +339,8 @@
export.discharge.longitudinal.section.csv.header.cw = W corr. [NN +m]
export.discharge.longitudinal.section.csv.header.q = Q [m\u00b3/s]
export.discharge.curve.at.header = Computed Discharge Curve for {0} {0}-km: {1}
-export.discharge.curve.at.gauge.header = Discharge Table for {1}/{0} since {2} PNP[NN+m] = {3}
+export.discharge.curve.at.gauge.header = Discharge Table for {1}/{0} since {2} PNP[{4}] = {3}
+export.discharge.curve.at.gauge.calc.header = Computed Discharge Curve for {0}, Gauge: {1} PNP[{3}] = {2}
export.historical.discharge.csv.header.timerange = Timerange
export.historical.discharge.csv.header.waterlevel = Waterlevel [cm]
export.historical.discharge.csv.header.discharge = Discharge [m\u00b3/s]
@@ -351,7 +352,8 @@
export.reference_curve.csv.header.w.q = equiv. Q (m\u00b3/s)
export.waterlevel.pdf.mode = Waterlevel
-export.computed.discharge.pdf.mode = Computed Dischargecurve
+export.computed.discharge.pdf.mode = Dischargecurve
+export.computed.discharge.pdf.calc.mode = Computed Dischargecurve
export.duration.pdf.mode = Durationcurve
export.wdifferences.pdf.mode = W Differences
export.historical.discharge.pdf.mode = Historical Discharge
diff -r 152e1ba8e5bd -r 40c77429319d artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties Wed Jun 12 16:07:28 2013 +0200
+++ b/artifacts/src/main/resources/messages_de.properties Wed Jun 12 16:10:56 2013 +0200
@@ -339,7 +339,8 @@
export.discharge.longitudinal.section.csv.header.cw = W korr. [NN + m]
export.discharge.longitudinal.section.csv.header.q = Q [m\u00b3/s]
export.discharge.curve.at.header = Berechnete Abflusstafel f\u00fcr {0}, km {1}
-export.discharge.curve.at.gauge.header = Abflusstafel f\u00fcr {1}/{0} ab {2} PNP[NN+m] = {3}
+export.discharge.curve.at.gauge.header = Abflusstafel f\u00fcr {1}/{0} ab {2} PNP[{4}] = {3}
+export.discharge.curve.at.gauge.calc.header = Berechnete Abflusstafel f\u00fcr {0}, Pegel: {1} PNP[{3}] = {2}
export.historical.discharge.csv.header.timerange = Zeitraum
export.historical.discharge.csv.header.waterlevel = Wasserstand [cm]
export.historical.discharge.csv.header.discharge = Abfluss [m\u00b3/s]
@@ -353,6 +354,7 @@
export.waterlevel.pdf.mode = Wasserstand
export.computed.discharge.pdf.mode = Abflusskurve
+export.computed.discharge.pdf.calc.mode = Berechnete Abflusskurve
export.duration.pdf.mode = Dauerlinie
export.wdifferences.pdf.mode = W Differenzen
export.historical.discharge.pdf.mode = Historischer Abfluss
diff -r 152e1ba8e5bd -r 40c77429319d artifacts/src/main/resources/messages_de_DE.properties
--- a/artifacts/src/main/resources/messages_de_DE.properties Wed Jun 12 16:07:28 2013 +0200
+++ b/artifacts/src/main/resources/messages_de_DE.properties Wed Jun 12 16:10:56 2013 +0200
@@ -335,7 +335,8 @@
export.discharge.longitudinal.section.csv.header.w = W [NN + m]
export.discharge.longitudinal.section.csv.header.cw = W korr. [NN + m]
export.discharge.longitudinal.section.csv.header.q = Q [m\u00b3/s]
-export.discharge.curve.at.gauge.header = Abflusstafel f\u00fcr {1}/{0} ab {2} PNP[NN+m] = {3}
+export.discharge.curve.at.gauge.header = Abflusstafel f\u00fcr {1}/{0} ab {2} PNP[{4}] = {3}
+export.discharge.curve.at.gauge.calc.header = Berechnete Abflusstafel f\u00fcr {0}, Pegel: {1} PNP[{3}] = {2}
export.discharge.curve.at.header = Berechnete Abflusstafel f\u00fcr {0}, km {1}
export.historical.discharge.csv.header.timerange = Zeitraum
export.historical.discharge.csv.header.waterlevel = Wasserstand [cm]
@@ -349,6 +350,7 @@
export.waterlevel.pdf.mode = Wasserstand
export.computed.discharge.pdf.mode = Abflusskurve
+export.computed.discharge.pdf.calc.mode = Berechnete Abflusskurve
export.duration.pdf.mode = Dauerline
export.wdifferences.pdf.mode = W Differenzen
export.historical.discharge.pdf.mode = Historischer Abfluss
diff -r 152e1ba8e5bd -r 40c77429319d artifacts/src/main/resources/messages_en.properties
--- a/artifacts/src/main/resources/messages_en.properties Wed Jun 12 16:07:28 2013 +0200
+++ b/artifacts/src/main/resources/messages_en.properties Wed Jun 12 16:10:56 2013 +0200
@@ -341,7 +341,8 @@
export.discharge.longitudinal.section.csv.header.cw = W corr. [NN + m]
export.discharge.longitudinal.section.csv.header.q = Q [m\u00b3/s]
export.discharge.curve.at.header = Computed Discharge Curve for {0} {0}-km: {1}
-export.discharge.curve.at.gauge.header = Dischargetable for {1}/{0} since {2} Datum[NN+m] = {3}
+export.discharge.curve.at.gauge.header = Dischargetable for {1}/{0} since {2} Datum[{4}] = {3}
+export.discharge.curve.at.gauge.calc.header = Computed Discharge Curve for {0}, Gauge: {1} Datum[{3}] = {2}
export.historical.discharge.csv.header.timerange = Timerange
export.historical.discharge.csv.header.waterlevel = Waterlevel [cm]
export.historical.discharge.csv.header.discharge = Discharge [m\u00b3/s]
@@ -353,7 +354,8 @@
export.reference_curve.csv.header.w.q = equiv. Q (m\u00b3/s)
export.waterlevel.pdf.mode = Waterlevel
-export.computed.discharge.pdf.mode = Computed Dischargecurve
+export.computed.discharge.pdf.mode = Dischargecurve
+export.computed.discharge.pdf.calc.mode = Computed Dischargecurve
export.duration.pdf.mode = Durationcurve
export.wdifferences.pdf.mode = W Differences
export.historical.discharge.pdf.mode = Historical Discharge
More information about the Dive4elements-commits
mailing list