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