Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculationResult.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 | a4121ec450d6 |
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.flowdepthminmax; | 10 package org.dive4elements.river.artifacts.sinfo.flowdepthminmax; |
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.AbstractSInfoCalculationResult; | 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 FlowDepthMinMaxCalculationResult extends AbstractSInfoCalculationResult { | 30 final class FlowDepthMinMaxCalculationResult extends AbstractCalculationExportableResult<FlowDepthMinMaxCalculationResults> { |
25 | 31 |
26 private static final long serialVersionUID = 1L; | 32 private static final long serialVersionUID = 1L; |
33 private static final String JASPER_FILE = "/jasper/templates/sinfo.flowdepthminmax.jrxml"; | |
27 | 34 |
28 private final BedHeightInfo sounding; | 35 private final BedHeightInfo sounding; |
36 private final WstInfo wst; | |
29 | 37 |
30 public FlowDepthMinMaxCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding, | 38 public FlowDepthMinMaxCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding, final Collection<ResultRow> rows) { |
31 final Collection<ResultRow> rows) { | 39 super(label, rows); |
32 super(label, wst, rows); | 40 this.wst = wst; |
33 | |
34 this.sounding = sounding; | 41 this.sounding = sounding; |
35 } | 42 } |
36 | 43 |
37 public BedHeightInfo getSounding() { | 44 public BedHeightInfo getSounding() { |
38 return this.sounding; | 45 return this.sounding; |
39 } | 46 } |
47 | |
48 @Override | |
49 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final FlowDepthMinMaxCalculationResults results, final RiverInfo river) { | |
50 | |
51 final Collection<String> header = new ArrayList<>(11); | |
52 | |
53 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); | |
54 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.flowdepthmin)); | |
55 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.flowdepthmax)); | |
56 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel, river.getWstUnit())); | |
57 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge)); | |
58 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.waterlevelLabel)); | |
59 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); | |
60 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.meanBedHeight, river.getWstUnit())); | |
61 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.soundingLabel)); | |
62 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); | |
63 | |
64 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); | |
65 | |
66 } | |
67 | |
68 @Override | |
69 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final FlowDepthMinMaxCalculationResults results) { | |
70 | |
71 exportContextCSV.writeCSVSoundingMetadata(this.sounding); | |
72 exportContextCSV.writeBlankLine(); | |
73 | |
74 exportContextCSV.writeCSVWaterlevelMetadata(this.wst); | |
75 exportContextCSV.writeBlankLine(); | |
76 | |
77 } | |
78 | |
79 @Override | |
80 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final FlowDepthMinMaxCalculationResults results, final ResultRow row) { | |
81 | |
82 return formatRow(exportContextCSV, results, row); | |
83 } | |
84 | |
85 @Override | |
86 protected String[] formatPDFRow(final ExportContextCSV exportContextPDF, final FlowDepthMinMaxCalculationResults results, final ResultRow row) { | |
87 | |
88 return formatRow(exportContextPDF, results, row); | |
89 } | |
90 | |
91 @Override | |
92 protected String getJasperFile() { | |
93 return this.JASPER_FILE; | |
94 } | |
95 | |
96 @Override | |
97 protected void addJRTableHeader(final ExportContextCSV exportContextPDF, final MetaAndTableJRDataSource source, | |
98 final FlowDepthMinMaxCalculationResults results) { | |
99 | |
100 /* column headings */ | |
101 exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station); | |
102 exportContextPDF.addJRMetadata(source, "flowdepthmin_header", SInfoResultType.flowdepthmin); | |
103 exportContextPDF.addJRMetadata(source, "flowdepthmax_header", SInfoResultType.flowdepthmax); | |
104 exportContextPDF.addJRMetadata(source, "waterlevel_header", SInfoResultType.waterlevel); | |
105 exportContextPDF.addJRMetadata(source, "discharge_header", SInfoResultType.discharge); | |
106 exportContextPDF.addJRMetadata(source, "waterlevel_name_header", SInfoResultType.waterlevelLabel); | |
107 exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel); | |
108 exportContextPDF.addJRMetadata(source, "bedheight_header", SInfoResultType.meanBedHeight); | |
109 exportContextPDF.addJRMetadata(source, "sounding_name_header", SInfoResultType.soundingLabel); | |
110 exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location); | |
111 | |
112 } | |
113 | |
114 protected String[] formatRow(final ExportContextCSV exportContextCSV, final FlowDepthMinMaxCalculationResults results, final ResultRow row) { | |
115 | |
116 final Collection<String> lines = new ArrayList<>(10); | |
117 | |
118 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); | |
119 | |
120 // REMARK: null check as pdf will call this with null and in that case we show all columns (to avoid multiple jasper | |
121 // FIXME: does not work like this: we may have several pairs of min/max; so we need to look at all of them? | |
122 // templates) | |
123 // if (result == null || result.getMinSounding() != null) | |
124 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.flowdepthmin)); | |
125 // if (result == null || result.getMaxSounding() != null) | |
126 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.flowdepthmax)); | |
127 | |
128 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel)); | |
129 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge)); | |
130 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevelLabel)); | |
131 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel)); | |
132 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.meanBedHeight)); | |
133 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.soundingLabel)); | |
134 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location)); | |
135 | |
136 return lines.toArray(new String[lines.size()]); | |
137 } | |
40 } | 138 } |