Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/exports/fixings/DeltaWtExporter.java @ 9322:a49fe0ebb297
bundu bezugswst pdf-export details
author | gernotbelger |
---|---|
date | Fri, 27 Jul 2018 11:13:57 +0200 |
parents | 8024e51e828a |
children | ddcd52d239cd |
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:
5863
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:
5863
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:
5603
diff
changeset
|
9 package org.dive4elements.river.exports.fixings; |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.io.IOException; |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.io.OutputStream; |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import java.text.DateFormat; |
3398
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
14 import java.text.MessageFormat; |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import java.text.NumberFormat; |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import java.util.ArrayList; |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import java.util.List; |
5603
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
18 import java.util.TreeMap; |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import org.apache.log4j.Logger; |
9082 | 21 import org.dive4elements.artifacts.CallMeta; |
22 import org.dive4elements.river.artifacts.D4EArtifact; | |
9306 | 23 import org.dive4elements.river.artifacts.access.RangeAccess; |
9082 | 24 import org.dive4elements.river.artifacts.access.RiverAccess; |
9306 | 25 import org.dive4elements.river.artifacts.common.DefaultCalculationResults; |
26 import org.dive4elements.river.artifacts.common.ExportContextPDF; | |
27 import org.dive4elements.river.artifacts.common.GeneralResultType; | |
28 import org.dive4elements.river.artifacts.common.JasperReporter; | |
29 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; | |
9082 | 30 import org.dive4elements.river.artifacts.model.CalculationResult; |
31 import org.dive4elements.river.artifacts.model.fixings.AnalysisPeriod; | |
32 import org.dive4elements.river.artifacts.model.fixings.FixAnalysisResult; | |
33 import org.dive4elements.river.artifacts.model.fixings.QWD; | |
34 import org.dive4elements.river.artifacts.resources.Resources; | |
9306 | 35 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; |
36 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | |
9082 | 37 import org.dive4elements.river.exports.AbstractExporter; |
38 import org.dive4elements.river.utils.Formatter; | |
39 import org.dive4elements.river.utils.KMIndex; | |
40 | |
41 import au.com.bytecode.opencsv.CSVWriter; | |
9306 | 42 import net.sf.jasperreports.engine.JRException; |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
3644
fa633f6a5fd9
smaller part of issue825 fixed (column ordering of dwt-export).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3415
diff
changeset
|
44 /** Exports fixation analysis deltaw(t) computation results to csv. */ |
9082 | 45 public class DeltaWtExporter extends AbstractExporter { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
46 /** Private log. */ |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 private static Logger log = Logger.getLogger(DeltaWtExporter.class); |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
9306 | 49 private static final String JASPER_FILE = "/jasper/templates/fixanalysis.delta_wt.jrxml"; |
50 | |
9082 | 51 public static final String CSV_KM_HEADER = "export.fixings.deltawt.csv.header.km"; |
3397
6d1740533810
FixA: Added discharge column to DeltaW(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
52 |
9082 | 53 public static final String CSV_DELTA_W_HEADER = "export.fixings.deltawt.csv.header.deltaw"; |
3402
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
54 |
9082 | 55 public static final String CSV_Q_HEADER = "export.fixings.deltawt.csv.header.q"; |
3398
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
56 |
9082 | 57 public static final String CSV_W_HEADER = "export.fixings.deltawt.csv.header.w"; |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
9082 | 59 public static final String CSV_TRANGE_HEADER = "export.fixings.deltawt.csv.header.time.range"; |
60 | |
61 public static final String CSV_T_HEADER = "export.fixings.deltawt.csv.header.t"; | |
62 | |
63 public static final String CSV_T_FORMAT = "export.fixings.deltawt.csv.t.format"; | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 public static final String DEFAULT_CSV_KM_HEADER = "km"; |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 public static final String DEFAULT_CSV_DELTA_W_HEADER = "\u0394 W [cm]"; |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
3402
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
69 public static final String DEFAULT_CSV_W_HEADER = "Wasserstand [m]"; |
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
70 |
3397
6d1740533810
FixA: Added discharge column to DeltaW(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
71 public static final String DEFAULT_CSV_Q_HEADER = "Abfluss [m\u00b3/s]"; |
6d1740533810
FixA: Added discharge column to DeltaW(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
72 |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 public static final String DEFAULT_CSV_T_HEADER = "Datum"; |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 |
9082 | 75 public static final String DEFAULT_CSV_TRANGE_DESC_HEADER = "Status"; |
3398
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
76 |
9082 | 77 public static final String CSV_REFERENCE = "export.fixings.deltawt.csv.reference"; |
3398
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
78 |
9082 | 79 public static final String CSV_ANALYSIS = "export.fixings.deltawt.csv.analysis"; |
3402
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
80 |
9082 | 81 public static final String DEFAULT_CSV_REFERENCE = "B"; |
3398
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
82 |
9082 | 83 public static final String DEFAULT_CSV_ANALYSIS = "A{0,number,integer}"; |
84 | |
85 public static final String DEFAULT_CSV_T_FORMAT = "dd.MM.yyyy"; | |
86 | |
87 protected List<KMIndex<AnalysisPeriod[]>> analysisPeriods; | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 protected List<KMIndex<QWD[]>> referenceEvents; |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 |
7077
0a337f0005c2
Extended init() of OutGenerator to take name of the out to serve.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
91 public DeltaWtExporter() { |
9082 | 92 this.analysisPeriods = new ArrayList<>(); |
93 this.referenceEvents = new ArrayList<>(); | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 @Override |
9082 | 97 protected void addData(final Object d) { |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 log.debug("DeltaWtExporter.addData"); |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 if (!(d instanceof CalculationResult)) { |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 log.warn("Invalid data type"); |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 return; |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
9082 | 104 final Object data = ((CalculationResult) d).getData(); |
3415
e3c7a3228bc2
FixA: Renamed FixResult to FixAnalysisResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3402
diff
changeset
|
105 if (!(data instanceof FixAnalysisResult)) { |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 log.warn("Invalid data stored in result."); |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 } |
9082 | 108 final FixAnalysisResult result = (FixAnalysisResult) data; |
109 this.analysisPeriods.add(result.getAnalysisPeriods()); | |
110 this.referenceEvents.add(result.getReferenced()); | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 @Override |
9082 | 114 protected void writeCSVData(final CSVWriter writer) throws IOException { |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 |
9082 | 116 final boolean debug = log.isDebugEnabled(); |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 writeCSVHeader(writer); |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
9306 | 120 final TreeMap<Double, ArrayList<String[]>> sorted = getRows(); |
121 for (final ArrayList<String[]> list : sorted.values()) { | |
122 for (final String[] row : list) { | |
123 writer.writeNext(row); | |
124 } | |
125 } | |
126 | |
127 writer.flush(); | |
128 } | |
129 | |
130 private TreeMap<Double, ArrayList<String[]>> getRows() { | |
9082 | 131 final NumberFormat kmF = getKMFormatter(); |
132 final NumberFormat dwF = getDeltaWFormatter(); | |
133 final NumberFormat qF = getQFormatter(); | |
134 final NumberFormat wF = getWFormatter(); | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 |
9082 | 136 final DateFormat dF = getDateFormatter(); |
3398
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
137 |
9082 | 138 final TreeMap<Double, ArrayList<String[]>> sorted = new TreeMap<>(); |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 |
9082 | 140 final String referenceS = getReference(); |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 |
9082 | 142 for (final KMIndex<QWD[]> reference : this.referenceEvents) { |
5603
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
143 |
9082 | 144 for (final KMIndex.Entry<QWD[]> kmEntry : reference) { |
145 | |
146 final Double km = kmEntry.getKm(); | |
147 | |
148 ArrayList<String[]> list = sorted.get(km); | |
5603
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
149 |
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
150 if (list == null) { |
9082 | 151 list = new ArrayList<>(); |
5603
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
152 sorted.put(km, list); |
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
153 } |
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
154 |
9082 | 155 final String kmS = kmF.format(kmEntry.getKm()); |
156 for (final QWD qwd : kmEntry.getValue()) { | |
157 final String deltaWS = dwF.format(qwd.getDeltaW()); | |
158 final String qS = qF.format(qwd.getQ()); | |
159 final String wS = wF.format(qwd.getW()); | |
160 final String dateS = dF.format(qwd.getDate()); | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 |
9082 | 162 list.add(new String[] { kmS, dateS, qS, wS, referenceS, deltaWS }); |
5603
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
163 } |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 |
9306 | 167 // if (debug) { |
168 // log.debug("AnalysisPeriods: " + this.analysisPeriods.size()); | |
169 // } | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 |
9082 | 171 final String analysisTemplate = getAnalysisTemplate(); |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 |
9082 | 173 for (final KMIndex<AnalysisPeriod[]> periods : this.analysisPeriods) { |
4736
b195fede1c3b
Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4238
diff
changeset
|
174 |
9082 | 175 for (final KMIndex.Entry<AnalysisPeriod[]> kmEntry : periods) { |
5603
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
176 |
9082 | 177 final Double km = kmEntry.getKm(); |
178 | |
179 ArrayList<String[]> list = sorted.get(km); | |
5603
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
180 |
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
181 if (list == null) { |
9082 | 182 list = new ArrayList<>(); |
5603
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
183 sorted.put(km, list); |
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
184 } |
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
185 |
9082 | 186 final String kmS = kmF.format(kmEntry.getKm()); |
4238
50273de4cf63
flys/issue825/2 Fix labeling of Analysisperiods (like A1, A2....)
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3915
diff
changeset
|
187 int analysisCount = 1; |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 |
9082 | 189 for (final AnalysisPeriod period : kmEntry.getValue()) { |
4238
50273de4cf63
flys/issue825/2 Fix labeling of Analysisperiods (like A1, A2....)
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3915
diff
changeset
|
190 // Typically resulting in A1,A2... |
9082 | 191 final String analyisS = MessageFormat.format(analysisTemplate, analysisCount); |
192 final QWD[] qwds = period.getQWDs(); | |
3644
fa633f6a5fd9
smaller part of issue825 fixed (column ordering of dwt-export).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3415
diff
changeset
|
193 |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 if (qwds != null) { |
9082 | 195 for (final QWD qwd : qwds) { |
196 final String deltaWS = dwF.format(qwd.getDeltaW()); | |
197 final String qS = qF.format(qwd.getQ()); | |
198 final String wS = wF.format(qwd.getW()); | |
199 final String dateS = dF.format(qwd.getDate()); | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 |
9082 | 201 list.add(new String[] { kmS, dateS, qS, wS, analyisS, deltaWS }); |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 } |
4238
50273de4cf63
flys/issue825/2 Fix labeling of Analysisperiods (like A1, A2....)
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3915
diff
changeset
|
204 ++analysisCount; |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 } |
9306 | 208 return sorted; |
5603
47e5bc64d3de
FixA: tab output ist now grouped by km and periods. Fixes flys/issue1163
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
209 |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 |
3644
fa633f6a5fd9
smaller part of issue825 fixed (column ordering of dwt-export).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3415
diff
changeset
|
212 /** Template to create "State" strings like A1,A2... */ |
3398
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
213 protected String getAnalysisTemplate() { |
9082 | 214 return Resources.getMsg(this.context.getMeta(), CSV_ANALYSIS, DEFAULT_CSV_ANALYSIS); |
3398
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
215 } |
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
216 |
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
217 protected String getReference() { |
9082 | 218 return Resources.getMsg(this.context.getMeta(), CSV_REFERENCE, DEFAULT_CSV_REFERENCE); |
3398
7f9fe694f8d1
FixA: Added time range column to Delta W(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3397
diff
changeset
|
219 } |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 protected NumberFormat getKMFormatter() { |
9082 | 222 return Formatter.getFixDeltaWKM(this.context); |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 protected NumberFormat getDeltaWFormatter() { |
9082 | 226 return Formatter.getFixDeltaWDeltaW(this.context); |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 |
9082 | 229 @Override |
3397
6d1740533810
FixA: Added discharge column to DeltaW(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
230 protected NumberFormat getQFormatter() { |
9082 | 231 return Formatter.getFixDeltaWQ(this.context); |
3397
6d1740533810
FixA: Added discharge column to DeltaW(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
232 } |
6d1740533810
FixA: Added discharge column to DeltaW(t) CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
233 |
9082 | 234 @Override |
3402
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
235 protected NumberFormat getWFormatter() { |
9082 | 236 return Formatter.getFixDeltaWW(this.context); |
3402
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
237 } |
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
238 |
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
239 protected DateFormat getDateFormatter() { |
9082 | 240 final CallMeta meta = this.context.getMeta(); |
241 return Formatter.getDateFormatter(meta, Resources.getMsg(meta, CSV_T_FORMAT, DEFAULT_CSV_T_FORMAT)); | |
3402
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
242 } |
0336132ec9db
Adjusted Delta W(t) CSV exporter to customers wishes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3398
diff
changeset
|
243 |
9082 | 244 protected void writeCSVHeader(final CSVWriter writer) { |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 log.debug("DeltaWtExporter.writeCSVHeader"); |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 |
9082 | 247 /* |
248 * issue825 | |
249 * km; Ereignis, Abfluss, GEMESSENER Wasserstand; | |
250 * Status (RECHTSBÜNDIG), del W | |
251 */ | |
252 final RiverAccess river = new RiverAccess((D4EArtifact) this.master); | |
253 final String unit = river.getRiver().getWstUnit().getName(); | |
3644
fa633f6a5fd9
smaller part of issue825 fixed (column ordering of dwt-export).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3415
diff
changeset
|
254 |
9082 | 255 writer.writeNext(new String[] { msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), msg(CSV_T_HEADER, DEFAULT_CSV_T_HEADER), |
256 msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER), msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit }), | |
257 msg(CSV_TRANGE_HEADER, DEFAULT_CSV_TRANGE_DESC_HEADER), msg(CSV_DELTA_W_HEADER, DEFAULT_CSV_DELTA_W_HEADER) }); | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 } |
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 |
9306 | 260 private void addMetaData(final MetaAndTableJRDataSource source) { |
261 final D4EArtifact flys = (D4EArtifact) this.master; | |
262 final String user = CalculationUtils.findArtifactUser(this.context, flys); | |
263 final RangeAccess ra = new RangeAccess(flys); | |
264 final RiverInfo ri = new RiverInfo(ra.getRiver()); | |
265 | |
266 final DefaultCalculationResults results = new DefaultCalculationResults(msg("calculation.analysis"), user, ri, ra.getRange()); | |
267 final ExportContextPDF contextPdf = new ExportContextPDF(this.context, results); | |
268 contextPdf.addJRMetaDataDefaults(source); | |
9322 | 269 contextPdf.addJRMetaDataForModules(source); |
9306 | 270 |
271 /* column headings */ | |
272 contextPdf.addJRMetadata(source, "station_header", GeneralResultType.station); | |
273 contextPdf.addJRMetadata(source, "fix_date", msg(CSV_T_HEADER)); | |
274 contextPdf.addJRMetadata(source, "fix_q", msg(CSV_Q_HEADER)); | |
275 contextPdf.addJRMetadata(source, "fix_w", msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { ri.getWstUnit() })); | |
276 contextPdf.addJRMetadata(source, "fix_state", msg(CSV_TRANGE_HEADER)); | |
277 contextPdf.addJRMetadata(source, "fix_delta_w", msg(CSV_DELTA_W_HEADER)); | |
278 } | |
279 | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 @Override |
9082 | 281 protected void writePDF(final OutputStream out) { |
9306 | 282 final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource(); |
283 final String jasperFile = Resources.getMsg(this.context.getMeta(), JASPER_FILE); | |
284 addMetaData(source); | |
285 try { | |
286 final TreeMap<Double, ArrayList<String[]>> sorted = getRows(); // Custom Result could be nice, too... | |
287 for (final ArrayList<String[]> list : sorted.values()) { | |
288 for (final String[] row : list) { | |
289 source.addData(row); | |
290 } | |
291 } | |
292 final JasperReporter reporter = new JasperReporter(); | |
293 reporter.addReport(jasperFile, source); | |
294 reporter.exportPDF(out); | |
295 } | |
296 catch (final JRException je) { | |
297 log.warn("Error generating PDF Report!", je); | |
298 } | |
3216
a46910e61dfb
FixA: Moved DeltaWtExporter to fixings exporter package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 } |
9306 | 300 } |