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