comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java @ 9150:23945061daec

gigantic refactoring: exporter, result, results to support multiple jaspers -> collisions
author gernotbelger
date Thu, 14 Jun 2018 16:56:31 +0200
parents 2ed3824a3d53
children 9b2e46090099
comparison
equal deleted inserted replaced
9149:5be112fba832 9150:23945061daec
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
9 */ 9 */
10 package org.dive4elements.river.artifacts.sinfo.flowdepth; 10 package org.dive4elements.river.artifacts.sinfo.flowdepth;
11 11
12 import java.util.ArrayList;
12 import java.util.Collection; 13 import java.util.Collection;
13 14
15 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
16 import org.dive4elements.river.artifacts.common.ExportContextCSV;
17 import org.dive4elements.river.artifacts.common.GeneralResultType;
18 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
14 import org.dive4elements.river.artifacts.common.ResultRow; 19 import org.dive4elements.river.artifacts.common.ResultRow;
15 import org.dive4elements.river.artifacts.sinfo.common.AbstractTkhCalculationResult; 20 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
16 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; 21 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
22 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
17 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; 23 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
18 24
19 /** 25 /**
20 * Contains the results of a {@link FloodDurationCalculation}. 26 * Contains the results of a {@link FloodDurationCalculation}.
21 * 27 *
22 * @author Gernot Belger 28 * @author Gernot Belger
23 */ 29 */
24 final class FlowDepthCalculationResult extends AbstractTkhCalculationResult { 30 final class FlowDepthCalculationResult extends AbstractCalculationExportableResult<FlowDepthCalculationResults> {
25 31
26 private static final long serialVersionUID = 1L; 32 private static final long serialVersionUID = 1L;
27 33
34 private enum ExportMode { // TODO; nicht ständig kopieren
35 pdf, csv
36 }
37
38 private static final String JASPER_FILE = "/jasper/templates/sinfo.flowdepth.jrxml"; // TODO use jrxml-path all over the project
39
28 private final BedHeightInfo sounding; 40 private final BedHeightInfo sounding;
41 private final WstInfo wst;
42 private final boolean hasTkh;
29 43
30 public FlowDepthCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding, final boolean hasTkh, 44 public FlowDepthCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding, final boolean hasTkh,
31 final Collection<ResultRow> rows) { 45 final Collection<ResultRow> rows) {
32 super(label, wst, hasTkh, rows); 46 super(label, rows);
33 47
34 this.sounding = sounding; 48 this.sounding = sounding;
49 this.wst = wst;
50 this.hasTkh = hasTkh;
35 } 51 }
36 52
37 public BedHeightInfo getSounding() { 53 public BedHeightInfo getSounding() {
38 return this.sounding; 54 return this.sounding;
39 } 55 }
56
57 @Override
58 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final FlowDepthCalculationResults results, final RiverInfo river) {
59 // getLog().info("FlowDepthExporter.writeCSVHeader");
60
61 final Collection<String> header = new ArrayList<>(11);
62
63 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station));
64 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.flowdepth));
65
66 if (this.hasTkh()) {
67 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.flowdepthtkh));
68 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.tkh));
69 }
70
71 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel, river.getWstUnit()));
72 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge));
73 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.waterlevelLabel));
74 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel));
75 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.meanBedHeight));
76 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.soundingLabel));
77 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location));
78
79 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
80
81 }
82
83 @Override
84 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final FlowDepthCalculationResults results) {
85
86 exportContextCSV.writeCSVSoundingMetadata(this.sounding);
87
88 exportContextCSV.writeBlankLine();// .writeNext(new String[] { "" }); // break line
89
90 exportContextCSV.writeCSVWaterlevelMetadata(this.wst);
91
92 exportContextCSV.writeBlankLine();// .writeNext(new String[] { "" }); // break line
93
94 }
95
96 @Override
97 protected String getJasperFile() {
98 return JASPER_FILE;
99 }
100
101 @Override
102 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final FlowDepthCalculationResults results, final ResultRow row) {
103 return formatRow(ExportMode.csv, exportContextCSV, results, row);
104 }
105
106 @Override
107 protected String[] formatPDFRow(final ExportContextCSV exportContextPDF, final FlowDepthCalculationResults results, final ResultRow row) {
108
109 return formatRow(ExportMode.pdf, exportContextPDF, results, row);
110 }
111
112 @Override
113 protected void addJRTableHeader(final ExportContextCSV exportContextPDF, final MetaAndTableJRDataSource source, final FlowDepthCalculationResults results) {
114
115 /* column headings */
116 exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station);
117 exportContextPDF.addJRMetadata(source, "flowdepth_header", SInfoResultType.flowdepth);
118 exportContextPDF.addJRMetadata(source, "flowdepth_tkh_header", SInfoResultType.flowdepthtkh);
119 exportContextPDF.addJRMetadata(source, "tkh_header", SInfoResultType.tkh);
120 exportContextPDF.addJRMetadata(source, "waterlevel_header", SInfoResultType.waterlevel);
121 exportContextPDF.addJRMetadata(source, "discharge_header", SInfoResultType.discharge);
122 exportContextPDF.addJRMetadata(source, "waterlevel_name_header", SInfoResultType.waterlevelLabel);
123 exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel);
124 exportContextPDF.addJRMetadata(source, "bedheight_header", SInfoResultType.meanBedHeight);
125 exportContextPDF.addJRMetadata(source, "sounding_name_header", SInfoResultType.soundingLabel);
126 exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location);
127 }
128
129 public boolean hasTkh() {
130 return this.hasTkh;
131 }
132
133 private String[] formatRow(final ExportMode mode, final ExportContextCSV exportContextCSV, final FlowDepthCalculationResults results, final ResultRow row) {
134
135 final Collection<String> lines = new ArrayList<>(11);
136
137 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station));
138 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.flowdepth));
139
140 if (mode == ExportMode.pdf || results.isUseTkh()) {
141 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.flowdepthtkh));
142 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.tkh));
143 }
144
145 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel));
146 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge));
147 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevelLabel));
148 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel));
149 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.meanBedHeight));
150 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.soundingLabel));
151 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location));
152
153 return lines.toArray(new String[lines.size()]);
154 }
155
40 } 156 }

http://dive4elements.wald.intevation.org