Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthExporter.java @ 8954:183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
author | gernotbelger |
---|---|
date | Mon, 19 Mar 2018 14:13:37 +0100 |
parents | 09e4a4909814 |
children | d5802f22e4f5 |
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 | |
14 import org.apache.log4j.Logger; | |
8928 | 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; | |
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; | |
8854 | 22 |
23 import au.com.bytecode.opencsv.CSVWriter; | |
24 | |
25 /** | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
26 * Generates different output formats (csv, pdf) of data that resulted from a flow depths min/max computation. |
8854 | 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 FlowDepthExporter extends AbstractSInfoExporter<FlowDepthCalculationResult, FlowDepthCalculationResults> { |
8854 | 33 |
8954
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
34 private static enum ExportMode { |
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
35 pdf, csv |
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
36 } |
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
37 |
8877 | 38 /** The log used in this exporter. */ |
8854 | 39 private static Logger log = Logger.getLogger(FlowDepthExporter.class); |
40 | |
8948 | 41 private static final String JASPER_FILE = "/jasper/sinfo.flowdepth.jasper"; |
8863 | 42 |
8928 | 43 @Override |
44 protected Logger getLog() { | |
45 return log; | |
8863 | 46 } |
8877 | 47 |
8854 | 48 @Override |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
49 protected void writeCSVGlobalMetadata(final CSVWriter writer, final FlowDepthCalculationResults results) { |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
50 log.info("FlowDepthExporter.writeCSVMeta"); |
8877 | 51 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
52 super.writeCSVGlobalMetadataDefaults(writer, results); |
8877 | 53 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
54 writer.writeNext(new String[] { "" }); |
8877 | 55 } |
8854 | 56 |
8928 | 57 @Override |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
58 protected void writeCSVResultMetadata(final CSVWriter writer, final FlowDepthCalculationResults results, final FlowDepthCalculationResult result) { |
8854 | 59 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
60 final BedHeightInfo sounding = result.getSounding(); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
61 super.writeCSVSoundingMetadata(writer, sounding); |
8854 | 62 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
63 final WstInfo wst = result.getWst(); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
64 super.writeCSVWaterlevelMetadata(writer, wst); |
8854 | 65 } |
66 | |
8877 | 67 /** |
8854 | 68 * Write the header, with different headings depending on whether at a |
69 * gauge or at a location. | |
8877 | 70 * |
71 * @param river | |
72 * @param useTkh | |
8854 | 73 */ |
8928 | 74 @Override |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
75 protected void writeCSVHeader(final CSVWriter writer, final FlowDepthCalculationResults results, final RiverInfo river) { |
8854 | 76 log.info("FlowDepthExporter.writeCSVHeader"); |
77 | |
78 final Collection<String> header = new ArrayList<>(11); | |
8877 | 79 |
8948 | 80 header.add(msg(SInfoResultType.station.getCsvHeader())); |
81 header.add(msgUnit(SInfoResultType.flowdepth.getCsvHeader(), SInfoResultType.flowdepth.getUnit())); | |
82 | |
83 if (results.isUseTkh()) { | |
84 header.add(msgUnit(SInfoResultType.flowdepthtkh.getCsvHeader(), SInfoResultType.flowdepthtkh.getUnit())); | |
85 header.add(msgUnit(SInfoResultType.tkh.getCsvHeader(), SInfoResultType.tkh.getUnit())); | |
8854 | 86 } |
8863 | 87 |
8948 | 88 header.add(msgUnit(SInfoResultType.waterlevel.getCsvHeader(), river.getWstUnit())); |
89 header.add(msgUnit(SInfoResultType.discharge.getCsvHeader(), SInfoResultType.discharge.getUnit())); | |
90 header.add(msg(SInfoResultType.waterlevelLabel.getCsvHeader())); | |
91 header.add(msg(SInfoResultType.gaugeLabel.getCsvHeader())); | |
92 header.add(msgUnit(SInfoResultType.meanBedHeight.getCsvHeader(), river.getWstUnit())); | |
93 header.add(msg(SInfoResultType.soundingLabel.getCsvHeader())); | |
94 header.add(msg(SInfoResultType.location.getCsvHeader())); | |
8854 | 95 |
8877 | 96 writer.writeNext(header.toArray(new String[header.size()])); |
8854 | 97 } |
98 | |
8928 | 99 @Override |
8948 | 100 protected String[] formatCSVRow(final FlowDepthCalculationResults results, final FlowDepthCalculationResult result, final SInfoResultRow row) { |
8954
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
101 return formatRow(row, ExportMode.csv); |
8928 | 102 } |
103 | |
8854 | 104 /** |
105 * Format a row of a flow depth result into an array of string, both used by csv and pdf | |
8877 | 106 * |
8954
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
107 * @param pdf |
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
108 * |
8877 | 109 * @param useTkh |
8854 | 110 */ |
8954
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
111 private String[] formatRow(final SInfoResultRow row, final ExportMode mode) { |
8854 | 112 |
8877 | 113 final Collection<String> lines = new ArrayList<>(11); |
8854 | 114 |
8948 | 115 lines.add(row.exportValue(this.context, SInfoResultType.station)); |
116 lines.add(row.exportValue(this.context, SInfoResultType.flowdepth)); | |
8877 | 117 |
8954
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
118 if (mode == ExportMode.pdf || getData().isUseTkh()) { |
8948 | 119 lines.add(row.exportValue(this.context, SInfoResultType.flowdepthtkh)); |
120 lines.add(row.exportValue(this.context, SInfoResultType.tkh)); | |
8877 | 121 } |
122 | |
8948 | 123 lines.add(row.exportValue(this.context, SInfoResultType.waterlevel)); |
124 lines.add(row.exportValue(this.context, SInfoResultType.discharge)); | |
125 lines.add(row.exportValue(this.context, SInfoResultType.waterlevelLabel)); | |
126 lines.add(row.exportValue(this.context, SInfoResultType.gaugeLabel)); | |
127 lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight)); | |
128 lines.add(row.exportValue(this.context, SInfoResultType.soundingLabel)); | |
129 lines.add(row.exportValue(this.context, SInfoResultType.location)); | |
8877 | 130 |
131 return lines.toArray(new String[lines.size()]); | |
8854 | 132 } |
8877 | 133 |
8928 | 134 @Override |
135 protected final String getJasperFile() { | |
136 return JASPER_FILE; | |
8854 | 137 } |
138 | |
8877 | 139 @Override |
8928 | 140 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final FlowDepthCalculationResults results) { |
8854 | 141 |
8877 | 142 /* general metadata */ |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
143 super.addJRMetaDataDefaults(source, results); |
8854 | 144 |
8863 | 145 /* column headings */ |
8949
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
146 source.addMetaData("station_header", SInfoResultType.station.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
147 source.addMetaData("flowdepth_header", SInfoResultType.flowdepth.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
148 source.addMetaData("flowdepth_tkh_header", SInfoResultType.flowdepthtkh.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
149 source.addMetaData("tkh_header", SInfoResultType.tkh.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
150 source.addMetaData("waterlevel_header", SInfoResultType.waterlevel.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
151 source.addMetaData("discharge_header", SInfoResultType.discharge.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
152 source.addMetaData("waterlevel_name_header", SInfoResultType.waterlevelLabel.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
153 source.addMetaData("gauge_header", SInfoResultType.gaugeLabel.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
154 source.addMetaData("bedheight_header", SInfoResultType.meanBedHeight.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
155 source.addMetaData("sounding_name_header", SInfoResultType.soundingLabel.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
156 source.addMetaData("location_header", SInfoResultType.location.getPdfHeader(this.context.getMeta())); |
8854 | 157 } |
158 | |
8928 | 159 @Override |
8948 | 160 protected String[] formatPDFRow(final FlowDepthCalculationResults results, final SInfoResultRow row) { |
8954
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8949
diff
changeset
|
161 return formatRow(row, ExportMode.pdf); |
8877 | 162 } |
8928 | 163 } |