8946
|
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.flowdepthminmax; |
|
10 |
|
11 import java.util.ArrayList; |
|
12 import java.util.Collection; |
|
13 |
|
14 import org.apache.log4j.Logger; |
|
15 import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoExporter; |
8948
|
16 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultRow; |
|
17 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
8946
|
18 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; |
|
19 import org.dive4elements.river.artifacts.sinfo.util.MetaAndTableJRDataSource; |
|
20 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
|
21 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; |
|
22 |
|
23 import au.com.bytecode.opencsv.CSVWriter; |
|
24 |
|
25 /** |
|
26 * Generates different output formats (csv, pdf) of data that resulted from a flow depths computation. |
|
27 * |
|
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
|
29 * @author Gernot Belger |
|
30 */ |
|
31 // REMARK: must be public because its registered in generators.xml |
8948
|
32 public class FlowDepthMinMaxExporter extends AbstractSInfoExporter<FlowDepthMinMaxCalculationResult, FlowDepthMinMaxCalculationResults> { |
8946
|
33 |
|
34 /** The log used in this exporter. */ |
|
35 private static Logger log = Logger.getLogger(FlowDepthMinMaxExporter.class); |
|
36 |
8948
|
37 private static final String JASPER_FILE = "/jasper/sinfo.flowdepthminmax.jasper"; |
8946
|
38 |
|
39 @Override |
|
40 protected Logger getLog() { |
|
41 return log; |
|
42 } |
|
43 |
|
44 @Override |
|
45 protected void writeCSVResultMetadata(final CSVWriter writer, final FlowDepthMinMaxCalculationResults results, |
|
46 final FlowDepthMinMaxCalculationResult result) { |
|
47 |
|
48 final BedHeightInfo sounding = result.getAnySounding(); |
|
49 super.writeCSVSoundingMetadata(writer, sounding); |
|
50 |
|
51 final WstInfo wst = result.getWst(); |
|
52 writeCSVWaterlevelMetadata(writer, wst); |
|
53 } |
|
54 |
|
55 @Override |
|
56 protected void writeCSVGlobalMetadata(final CSVWriter writer, final FlowDepthMinMaxCalculationResults results) { |
|
57 |
|
58 super.writeCSVGlobalMetadataDefaults(writer, results); |
|
59 |
|
60 writer.writeNext(new String[] { "" }); |
|
61 } |
|
62 |
|
63 /** |
|
64 * Write the header, with different headings depending on whether at a |
|
65 * gauge or at a location. |
|
66 * |
|
67 * @param river |
|
68 * @param useTkh |
|
69 */ |
|
70 @Override |
|
71 protected void writeCSVHeader(final CSVWriter writer, final FlowDepthMinMaxCalculationResults results, final RiverInfo river) { |
|
72 log.info("FlowDepthExporter.writeCSVHeader"); |
|
73 |
|
74 final Collection<String> header = new ArrayList<>(11); |
|
75 |
8948
|
76 header.add(msg(SInfoResultType.station.getCsvHeader())); |
|
77 header.add(msgUnit(SInfoResultType.flowdepthmin.getCsvHeader(), SInfoResultType.flowdepthmin.getUnit())); |
|
78 header.add(msgUnit(SInfoResultType.flowdepthmax.getCsvHeader(), SInfoResultType.flowdepthmax.getUnit())); |
|
79 header.add(msgUnit(SInfoResultType.waterlevel.getCsvHeader(), river.getWstUnit())); |
|
80 header.add(msgUnit(SInfoResultType.discharge.getCsvHeader(), SInfoResultType.discharge.getUnit())); |
|
81 header.add(msg(SInfoResultType.waterlevelLabel.getCsvHeader())); |
|
82 header.add(msg(SInfoResultType.gaugeLabel.getCsvHeader())); |
|
83 header.add(msgUnit(SInfoResultType.meanBedHeight.getCsvHeader(), river.getWstUnit())); |
|
84 header.add(msg(SInfoResultType.soundingLabel.getCsvHeader())); |
|
85 header.add(msg(SInfoResultType.location.getCsvHeader())); |
8946
|
86 |
|
87 writer.writeNext(header.toArray(new String[header.size()])); |
|
88 } |
|
89 |
|
90 @Override |
8948
|
91 protected String[] formatCSVRow(final FlowDepthMinMaxCalculationResults results, final FlowDepthMinMaxCalculationResult result, final SInfoResultRow row) { |
|
92 return formatRow(result, row); |
8946
|
93 } |
|
94 |
|
95 /** |
|
96 * Format a row of a flow depth result into an array of string, both used by csv and pdf |
|
97 * |
8948
|
98 * @param result |
|
99 * |
8946
|
100 * @param useTkh |
|
101 */ |
8948
|
102 private String[] formatRow(final FlowDepthMinMaxCalculationResult result, final SInfoResultRow row) { |
8946
|
103 |
8948
|
104 final Collection<String> lines = new ArrayList<>(10); |
8946
|
105 |
8948
|
106 lines.add(row.exportValue(this.context, SInfoResultType.station)); |
8946
|
107 |
8948
|
108 // REMARK: null check as pdf will call this with null and in that case we show all columns (to avoid multiple jasper |
|
109 // FIXME: does not work like this: we may have several pairs of min/max; so we need to look at all of them? |
|
110 // templates) |
|
111 // if (result == null || result.getMinSounding() != null) |
|
112 lines.add(row.exportValue(this.context, SInfoResultType.flowdepthmin)); |
|
113 // if (result == null || result.getMaxSounding() != null) |
|
114 lines.add(row.exportValue(this.context, SInfoResultType.flowdepthmax)); |
8946
|
115 |
8948
|
116 lines.add(row.exportValue(this.context, SInfoResultType.waterlevel)); |
|
117 lines.add(row.exportValue(this.context, SInfoResultType.discharge)); |
|
118 lines.add(row.exportValue(this.context, SInfoResultType.waterlevelLabel)); |
|
119 lines.add(row.exportValue(this.context, SInfoResultType.gaugeLabel)); |
|
120 lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight)); |
|
121 lines.add(row.exportValue(this.context, SInfoResultType.soundingLabel)); |
|
122 lines.add(row.exportValue(this.context, SInfoResultType.location)); |
8946
|
123 |
|
124 return lines.toArray(new String[lines.size()]); |
|
125 } |
|
126 |
|
127 @Override |
|
128 protected final String getJasperFile() { |
|
129 return JASPER_FILE; |
|
130 } |
|
131 |
|
132 @Override |
|
133 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final FlowDepthMinMaxCalculationResults results) { |
|
134 |
|
135 /* general metadata */ |
|
136 super.addJRMetaDataDefaults(source, results); |
|
137 |
|
138 /* column headings */ |
8948
|
139 source.addMetaData("station_header", msg(SInfoResultType.station.getCsvHeader())); |
|
140 source.addMetaData("flowdepthmin_header", msg(SInfoResultType.flowdepthmin.getCsvHeader())); |
|
141 source.addMetaData("flowdepthmax_header", msg(SInfoResultType.flowdepthmax.getCsvHeader())); |
|
142 source.addMetaData("waterlevel_header", msg(SInfoResultType.waterlevel.getCsvHeader())); |
|
143 source.addMetaData("discharge_header", msg(SInfoResultType.discharge.getCsvHeader())); |
|
144 source.addMetaData("waterlevel_name_header", msg(SInfoResultType.waterlevelLabel.getCsvHeader())); |
|
145 source.addMetaData("gauge_header", msg(SInfoResultType.gaugeLabel.getCsvHeader())); |
|
146 source.addMetaData("bedheight_header", msg(SInfoResultType.meanBedHeight.getCsvHeader())); |
|
147 source.addMetaData("sounding_name_header", msg(SInfoResultType.soundingLabel.getCsvHeader())); |
|
148 source.addMetaData("location_header", msg(SInfoResultType.location.getCsvHeader())); |
8946
|
149 } |
|
150 |
|
151 @Override |
8948
|
152 protected String[] formatPDFRow(final FlowDepthMinMaxCalculationResults results, final SInfoResultRow row) { |
|
153 return formatRow(null, row); |
8946
|
154 } |
|
155 } |