Mercurial > dive4elements > river
annotate 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 |
rev | line source |
---|---|
8928 | 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.tkhstate; | |
10 | |
11 import java.util.ArrayList; | |
12 import java.util.Collection; | |
13 | |
14 import org.apache.log4j.Logger; | |
8996 | 15 import org.dive4elements.river.artifacts.common.GeneralResultType; |
16 import org.dive4elements.river.artifacts.common.ResultRow; | |
8928 | 17 import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoExporter; |
8948 | 18 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
8928 | 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 tkh computation. | |
27 * | |
28 * @author Gernot Belger | |
29 */ | |
30 // REMARK: must be public because its registered in generators.xml | |
8948 | 31 public class TkhExporter extends AbstractSInfoExporter<TkhCalculationResult, TkhCalculationResults> { |
8928 | 32 |
33 /** The log used in this exporter. */ | |
34 private static Logger log = Logger.getLogger(TkhExporter.class); | |
35 | |
36 private static final String CSV_META_CALCULATION_FORMULA = "sinfo.export.tkh.calculation.formula"; | |
37 | |
8984 | 38 private static final String JASPER_FILE = "/jasper/sinfo.tkh.jasper"; |
8928 | 39 |
40 @Override | |
41 protected Logger getLog() { | |
42 return log; | |
43 } | |
44 | |
45 @Override | |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
46 protected void writeCSVGlobalMetadata(final CSVWriter writer, final TkhCalculationResults results) { |
8928 | 47 log.info("TkhExporter.writeCSVMeta"); |
48 | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
49 super.writeCSVGlobalMetadataDefaults(writer, results); |
8928 | 50 |
51 // "# Berechnungsgrundlage: Gleichung nach GILL (1971)" | |
52 writeCSVMetaEntry(writer, CSV_META_CALCULATION_FORMULA); | |
53 | |
54 writer.writeNext(new String[] { "" }); | |
55 } | |
56 | |
57 /** | |
58 * Write the header, with different headings depending on whether at a gauge or at a location. | |
59 */ | |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
60 |
8928 | 61 @Override |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
62 protected void writeCSVHeader(final CSVWriter writer, final TkhCalculationResults results, final RiverInfo river) { |
8928 | 63 log.info("TkhExporter.writeCSVHeader"); |
64 | |
65 final Collection<String> header = new ArrayList<>(11); | |
66 | |
8996 | 67 header.add(msg(GeneralResultType.station.getCsvHeader())); |
8948 | 68 header.add(msgUnit(SInfoResultType.tkh.getCsvHeader(), SInfoResultType.tkh.getUnit())); |
69 header.add(msg(SInfoResultType.soilkind.getCsvHeader())); | |
70 header.add(msgUnit(SInfoResultType.meanBedHeight.getCsvHeader(), river.getWstUnit())); | |
71 header.add(msgUnit(SInfoResultType.waterlevel.getCsvHeader(), river.getWstUnit())); | |
72 header.add(msgUnit(SInfoResultType.discharge.getCsvHeader(), SInfoResultType.discharge.getUnit())); | |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
73 |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
74 final String descriptionHeader = results.getDescriptionHeader(); |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
75 if (descriptionHeader != null) |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
76 header.add(msg(descriptionHeader)); |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
77 |
8948 | 78 header.add(msg(SInfoResultType.gaugeLabel.getCsvHeader())); |
79 header.add(msg(SInfoResultType.location.getCsvHeader())); | |
8928 | 80 |
81 writer.writeNext(header.toArray(new String[header.size()])); | |
82 } | |
83 | |
84 @Override | |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
85 // FIXME: rename |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
86 protected void writeCSVResultMetadata(final CSVWriter writer, final TkhCalculationResults results, final TkhCalculationResult result) { |
8928 | 87 |
88 final WstInfo wst = result.getWst(); | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
89 super.writeCSVWaterlevelMetadata(writer, wst); |
8928 | 90 |
8948 | 91 // FIXME: |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
92 // "# W/Pegel [cm]: " (nur bei Eingabe des Wasserstands am Pegel) |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8938
diff
changeset
|
93 // "# Q (m³/s): " (nur bei Eingabe des Durchflusses) |
8928 | 94 } |
95 | |
96 /** | |
97 * Format a row of a flow depth result into an array of string, both used by csv and pdf | |
98 * | |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
99 * @param results |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
100 * |
8928 | 101 * @param useTkh |
102 */ | |
8996 | 103 @Override |
104 protected String[] formatRow(final TkhCalculationResults results, final ResultRow row, final ExportMode mode) { | |
8928 | 105 |
106 final Collection<String> lines = new ArrayList<>(11); | |
107 | |
8996 | 108 lines.add(row.exportValue(this.context, GeneralResultType.station)); |
8948 | 109 lines.add(row.exportValue(this.context, SInfoResultType.tkh)); |
110 lines.add(row.exportValue(this.context, SInfoResultType.soilkind)); | |
111 lines.add(row.exportValue(this.context, SInfoResultType.meanBedHeight)); | |
112 lines.add(row.exportValue(this.context, SInfoResultType.waterlevel)); | |
113 lines.add(row.exportValue(this.context, SInfoResultType.discharge)); | |
8928 | 114 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
115 // REMARK: always export this column in pdf-mode, because WInfo also does it (no need for two jasper-templates). |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
116 if (results.getDescriptionHeader() != null || mode == ExportMode.pdf) |
8948 | 117 lines.add(row.exportValue(this.context, SInfoResultType.waterlevelLabel)); |
8928 | 118 |
8948 | 119 lines.add(row.exportValue(this.context, SInfoResultType.gaugeLabel)); |
120 lines.add(row.exportValue(this.context, SInfoResultType.location)); | |
8928 | 121 |
122 return lines.toArray(new String[lines.size()]); | |
123 } | |
124 | |
125 @Override | |
126 protected final String getJasperFile() { | |
127 return JASPER_FILE; | |
128 } | |
129 | |
130 @Override | |
131 protected final void addJRMetaData(final MetaAndTableJRDataSource source, final TkhCalculationResults results) { | |
132 | |
133 /* general metadata */ | |
8996 | 134 super.addJRMetaData(source, results); |
8928 | 135 |
8996 | 136 source.addMetaData("calculation_label", msg("sinfo.export.flow_depth.pdf.meta.calculation.label")); |
137 source.addMetaData("calculation_name", msg("sinfo.export.flow_depth.pdf.meta.calculation.name")); | |
138 | |
8928 | 139 /* column headings */ |
8996 | 140 source.addMetaData("station_header", GeneralResultType.station.getPdfHeader(this.context.getMeta())); |
8949
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
141 source.addMetaData("tkh_header", SInfoResultType.tkh.getPdfHeader(this.context.getMeta())); |
8984 | 142 source.addMetaData("tkhkind_header", SInfoResultType.soilkind.getPdfHeader(this.context.getMeta())); |
8949
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
143 source.addMetaData("bedheight_header", SInfoResultType.meanBedHeight.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
144 source.addMetaData("waterlevel_header", SInfoResultType.waterlevel.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
145 source.addMetaData("discharge_header", SInfoResultType.discharge.getPdfHeader(this.context.getMeta())); |
8996 | 146 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
147 // REMARK: actually the column makes no sense if description header is null. But (software symmetry...) WINFO also |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
148 // writes an empty column into the pdf in that case (most probably to avoid the need for two jasper templates). |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
149 final String descriptionHeader = results.getDescriptionHeader(); |
8949
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
150 final String waterlevelNameHeader = descriptionHeader == null ? SInfoResultType.waterlevelLabel.getPdfHeader(this.context.getMeta()) |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
151 : descriptionHeader; |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
152 source.addMetaData("waterlevel_name_header", waterlevelNameHeader); |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8928
diff
changeset
|
153 |
8949
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
154 source.addMetaData("gauge_header", SInfoResultType.gaugeLabel.getPdfHeader(this.context.getMeta())); |
09e4a4909814
Distinguish between csv and pdf column headers
gernotbelger
parents:
8948
diff
changeset
|
155 source.addMetaData("location_header", SInfoResultType.location.getPdfHeader(this.context.getMeta())); |
8928 | 156 } |
157 | |
158 } |