Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java @ 9612:f8308db94634
#20 UI, Diagramme
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 09 Oct 2019 16:17:16 +0200 |
parents | aa6ee96071b7 |
children | d889ffe2fb05 |
comparison
equal
deleted
inserted
replaced
9611:8ed6c45136fa | 9612:f8308db94634 |
---|---|
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.flood_duration; | 10 package org.dive4elements.river.artifacts.sinfo.flood_duration; |
11 | 11 |
12 import java.io.Serializable; | |
12 import java.text.NumberFormat; | 13 import java.text.NumberFormat; |
13 import java.util.ArrayList; | 14 import java.util.ArrayList; |
14 import java.util.Collection; | 15 import java.util.Collection; |
15 import java.util.Collections; | 16 import java.util.Collections; |
16 import java.util.List; | 17 import java.util.List; |
18 import java.util.Map.Entry; | |
19 import java.util.Set; | |
17 | 20 |
18 import org.apache.commons.collections.Predicate; | 21 import org.apache.commons.collections.Predicate; |
22 import org.apache.commons.lang.builder.EqualsBuilder; | |
23 import org.apache.commons.lang.builder.HashCodeBuilder; | |
24 import org.dive4elements.artifacts.CallContext; | |
19 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; | 25 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; |
20 import org.dive4elements.river.artifacts.common.AbstractExportContext; | 26 import org.dive4elements.river.artifacts.common.AbstractExportContext; |
21 import org.dive4elements.river.artifacts.common.ExportContextCSV; | 27 import org.dive4elements.river.artifacts.common.ExportContextCSV; |
22 import org.dive4elements.river.artifacts.common.ExportContextPDF; | 28 import org.dive4elements.river.artifacts.common.ExportContextPDF; |
23 import org.dive4elements.river.artifacts.common.GeneralResultType; | 29 import org.dive4elements.river.artifacts.common.GeneralResultType; |
24 import org.dive4elements.river.artifacts.common.IResultType; | 30 import org.dive4elements.river.artifacts.common.IResultType; |
25 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; | 31 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
26 import org.dive4elements.river.artifacts.common.ResultRow; | 32 import org.dive4elements.river.artifacts.common.ResultRow; |
33 import org.dive4elements.river.artifacts.resources.Resources; | |
27 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | 34 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
28 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | 35 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
29 import org.dive4elements.river.model.Attribute.AttributeKey; | 36 import org.dive4elements.river.model.Attribute.AttributeKey; |
30 | 37 |
31 import gnu.trove.TDoubleArrayList; | 38 import gnu.trove.TDoubleArrayList; |
35 * | 42 * |
36 * @author Gernot Belger | 43 * @author Gernot Belger |
37 */ | 44 */ |
38 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { | 45 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { |
39 | 46 |
40 private final static class RiversidePredicate implements Predicate { | 47 private final static class InfrastructurePredicate implements Predicate { |
41 | 48 |
42 private final AttributeKey riverside; | 49 private final Infrastructure m_infrastructure; |
43 | 50 |
44 public RiversidePredicate(final AttributeKey riverside) { | 51 public InfrastructurePredicate(final Infrastructure infrastructure) { |
45 this.riverside = riverside; | 52 this.m_infrastructure = infrastructure; |
46 } | 53 } |
47 | 54 |
48 @Override | 55 @Override |
49 public boolean evaluate(final Object object) { | 56 public boolean evaluate(final Object object) { |
50 final ResultRow row = (ResultRow) object; | 57 final ResultRow row = (ResultRow) object; |
51 | 58 final Infrastructure test = new Infrastructure(row); |
52 return row.getValue(SInfoResultType.riverside) == this.riverside; | 59 return this.m_infrastructure.equals(test); |
53 } | 60 } |
54 } | 61 } |
55 | 62 |
56 private final static class HasInfrastructurePredicate implements Predicate { | 63 private final static class HasInfrastructurePredicate implements Predicate { |
57 | 64 |
61 | 68 |
62 return row.getValue(SInfoResultType.riverside) != null; | 69 return row.getValue(SInfoResultType.riverside) != null; |
63 } | 70 } |
64 } | 71 } |
65 | 72 |
73 public static final class Infrastructure implements Serializable { | |
74 | |
75 private static final long serialVersionUID = 1L; | |
76 | |
77 private final String m_type; | |
78 | |
79 private final String m_part; | |
80 | |
81 private final AttributeKey m_riverside; | |
82 | |
83 private static final String FACET_FLOOD_DURATION_DESCRIPTION = "sinfo_facet_flood_duration"; | |
84 | |
85 private static final String FACET_ABSOLUTE_HEIGHT = "sinfo.flood_duration.absolute.height"; | |
86 | |
87 public Infrastructure(final ResultRow row) { | |
88 this.m_type = String.valueOf(row.getValue(SInfoResultType.infrastructuretype)); | |
89 this.m_part = String.valueOf(row.getValue(SInfoResultType.infrastructurepart)); | |
90 final String riversideStr = String.valueOf(row.getValue(SInfoResultType.riverside)); | |
91 this.m_riverside = riversideStr.equals("null") ? AttributeKey.NONE : AttributeKey.valueOf(riversideStr); | |
92 } | |
93 | |
94 public AttributeKey getRiverside() { | |
95 return this.m_riverside; | |
96 } | |
97 | |
98 @Override | |
99 public int hashCode() { | |
100 return new HashCodeBuilder() // | |
101 .append(this.m_type)// | |
102 .append(this.m_part)// | |
103 .append(this.m_riverside)// | |
104 .toHashCode(); | |
105 } | |
106 | |
107 @Override | |
108 public boolean equals(final Object obj) { | |
109 | |
110 if (obj == null) | |
111 return false; | |
112 if (obj == this) | |
113 return true; | |
114 if (obj.getClass() != getClass()) | |
115 return false; | |
116 | |
117 final Infrastructure other = (Infrastructure) obj; | |
118 return new EqualsBuilder() // | |
119 .append(this.m_type, other.m_type) // | |
120 .append(this.m_part, other.m_part) // | |
121 .append(this.m_riverside, other.m_riverside) // | |
122 .isEquals(); | |
123 } | |
124 | |
125 public String getFloodHeightLabel(final CallContext context) { | |
126 return Resources.getMsg(context.getMeta(), FACET_ABSOLUTE_HEIGHT, FACET_ABSOLUTE_HEIGHT) + " " + this.m_type + " - " + this.m_part + " (" | |
127 + getLocalizedRiverside(context) + ")"; | |
128 } | |
129 | |
130 public String getFloodDurationLabel(final CallContext context) { | |
131 return Resources.getMsg(context.getMeta(), FACET_FLOOD_DURATION_DESCRIPTION, FACET_FLOOD_DURATION_DESCRIPTION) + " " + this.m_type + " - " | |
132 + this.m_part + " (" + getLocalizedRiverside(context) + ")"; | |
133 } | |
134 | |
135 private String getLocalizedRiverside(final CallContext callContext) { | |
136 return SInfoResultType.localizeRiverside(callContext, this.m_riverside); | |
137 } | |
138 } | |
139 | |
66 private static final long serialVersionUID = 1L; | 140 private static final long serialVersionUID = 1L; |
67 | 141 |
68 private final boolean isUseWspl; | 142 private final boolean isUseWspl; |
69 | 143 |
70 private final String[] waterlevelLabels; | 144 private final String[] waterlevelLabels; |
71 | 145 |
72 private final int maxWaterlevelPdf = 3; | 146 private final int maxWaterlevelPdf = 3; |
147 | |
148 private final Set<Infrastructure> m_infastructures; | |
73 | 149 |
74 public interface ValueGetter { | 150 public interface ValueGetter { |
75 double getValue(DurationWaterlevel waterlevel); | 151 double getValue(DurationWaterlevel waterlevel); |
76 } | 152 } |
77 | 153 |
78 private enum ExportMode { | 154 private enum ExportMode { |
79 pdf, csv | 155 pdf, csv |
80 } | 156 } |
81 | 157 |
82 public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows, final boolean isUseWspl) { | 158 public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows, final boolean isUseWspl, |
159 final Set<Infrastructure> infrastructures) { | |
83 super(label, rows); | 160 super(label, rows); |
84 this.waterlevelLabels = mainvalueLabels; | 161 this.waterlevelLabels = mainvalueLabels; |
85 this.isUseWspl = isUseWspl; | 162 this.isUseWspl = isUseWspl; |
163 this.m_infastructures = infrastructures; | |
164 } | |
165 | |
166 public Set<Infrastructure> getInfastructureMap() { | |
167 return this.m_infastructures; | |
86 } | 168 } |
87 | 169 |
88 /** | 170 /** |
89 * Collection of the result rows containing only the rows describing an infrastructure | 171 * Collection of the result rows containing only the rows describing an infrastructure |
90 */ | 172 */ |
94 | 176 |
95 final Collection<ResultRow> rows = super.getRows(); | 177 final Collection<ResultRow> rows = super.getRows(); |
96 | 178 |
97 final List<ResultRow> infrasOnlyRows = new ArrayList<>(); | 179 final List<ResultRow> infrasOnlyRows = new ArrayList<>(); |
98 for (final ResultRow row : rows) { | 180 for (final ResultRow row : rows) { |
99 if (row.getValue(SInfoResultType.infrastructuretype) != null) | 181 if (row.getValue(SInfoResultType.infrastructuretype) != null && row.getValue(SInfoResultType.infrastructurepart) != null) |
100 infrasOnlyRows.add(row); | 182 infrasOnlyRows.add(row); |
101 } | 183 } |
102 return Collections.unmodifiableCollection(infrasOnlyRows); | 184 return Collections.unmodifiableCollection(infrasOnlyRows); |
103 } | 185 } |
104 | 186 |
128 final Collection<String> lines = new ArrayList<>(20); | 210 final Collection<String> lines = new ArrayList<>(20); |
129 | 211 |
130 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); | 212 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); |
131 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.riverside)); | 213 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.riverside)); |
132 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration)); | 214 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration)); |
215 | |
133 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge)); | 216 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge)); |
217 | |
134 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); | 218 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); |
135 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); | 219 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); |
220 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructurepart)); | |
136 | 221 |
137 final List<DurationWaterlevel> waterlevelList = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel); | 222 final List<DurationWaterlevel> waterlevelList = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel); |
138 | 223 |
139 final int expectedSizetoGaugelabel = lines.size() + (waterlevelList.size() < 2 ? 4 : 12); // removing columns only works for fixed | 224 final int expectedSizetoGaugelabel = lines.size() + (waterlevelList.size() < 2 ? 4 : 12); // removing columns only works for fixed |
140 // indices | 225 // indices |
176 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.riverside)); | 261 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.riverside)); |
177 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.floodDuration)); | 262 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.floodDuration)); |
178 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit())); | 263 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit())); |
179 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, river.getWstUnit())); | 264 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, river.getWstUnit())); |
180 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); | 265 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); |
266 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructurepart)); | |
181 | 267 |
182 // add dynamic headers | 268 // add dynamic headers |
183 final int waterlevelCount = // results. | 269 final int waterlevelCount = // results. |
184 getWaterlevelCount(); | 270 getWaterlevelCount(); |
185 for (int i = 0; i < waterlevelCount; i++) { | 271 for (int i = 0; i < waterlevelCount; i++) { |
225 exportContextPDF.addJRMetadata(source, "riverside_header", SInfoResultType.riverside); | 311 exportContextPDF.addJRMetadata(source, "riverside_header", SInfoResultType.riverside); |
226 exportContextPDF.addJRMetadata(source, "inundationduration_header", SInfoResultType.floodDuration); | 312 exportContextPDF.addJRMetadata(source, "inundationduration_header", SInfoResultType.floodDuration); |
227 exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge); | 313 exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge); |
228 exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeight); | 314 exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeight); |
229 exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); | 315 exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); |
316 exportContextPDF.addJRMetadata(source, "infrastructure_part_header", SInfoResultType.infrastructurepart); | |
230 | 317 |
231 for (int i = 1; i <= this.getWaterlevelCount(); i++) { | 318 for (int i = 1; i <= this.getWaterlevelCount(); i++) { |
232 | 319 |
233 final String appendIndex = "_" + Integer.toString(i); | 320 final String appendIndex = "_" + Integer.toString(i); |
234 exportContextPDF.addJRMetadata(source, getPdfHeader("w", i), exportContextPDF.msg(DurationWaterlevel.getHeaderWPdf(), appendIndex)); | 321 exportContextPDF.addJRMetadata(source, getPdfHeader("w", i), exportContextPDF.msg(DurationWaterlevel.getHeaderWPdf(), appendIndex)); |
260 } | 347 } |
261 | 348 |
262 /** | 349 /** |
263 * Gets the longitudinal section of a result value type for one river side | 350 * Gets the longitudinal section of a result value type for one river side |
264 */ | 351 */ |
265 public final double[][] getInfrastructurePoints(final IResultType type, final AttributeKey riverside) { | 352 public final double[][] getInfrastructurePoints(final IResultType type, final Infrastructure infrastructure) { |
266 return getPoints(GeneralResultType.station, type, new RiversidePredicate(riverside)); | 353 |
354 return getPoints(GeneralResultType.station, type, new InfrastructurePredicate(infrastructure)); | |
267 } | 355 } |
268 | 356 |
269 /** | 357 /** |
270 * Gets a longitudinal section of W, Q, or flood duration of one of the waterlevels | 358 * Gets a longitudinal section of W, Q, or flood duration of one of the waterlevels |
271 */ | 359 */ |
293 } | 381 } |
294 | 382 |
295 public boolean isUseWspl() { | 383 public boolean isUseWspl() { |
296 return this.isUseWspl; | 384 return this.isUseWspl; |
297 } | 385 } |
386 | |
387 public Collection<Entry<String, String>> getUniqueInfrastruktureTypes() { | |
388 // TODO Auto-generated method stub | |
389 return null; | |
390 } | |
298 } | 391 } |