Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveExporter.java @ 9431:eeea16ea0980
Added inverted attribute for y axis
author | mschaefer |
---|---|
date | Mon, 20 Aug 2018 09:42:32 +0200 |
parents | 740d65e4aa14 |
children |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5986
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5986
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5421
diff
changeset
|
9 package org.dive4elements.river.exports; |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import java.io.OutputStream; |
9312 | 12 import java.text.DateFormat; |
418
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
13 import java.text.NumberFormat; |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import java.util.ArrayList; |
701
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
664
diff
changeset
|
15 import java.util.Arrays; |
9312 | 16 import java.util.Date; |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
17 import java.util.HashMap; |
9312 | 18 import java.util.List; |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
19 import java.util.Locale; |
9312 | 20 import java.util.Map; |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import org.apache.log4j.Logger; |
9312 | 23 import org.dive4elements.artifacts.CallMeta; |
24 import org.dive4elements.artifacts.common.utils.Config; | |
25 import org.dive4elements.river.artifacts.D4EArtifact; | |
26 import org.dive4elements.river.artifacts.access.RangeAccess; | |
27 import org.dive4elements.river.artifacts.model.CalculationResult; | |
28 import org.dive4elements.river.artifacts.model.WKmsJRDataSource; | |
29 import org.dive4elements.river.artifacts.model.WQ; | |
30 import org.dive4elements.river.artifacts.model.WQKms; | |
31 import org.dive4elements.river.artifacts.resources.Resources; | |
32 import org.dive4elements.river.model.Gauge; | |
33 import org.dive4elements.river.model.River; | |
34 import org.dive4elements.river.utils.Formatter; | |
35 import org.dive4elements.river.utils.RiverUtils; | |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 import au.com.bytecode.opencsv.CSVWriter; |
9312 | 38 import net.sf.jasperreports.engine.JRException; |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
39 import net.sf.jasperreports.engine.JasperExportManager; |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
40 import net.sf.jasperreports.engine.JasperFillManager; |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
41 import net.sf.jasperreports.engine.JasperPrint; |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 /** |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 */ |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 public class ComputedDischargeCurveExporter extends AbstractExporter { |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
9312 | 48 /** The log used in this exporter. */ |
49 private static Logger log = Logger.getLogger(ComputedDischargeCurveExporter.class); | |
416
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
394
diff
changeset
|
50 |
9312 | 51 public static final String CSV_W_HEADER = "export.computed.discharge.curve.csv.header.w"; |
416
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
394
diff
changeset
|
52 |
9312 | 53 public static final String CSV_Q_HEADER = "common.export.csv.header.q"; |
54 | |
55 public static final String DEFAULT_CSV_W_HEADER = "W [NN + m]"; | |
56 public static final String DEFAULT_CSV_Q_HEADER = "Q [m\u00b3/s]"; | |
57 | |
58 public static final String PDF_HEADER_MODE = "export.computed.discharge.pdf.mode"; | |
59 public static final String PDF_HEADER_CALC_MODE = "export.computed.discharge.pdf.calc.mode"; | |
60 public static final String JASPER_FILE = "export.computed.discharge.pdf.file"; | |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
394
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
62 protected List<WQKms> data; |
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
63 |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
64 protected String wUnit; |
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
65 protected String riverUnit; |
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
66 protected String gaugeName; |
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
67 protected double gaugeDatum; |
6317
294742a49c1c
Add gauge validity information to dischargecurve exporter
Andre Heinecke <aheinecke@intevation.de>
parents:
6315
diff
changeset
|
68 protected Date validSince; |
394
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
69 |
7077
0a337f0005c2
Extended init() of OutGenerator to take name of the out to serve.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6317
diff
changeset
|
70 public ComputedDischargeCurveExporter() { |
9312 | 71 this.data = new ArrayList<>(); |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
701
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
664
diff
changeset
|
74 @Override |
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
664
diff
changeset
|
75 protected void addData(Object d) { |
715
9665d6a48f7b
Fix for flys/issue154
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
701
diff
changeset
|
76 if (d instanceof CalculationResult) { |
9312 | 77 d = ((CalculationResult) d).getData(); |
701
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
664
diff
changeset
|
78 } |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
79 WQKms referenceWQ = null; // used for gauge / unit observations |
9312 | 80 if (d instanceof WQKms[]) { |
81 this.data.addAll(Arrays.asList((WQKms[]) d)); | |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
82 // If there is a unit mix in this list |
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
83 // we are screwed anyway. |
9312 | 84 referenceWQ = ((WQKms[]) d)[0]; |
85 } else if (d instanceof WQKms) { | |
86 this.data.add((WQKms) d); | |
87 referenceWQ = (WQKms) d; | |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
88 } else { |
9312 | 89 log.warn("Can't add data for export. Unkown data type " + d.getClass().getName()); |
4610
497bc73ca64a
Fix: Don't show the warning if datatype is WQKms
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4585
diff
changeset
|
90 return; |
4585
b4a95290ec63
Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents:
2185
diff
changeset
|
91 } |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
92 if (referenceWQ != null) { |
9312 | 93 final D4EArtifact arti = (D4EArtifact) this.master; |
94 final River river = RiverUtils.getRiver(arti); | |
95 this.riverUnit = river.getWstUnit().getName(); | |
96 final RangeAccess rangeAccess = new RangeAccess(arti); | |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
97 |
9312 | 98 final double[] kms = rangeAccess.getKmRange(); |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
99 |
9312 | 100 final Gauge gauge = river.determineGaugeAtStation(kms[0]); |
8724
47199406994a
(issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents:
8383
diff
changeset
|
101 if (gauge != null) { |
9312 | 102 this.wUnit = "cm"; |
103 this.gaugeName = gauge.getName(); | |
104 this.gaugeDatum = gauge.getDatum().doubleValue(); | |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
105 |
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
106 // Now convert the data to cm because we are at gauge |
9312 | 107 final List<WQKms> newData = new ArrayList<>(); |
108 for (final WQKms d2 : this.data) { | |
109 newData.add(new WQKms(d2.getKms(), WQ.getFixedWQforExportAtGauge(d2, gauge.getDatum()))); | |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
110 } |
9312 | 111 this.data = newData; // All hail the garbage collector |
6317
294742a49c1c
Add gauge validity information to dischargecurve exporter
Andre Heinecke <aheinecke@intevation.de>
parents:
6315
diff
changeset
|
112 |
9312 | 113 this.validSince = gauge.fetchMasterDischargeTable().getTimeInterval().getStartTime(); |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
114 } else { |
9312 | 115 this.gaugeName = ""; |
116 this.validSince = null; | |
117 this.gaugeDatum = Double.NaN; | |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
118 } |
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
119 } |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 } |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 |
9312 | 122 @Override |
123 protected void writeCSVData(final CSVWriter writer) { | |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
124 log.info("ComputedDischargeCurveExporter.writeData"); |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 |
416
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
394
diff
changeset
|
126 writeCSVHeader(writer); |
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
394
diff
changeset
|
127 |
9312 | 128 final NumberFormat wf = getWFormatter(); |
129 final NumberFormat qf = getQFormatter(); | |
418
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
130 |
394
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
131 double[] res = new double[3]; |
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
132 |
9312 | 133 for (final WQKms wqkms : this.data) { |
134 final int size = wqkms.size(); | |
394
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
135 |
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
136 for (int i = 0; i < size; i++) { |
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
137 res = wqkms.get(i, res); |
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
138 |
9312 | 139 writer.writeNext(new String[] { wf.format(res[0]), qf.format(res[1]) }); |
394
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
140 } |
b9175ddea49b
Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
392
diff
changeset
|
141 } |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 } |
416
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
394
diff
changeset
|
143 |
9312 | 144 protected void writeCSVHeader(final CSVWriter writer) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
145 log.debug("ComputedDischargeCurveExporter.writeCSVHeader"); |
416
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
394
diff
changeset
|
146 |
9312 | 147 final RangeAccess access = new RangeAccess((D4EArtifact) this.master); |
148 final double[] km = access.getLocations(); | |
6308
aa4c13220fa0
Use the river unit in csv export if not converted
Andre Heinecke <aheinecke@intevation.de>
parents:
6306
diff
changeset
|
149 // If we are not at gauge (cm) use the river unit |
9312 | 150 final String realUnit = "cm".equals(this.wUnit) ? "cm" : this.riverUnit; |
151 final String header = msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { realUnit }); | |
5985
2ec6fae23bba
Be more tolerant when try to find out if a location is at a gauge position.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5981
diff
changeset
|
152 |
9312 | 153 writer.writeNext(new String[] { header, msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER) }); |
416
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
394
diff
changeset
|
154 } |
418
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
155 |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
156 /** |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
157 * Returns the number formatter for W values. |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
158 * |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
159 * @return the number formatter for W values. |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
160 */ |
9312 | 161 @Override |
418
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
162 protected NumberFormat getWFormatter() { |
9312 | 163 if ("cm".equals(this.wUnit)) { |
164 return Formatter.getFormatter(this.context, 0, 0); | |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
165 } |
9312 | 166 return Formatter.getComputedDischargeW(this.context); |
418
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
167 } |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
168 |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
169 /** |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
170 * Returns the number formatter for Q values. |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
171 * |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
172 * @return the number formatter for Q values. |
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
173 */ |
9312 | 174 @Override |
418
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
175 protected NumberFormat getQFormatter() { |
9312 | 176 return Formatter.getComputedDischargeQ(this.context); |
418
e0fec407a280
ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
416
diff
changeset
|
177 } |
2176 | 178 |
179 @Override | |
9312 | 180 protected void writePDF(final OutputStream out) { |
181 final WKmsJRDataSource source = createJRData(); | |
2185
a9a8df1473fd
Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2182
diff
changeset
|
182 |
9312 | 183 final String jasperFile = Resources.getMsg(this.context.getMeta(), JASPER_FILE, "/jasper/computed-discharge_en.jasper"); |
184 final String confPath = Config.getConfigDirectory().toString(); | |
2185
a9a8df1473fd
Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2182
diff
changeset
|
185 |
9312 | 186 final Map parameters = new HashMap(); |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
187 parameters.put("ReportTitle", "Exported Data"); |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
188 try { |
9312 | 189 final JasperPrint print = JasperFillManager.fillReport(confPath + jasperFile, parameters, source); |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
190 JasperExportManager.exportReportToPdfStream(print, out); |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
191 } |
9312 | 192 catch (final JRException je) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
193 log.warn("Error generating PDF Report!"); |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
194 je.printStackTrace(); |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
195 } |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
196 } |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
197 |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
198 protected WKmsJRDataSource createJRData() { |
9312 | 199 final WKmsJRDataSource source = new WKmsJRDataSource(); |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
200 |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
201 addMetaData(source); |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
202 addWQData(source); |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
203 |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
204 return source; |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
205 } |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
206 |
9312 | 207 protected void addMetaData(final WKmsJRDataSource source) { |
208 final CallMeta meta = this.context.getMeta(); | |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
209 |
9312 | 210 final D4EArtifact flys = (D4EArtifact) this.master; |
211 source.addMetaData("gauge", this.gaugeName); | |
212 if (!Double.isNaN(this.gaugeDatum)) { | |
213 final NumberFormat mf = Formatter.getMeterFormat(this.context); | |
214 source.addMetaData("datum", mf.format(this.gaugeDatum) + " " + this.riverUnit); | |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
215 } else { |
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
216 source.addMetaData("datum", ""); |
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
217 } |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
218 |
9312 | 219 source.addMetaData("river", RiverUtils.getRivername(flys)); |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
220 |
9312 | 221 final Locale locale = Resources.getLocale(meta); |
222 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); | |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
223 |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
224 source.addMetaData("date", df.format(new Date())); |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
225 |
9312 | 226 source.addMetaData("wUnit", "cm".equals(this.wUnit) ? "cm" : this.riverUnit); |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
227 |
9312 | 228 final RangeAccess rangeAccess = new RangeAccess(flys); |
229 final double[] kms = rangeAccess.getKmRange(); | |
230 source.addMetaData("range", Formatter.getCalculationKm(this.context.getMeta()).format(kms[0])); | |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
231 |
9312 | 232 if (!"cm".equals(this.wUnit)) { |
6317
294742a49c1c
Add gauge validity information to dischargecurve exporter
Andre Heinecke <aheinecke@intevation.de>
parents:
6315
diff
changeset
|
233 source.addMetaData("valid_since", ""); |
9312 | 234 source.addMetaData("calculation", Resources.getMsg(locale, PDF_HEADER_CALC_MODE, "Computed Discharge")); |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
235 } else { |
9312 | 236 source.addMetaData("valid_since", this.validSince == null ? "" : df.format(this.validSince)); |
237 source.addMetaData("calculation", Resources.getMsg(locale, PDF_HEADER_MODE, "Discharge")); | |
6305
40c77429319d
Update PDF/CSV export for discharge curves
Andre Heinecke <aheinecke@intevation.de>
parents:
6101
diff
changeset
|
238 } |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
239 } |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
240 |
9312 | 241 protected void addWQData(final WKmsJRDataSource source) { |
242 final NumberFormat wf = getWFormatter(); | |
243 final NumberFormat qf = getQFormatter(); | |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
244 |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
245 double[] res = new double[3]; |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
246 |
9312 | 247 for (final WQKms wqkms : this.data) { |
248 final int size = wqkms.size(); | |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
249 |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
250 for (int i = 0; i < size; i++) { |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
251 res = wqkms.get(i, res); |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
252 |
9312 | 253 source.addData(new String[] { "", // Empty, the WKmsJRDtasource stores km here. |
254 wf.format(res[0]), qf.format(res[1]) }); | |
2177
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
255 } |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
256 } |
28dbeb64ce7c
Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2176
diff
changeset
|
257 } |
392
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
258 } |
72177020db92
Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
259 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |