Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java @ 8996:fb9430250899
Work on uinfo
author | gernotbelger |
---|---|
date | Thu, 12 Apr 2018 19:13:39 +0200 |
parents | 7c1611b5a59e |
children | 7134a4c7d1b6 |
comparison
equal
deleted
inserted
replaced
8995:8c3e5682cb60 | 8996:fb9430250899 |
---|---|
10 | 10 |
11 import java.util.ArrayList; | 11 import java.util.ArrayList; |
12 import java.util.Collection; | 12 import java.util.Collection; |
13 | 13 |
14 import org.apache.log4j.Logger; | 14 import org.apache.log4j.Logger; |
15 import org.dive4elements.river.artifacts.common.GeneralResultType; | |
16 import org.dive4elements.river.artifacts.common.ResultRow; | |
15 import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoExporter; | 17 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.common.SInfoResultType; |
18 import org.dive4elements.river.artifacts.sinfo.util.MetaAndTableJRDataSource; | 19 import org.dive4elements.river.artifacts.sinfo.util.MetaAndTableJRDataSource; |
19 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | 20 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
20 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; | 21 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; |
21 | 22 |
26 * | 27 * |
27 * @author Gernot Belger | 28 * @author Gernot Belger |
28 */ | 29 */ |
29 // REMARK: must be public because its registered in generators.xml | 30 // REMARK: must be public because its registered in generators.xml |
30 public class TkhExporter extends AbstractSInfoExporter<TkhCalculationResult, TkhCalculationResults> { | 31 public class TkhExporter extends AbstractSInfoExporter<TkhCalculationResult, TkhCalculationResults> { |
31 | |
32 private static enum ExportMode { | |
33 pdf, csv | |
34 } | |
35 | 32 |
36 /** The log used in this exporter. */ | 33 /** The log used in this exporter. */ |
37 private static Logger log = Logger.getLogger(TkhExporter.class); | 34 private static Logger log = Logger.getLogger(TkhExporter.class); |
38 | 35 |
39 private static final String CSV_META_CALCULATION_FORMULA = "sinfo.export.tkh.calculation.formula"; | 36 private static final String CSV_META_CALCULATION_FORMULA = "sinfo.export.tkh.calculation.formula"; |
65 protected void writeCSVHeader(final CSVWriter writer, final TkhCalculationResults results, final RiverInfo river) { | 62 protected void writeCSVHeader(final CSVWriter writer, final TkhCalculationResults results, final RiverInfo river) { |
66 log.info("TkhExporter.writeCSVHeader"); | 63 log.info("TkhExporter.writeCSVHeader"); |
67 | 64 |
68 final Collection<String> header = new ArrayList<>(11); | 65 final Collection<String> header = new ArrayList<>(11); |
69 | 66 |
70 header.add(msg(SInfoResultType.station.getCsvHeader())); | 67 header.add(msg(GeneralResultType.station.getCsvHeader())); |
71 header.add(msgUnit(SInfoResultType.tkh.getCsvHeader(), SInfoResultType.tkh.getUnit())); | 68 header.add(msgUnit(SInfoResultType.tkh.getCsvHeader(), SInfoResultType.tkh.getUnit())); |
72 header.add(msg(SInfoResultType.soilkind.getCsvHeader())); | 69 header.add(msg(SInfoResultType.soilkind.getCsvHeader())); |
73 header.add(msgUnit(SInfoResultType.meanBedHeight.getCsvHeader(), river.getWstUnit())); | 70 header.add(msgUnit(SInfoResultType.meanBedHeight.getCsvHeader(), river.getWstUnit())); |
74 header.add(msgUnit(SInfoResultType.waterlevel.getCsvHeader(), river.getWstUnit())); | 71 header.add(msgUnit(SInfoResultType.waterlevel.getCsvHeader(), river.getWstUnit())); |
75 header.add(msgUnit(SInfoResultType.discharge.getCsvHeader(), SInfoResultType.discharge.getUnit())); | 72 header.add(msgUnit(SInfoResultType.discharge.getCsvHeader(), SInfoResultType.discharge.getUnit())); |
94 // FIXME: | 91 // FIXME: |
95 // "# W/Pegel [cm]: " (nur bei Eingabe des Wasserstands am Pegel) | 92 // "# W/Pegel [cm]: " (nur bei Eingabe des Wasserstands am Pegel) |
96 // "# Q (m³/s): " (nur bei Eingabe des Durchflusses) | 93 // "# Q (m³/s): " (nur bei Eingabe des Durchflusses) |
97 } | 94 } |
98 | 95 |
99 @Override | |
100 protected String[] formatCSVRow(final TkhCalculationResults results, final TkhCalculationResult result, final SInfoResultRow row) { | |
101 return formatRow(results, row, ExportMode.csv); | |
102 } | |
103 | |
104 /** | 96 /** |
105 * Format a row of a flow depth result into an array of string, both used by csv and pdf | 97 * Format a row of a flow depth result into an array of string, both used by csv and pdf |
106 * | 98 * |
107 * @param results | 99 * @param results |
108 * | 100 * |
109 * @param useTkh | 101 * @param useTkh |
110 */ | 102 */ |
111 private String[] formatRow(final TkhCalculationResults results, final SInfoResultRow row, final ExportMode mode) { | 103 @Override |
104 protected String[] formatRow(final TkhCalculationResults results, final ResultRow row, final ExportMode mode) { | |
112 | 105 |
113 final Collection<String> lines = new ArrayList<>(11); | 106 final Collection<String> lines = new ArrayList<>(11); |
114 | 107 |
115 lines.add(row.exportValue(this.context, SInfoResultType.station)); | 108 lines.add(row.exportValue(this.context, GeneralResultType.station)); |
116 lines.add(row.exportValue(this.context, SInfoResultType.tkh)); | 109 lines.add(row.exportValue(this.context, SInfoResultType.tkh)); |
117 lines.add(row.exportValue(this.context, SInfoResultType.soilkind)); | 110 lines.add(row.exportValue(this.context, SInfoResultType.soilkind)); |
118 lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight)); | 111 lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight)); |
119 lines.add(row.exportValue(this.context, SInfoResultType.waterlevel)); | 112 lines.add(row.exportValue(this.context, SInfoResultType.waterlevel)); |
120 lines.add(row.exportValue(this.context, SInfoResultType.discharge)); | 113 lines.add(row.exportValue(this.context, SInfoResultType.discharge)); |
136 | 129 |
137 @Override | 130 @Override |
138 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final TkhCalculationResults results) { | 131 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final TkhCalculationResults results) { |
139 | 132 |
140 /* general metadata */ | 133 /* general metadata */ |
141 super.addJRMetaDataDefaults(source, results); | 134 super.addJRMetaData(source, results); |
142 | 135 |
143 source.addMetaData("calculation_label",msg( "sinfo.export.flow_depth.pdf.meta.calculation.label" )); | 136 source.addMetaData("calculation_label", msg("sinfo.export.flow_depth.pdf.meta.calculation.label")); |
144 source.addMetaData("calculation_name",msg( "sinfo.export.flow_depth.pdf.meta.calculation.name" )); | 137 source.addMetaData("calculation_name", msg("sinfo.export.flow_depth.pdf.meta.calculation.name")); |
145 | 138 |
146 /* column headings */ | 139 /* column headings */ |
147 source.addMetaData("station_header", SInfoResultType.station.getPdfHeader(this.context.getMeta())); | 140 source.addMetaData("station_header", GeneralResultType.station.getPdfHeader(this.context.getMeta())); |
148 source.addMetaData("tkh_header", SInfoResultType.tkh.getPdfHeader(this.context.getMeta())); | 141 source.addMetaData("tkh_header", SInfoResultType.tkh.getPdfHeader(this.context.getMeta())); |
149 source.addMetaData("tkhkind_header", SInfoResultType.soilkind.getPdfHeader(this.context.getMeta())); | 142 source.addMetaData("tkhkind_header", SInfoResultType.soilkind.getPdfHeader(this.context.getMeta())); |
150 source.addMetaData("bedheight_header", SInfoResultType.meanBedHeight.getPdfHeader(this.context.getMeta())); | 143 source.addMetaData("bedheight_header", SInfoResultType.meanBedHeight.getPdfHeader(this.context.getMeta())); |
151 source.addMetaData("waterlevel_header", SInfoResultType.waterlevel.getPdfHeader(this.context.getMeta())); | 144 source.addMetaData("waterlevel_header", SInfoResultType.waterlevel.getPdfHeader(this.context.getMeta())); |
152 source.addMetaData("discharge_header", SInfoResultType.discharge.getPdfHeader(this.context.getMeta())); | 145 source.addMetaData("discharge_header", SInfoResultType.discharge.getPdfHeader(this.context.getMeta())); |
153 | 146 |
154 // REMARK: actually the column makes no sense if description header is null. But (software symmetry...) WINFO also | 147 // REMARK: actually the column makes no sense if description header is null. But (software symmetry...) WINFO also |
155 // writes an empty column into the pdf in that case (most probably to avoid the need for two jasper templates). | 148 // writes an empty column into the pdf in that case (most probably to avoid the need for two jasper templates). |
156 final String descriptionHeader = results.getDescriptionHeader(); | 149 final String descriptionHeader = results.getDescriptionHeader(); |
157 final String waterlevelNameHeader = descriptionHeader == null ? SInfoResultType.waterlevelLabel.getPdfHeader(this.context.getMeta()) | 150 final String waterlevelNameHeader = descriptionHeader == null ? SInfoResultType.waterlevelLabel.getPdfHeader(this.context.getMeta()) |
158 : descriptionHeader; | 151 : descriptionHeader; |
160 | 153 |
161 source.addMetaData("gauge_header", SInfoResultType.gaugeLabel.getPdfHeader(this.context.getMeta())); | 154 source.addMetaData("gauge_header", SInfoResultType.gaugeLabel.getPdfHeader(this.context.getMeta())); |
162 source.addMetaData("location_header", SInfoResultType.location.getPdfHeader(this.context.getMeta())); | 155 source.addMetaData("location_header", SInfoResultType.location.getPdfHeader(this.context.getMeta())); |
163 } | 156 } |
164 | 157 |
165 @Override | |
166 protected String[] formatPDFRow(final TkhCalculationResults results, final SInfoResultRow row) { | |
167 return formatRow(results, row, ExportMode.pdf); | |
168 } | |
169 } | 158 } |