Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthExporter.java @ 8946:5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
author | gernotbelger |
---|---|
date | Tue, 13 Mar 2018 18:49:33 +0100 |
parents | 9c02733a1b3c |
children | a4f1ac81f26d |
rev | line source |
---|---|
8854 | 1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts.sinfo.flowdepth; | |
10 | |
11 import java.util.ArrayList; | |
12 import java.util.Collection; | |
13 | |
8877 | 14 import org.apache.commons.lang.StringUtils; |
8854 | 15 import org.apache.log4j.Logger; |
8928 | 16 import org.dive4elements.river.artifacts.sinfo.SInfoI18NStrings; |
17 import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoExporter; | |
8894 | 18 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; |
8854 | 19 import org.dive4elements.river.artifacts.sinfo.util.MetaAndTableJRDataSource; |
8894 | 20 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
21 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; | |
8882 | 22 import org.dive4elements.river.utils.RiverUtils; |
8854 | 23 |
24 import au.com.bytecode.opencsv.CSVWriter; | |
25 | |
26 /** | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
27 * Generates different output formats (csv, pdf) of data that resulted from a flow depths min/max computation. |
8854 | 28 * |
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
30 * @author Gernot Belger | |
31 */ | |
32 // REMARK: must be public because its registered in generators.xml | |
8928 | 33 public class FlowDepthExporter extends AbstractSInfoExporter<FlowDepthRow, FlowDepthCalculationResult, FlowDepthCalculationResults> { |
8854 | 34 |
8877 | 35 /** The log used in this exporter. */ |
8854 | 36 private static Logger log = Logger.getLogger(FlowDepthExporter.class); |
37 | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
38 private static final String CSV_FLOWDEPTHMINMAX_HEADER = "sinfo.export.flow_depth_minmax.csv.header.flowdepthminmax"; |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
39 |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
40 private static final String CSV_FLOWDEPTHTKHMINMAX_HEADER = "sinfo.export.flow_depth_minmax.csv.header.flowdepthTkh"; |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
41 |
8854 | 42 private static final String CSV_TKH_HEADER = "sinfo.export.flow_depth.csv.header.tkh"; |
8928 | 43 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
44 private static final String JASPER_FILE = "/jasper/sinfo.flowdepthminmax.jasper"; |
8863 | 45 |
8928 | 46 @Override |
47 protected Logger getLog() { | |
48 return log; | |
8863 | 49 } |
8877 | 50 |
8854 | 51 @Override |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
52 protected void writeCSVGlobalMetadata(final CSVWriter writer, final FlowDepthCalculationResults results) { |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
53 log.info("FlowDepthExporter.writeCSVMeta"); |
8877 | 54 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
55 super.writeCSVGlobalMetadataDefaults(writer, results); |
8877 | 56 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
57 writer.writeNext(new String[] { "" }); |
8877 | 58 } |
8854 | 59 |
8928 | 60 @Override |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
61 protected void writeCSVResultMetadata(final CSVWriter writer, final FlowDepthCalculationResults results, final FlowDepthCalculationResult result) { |
8854 | 62 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
63 final BedHeightInfo sounding = result.getSounding(); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
64 super.writeCSVSoundingMetadata(writer, sounding); |
8854 | 65 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
66 final WstInfo wst = result.getWst(); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
67 super.writeCSVWaterlevelMetadata(writer, wst); |
8854 | 68 } |
69 | |
8877 | 70 /** |
8854 | 71 * Write the header, with different headings depending on whether at a |
72 * gauge or at a location. | |
8877 | 73 * |
74 * @param river | |
75 * @param useTkh | |
8854 | 76 */ |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
77 |
8928 | 78 @Override |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
79 protected void writeCSVHeader(final CSVWriter writer, final FlowDepthCalculationResults results, final RiverInfo river) { |
8854 | 80 log.info("FlowDepthExporter.writeCSVHeader"); |
81 | |
82 final Collection<String> header = new ArrayList<>(11); | |
8877 | 83 |
8928 | 84 header.add(msg(SInfoI18NStrings.CSV_KM_HEADER)); |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
85 header.add(msgUnit(CSV_FLOWDEPTHMINMAX_HEADER, SInfoI18NStrings.UNIT_M)); |
8928 | 86 if (getData().isUseTkh()) { |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
87 header.add(msgUnit(CSV_FLOWDEPTHTKHMINMAX_HEADER, SInfoI18NStrings.UNIT_M)); |
8928 | 88 header.add(msgUnit(CSV_TKH_HEADER, SInfoI18NStrings.UNIT_CM)); |
8854 | 89 } |
8863 | 90 |
8928 | 91 header.add(msgUnit(SInfoI18NStrings.CSV_WATERLEVEL_HEADER, river.getWstUnit())); |
92 header.add(msgUnit(SInfoI18NStrings.CSV_DISCHARGE_HEADER, SInfoI18NStrings.UNIT_CUBIC_M)); | |
93 header.add(msg(SInfoI18NStrings.CSV_LABEL_HEADER)); | |
94 header.add(msg(SInfoI18NStrings.CSV_GAUGE_HEADER)); | |
95 header.add(msgUnit(SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER, river.getWstUnit())); | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
96 header.add(msg(SInfoI18NStrings.CSV_SOUNDING_HEADER)); |
8928 | 97 header.add(msg(SInfoI18NStrings.CSV_LOCATION_HEADER)); |
8854 | 98 |
8877 | 99 writer.writeNext(header.toArray(new String[header.size()])); |
8854 | 100 } |
101 | |
8928 | 102 @Override |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
103 protected String[] formatCSVRow(final FlowDepthCalculationResults results, final FlowDepthRow row) { |
8928 | 104 return formatFlowDepthRow(row); |
105 } | |
106 | |
8854 | 107 /** |
108 * Format a row of a flow depth result into an array of string, both used by csv and pdf | |
8877 | 109 * |
110 * @param useTkh | |
8854 | 111 */ |
8928 | 112 private String[] formatFlowDepthRow(final FlowDepthRow row) { |
8854 | 113 |
8877 | 114 final Collection<String> lines = new ArrayList<>(11); |
8854 | 115 |
8877 | 116 // Fluss-km |
117 lines.add(getKmFormatter().format(row.getStation())); | |
118 | |
119 // Fließtiefe [m] | |
120 lines.add(getFlowDepthFormatter().format(row.getFlowDepth())); | |
121 | |
8928 | 122 if (getData().isUseTkh()) { |
8877 | 123 // Fließtiefe mit TKH [m] |
124 lines.add(getFlowDepthFormatter().format(row.getFlowDepthWithTkh())); | |
125 | |
126 // TKH [cm] | |
127 lines.add(getTkhFormatter().format(row.getTkh())); | |
128 } | |
129 | |
130 // Wasserstand [NN + m] | |
131 lines.add(getW2Formatter().format(row.getWaterlevel())); | |
132 | |
133 // Q [m³/s] | |
134 final double discharge = row.getDischarge(); | |
8884 | 135 if (Double.isNaN(discharge)) |
8877 | 136 lines.add(StringUtils.EMPTY); |
8884 | 137 else { |
8882 | 138 final double roundedDischarge = RiverUtils.roundQ(discharge); |
139 lines.add(getQFormatter().format(roundedDischarge)); | |
140 } | |
8877 | 141 |
142 // Bezeichnung | |
143 lines.add(row.getWaterlevelLabel()); | |
144 | |
145 // Bezugspegel | |
146 lines.add(row.getGauge()); | |
147 | |
148 // Mittlere Sohlhöhe [NN + m] | |
149 lines.add(getMeanBedHeighFormatter().format(row.getMeanBedHeight())); | |
150 | |
151 // Peilung/Epoche | |
152 lines.add(row.getSoundageLabel()); | |
153 | |
154 // Lage | |
155 lines.add(row.getLocation()); | |
156 | |
157 return lines.toArray(new String[lines.size()]); | |
8854 | 158 } |
8877 | 159 |
8928 | 160 @Override |
161 protected final String getJasperFile() { | |
162 return JASPER_FILE; | |
8854 | 163 } |
164 | |
8877 | 165 @Override |
8928 | 166 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final FlowDepthCalculationResults results) { |
8854 | 167 |
8877 | 168 /* general metadata */ |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
169 super.addJRMetaDataDefaults(source, results); |
8854 | 170 |
8863 | 171 /* column headings */ |
8928 | 172 source.addMetaData("station_header", msg(SInfoI18NStrings.CSV_KM_HEADER)); |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
173 source.addMetaData("flowdepth_header", msg(CSV_FLOWDEPTHMINMAX_HEADER)); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
174 source.addMetaData("flowdepth_tkh_header", msg(CSV_FLOWDEPTHTKHMINMAX_HEADER)); |
8863 | 175 source.addMetaData("tkh_header", msg(CSV_TKH_HEADER)); |
8928 | 176 source.addMetaData("waterlevel_header", msg(SInfoI18NStrings.CSV_WATERLEVEL_HEADER)); |
177 source.addMetaData("discharge_header", msg(SInfoI18NStrings.CSV_DISCHARGE_HEADER)); | |
178 source.addMetaData("waterlevel_name_header", msg(SInfoI18NStrings.CSV_LABEL_HEADER)); | |
179 source.addMetaData("gauge_header", msg(SInfoI18NStrings.CSV_GAUGE_HEADER)); | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
180 source.addMetaData("bedheight_header", msg(SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER_SHORT)); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
181 source.addMetaData("sounding_name_header", msg(SInfoI18NStrings.CSV_SOUNDING_HEADER)); |
8928 | 182 source.addMetaData("location_header", msg(SInfoI18NStrings.CSV_LOCATION_HEADER)); |
8854 | 183 } |
184 | |
8928 | 185 @Override |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
186 protected String[] formatPDFRow(final FlowDepthCalculationResults results, final FlowDepthRow row) { |
8928 | 187 return formatFlowDepthRow(row); |
8877 | 188 } |
8928 | 189 } |