Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FacetCalculator.java @ 9614:d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
author | mschaefer |
---|---|
date | Wed, 09 Oct 2019 19:17:06 +0200 |
parents | f8308db94634 |
children |
rev | line source |
---|---|
9612 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; | |
11 | |
12 import java.util.ArrayList; | |
13 import java.util.Collection; | |
14 import java.util.Collections; | |
15 import java.util.List; | |
16 | |
17 import org.dive4elements.artifacts.CallContext; | |
18 import org.dive4elements.river.artifacts.common.GeneralResultType; | |
19 import org.dive4elements.river.artifacts.common.ResultRow; | |
20 import org.dive4elements.river.artifacts.model.Calculation; | |
21 import org.dive4elements.river.artifacts.resources.Resources; | |
22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | |
23 import org.dive4elements.river.jfree.StickyAxisAnnotation; | |
24 import org.dive4elements.river.jfree.StickyAxisAnnotation.SimpleAxis; | |
25 import org.dive4elements.river.model.Attribute.AttributeKey; | |
26 | |
27 /** | |
28 * @author Domenico Nardi Tironi | |
29 * | |
30 */ | |
31 public class FacetCalculator { | |
32 | |
33 private static final double DELTA_KM = 0.0001; | |
34 | |
35 private final CallContext m_context; | |
36 | |
37 public FacetCalculator(final CallContext context) { | |
38 this.m_context = context; | |
39 } | |
40 | |
41 /** | |
42 * Calculates the data for the W main value lines in the duration curve chart | |
43 */ | |
44 public List<StickyAxisAnnotation> calcMainValueWAnnotations(final Calculation problems, final double station, final FloodDurationCalculationResult result) { | |
45 | |
46 final List<ResultRow> stationRows = searchStation(station, result.getAllRows(), AttributeKey.NONE); | |
47 if (stationRows.isEmpty()) | |
48 return Collections.emptyList(); | |
49 | |
50 final List<StickyAxisAnnotation> annotations = new ArrayList<>(); | |
51 final ResultRow row = stationRows.get(0); | |
52 final List<DurationWaterlevel> wqds = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel); | |
53 for (final DurationWaterlevel wqd : wqds) { | |
54 final String label = !wqd.getBezeichnung().startsWith("W=") ? "W(" + wqd.getBezeichnung() + ")" : wqd.getBezeichnung(); | |
55 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) wqd.getWaterlevel(), SimpleAxis.Y_AXIS, | |
56 FloodDurationCurveGenerator.YAXIS.W.idx); | |
57 annotation.setHitPoint((float) wqd.getFloodDurDaysPerYear()); | |
58 annotations.add(annotation); | |
59 } | |
60 return annotations; | |
61 } | |
62 | |
63 /** | |
64 * Calculates the data for the Q main value lines in the duration curve chart | |
65 * | |
66 * @param infrastructure | |
67 */ | |
68 public List<StickyAxisAnnotation> calcMainValueQAnnotations(final Calculation problems, final double station, final FloodDurationCalculationResult result) { | |
69 | |
70 final List<ResultRow> stationRows = searchStation(station, result.getAllRows(), AttributeKey.NONE); | |
71 if (stationRows.isEmpty()) | |
72 return Collections.emptyList(); | |
73 | |
74 final ResultRow row = stationRows.get(0); | |
75 final List<StickyAxisAnnotation> annotations = new ArrayList<>(); | |
76 final List<DurationWaterlevel> wqds = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel); | |
77 for (final DurationWaterlevel wqd : wqds) { | |
78 final String label = wqd.getBezeichnung().startsWith("W=") ? "Q(" + wqd.getBezeichnung() + ")" : wqd.getBezeichnung(); | |
79 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) wqd.getDischarge(), SimpleAxis.Y_AXIS, | |
80 FloodDurationCurveGenerator.YAXIS.Q.idx); | |
81 annotation.setHitPoint((float) wqd.getFloodDurDaysPerYear()); | |
82 annotations.add(annotation); | |
83 } | |
84 return annotations; | |
85 } | |
86 | |
87 /** | |
88 * Find and return the W or Q annotation(s) of a station and a riverside in a previously calculated result | |
89 * | |
90 * @param key | |
91 */ | |
92 public List<StickyAxisAnnotation> calcInfrastructureAnnotations(final Calculation problems, final double station, final boolean isW, | |
93 final FloodDurationCalculationResult result, final AttributeKey riverside) { | |
94 | |
95 final List<ResultRow> stationRows = searchStation(station, result.getAllRows(), riverside); | |
96 if (stationRows.isEmpty()) | |
97 return Collections.emptyList(); | |
98 | |
99 // Same way as in MainValueWFacet and ..QFacet | |
100 final List<StickyAxisAnnotation> annotations = new ArrayList<>(); | |
101 for (final ResultRow row : stationRows) { | |
102 if (isW) | |
103 annotations.add(calcInfrastructureWAnnotation(row)); | |
104 else | |
105 annotations.add(calcInfrastructureQAnnotation(row)); | |
106 } | |
107 return annotations; | |
108 } | |
109 | |
110 /** | |
111 * Calculates the Q annotation lines of an infrastructure | |
112 */ | |
113 private StickyAxisAnnotation calcInfrastructureQAnnotation(final ResultRow row) { | |
114 final String label = Resources.getMsg(this.m_context.getMeta(), "sinfo.chart.flood_duration.curve.infrastructure", | |
9614
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
115 "sinfo.chart.flood_duration.curve.infrastructure", getInfrastructureLabel(row)); |
9612 | 116 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.floodDischarge), SimpleAxis.Y_AXIS, |
117 FloodDurationCurveGenerator.YAXIS.Q.idx); | |
118 annotation.setHitPoint((float) row.getDoubleValue(SInfoResultType.floodDuration)); | |
119 return annotation; | |
120 } | |
121 | |
122 /** | |
123 * Calculates the W annotation lines of an infrastructure | |
124 */ | |
125 private StickyAxisAnnotation calcInfrastructureWAnnotation(final ResultRow row) { | |
126 final String label = Resources.getMsg(this.m_context.getMeta(), "sinfo.chart.flood_duration.curve.infrastructure", | |
9614
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
127 "sinfo.chart.flood_duration.curve.infrastructure", getInfrastructureLabel(row)); |
9612 | 128 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.infrastructureHeight), |
129 SimpleAxis.Y_AXIS, FloodDurationCurveGenerator.YAXIS.W.idx); | |
130 annotation.setHitPoint((float) row.getDoubleValue(SInfoResultType.floodDuration)); | |
131 return annotation; | |
132 } | |
133 | |
134 /** | |
9614
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
135 * Builds the label of the type and bank location of the infrastructure of a result row |
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
136 */ |
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
137 private String getInfrastructureLabel(final ResultRow row) { |
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
138 return SInfoResultType.getInfrastructureLabel(this.m_context, (String) row.getValue(SInfoResultType.infrastructuregroup), |
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
139 (String) row.getValue(SInfoResultType.infrastructuretype), (AttributeKey) row.getValue(SInfoResultType.riverside)); |
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
140 } |
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
141 |
d889ffe2fb05
Nachtrag Pos. 20: rename type/part to group/type, group added in Infrastructure class
mschaefer
parents:
9612
diff
changeset
|
142 /** |
9612 | 143 * Searches the one or two rows of a station in a result rows collection |
144 * | |
145 * @param m_riverside | |
146 */ | |
147 private List<ResultRow> searchStation(final double station, final Collection<ResultRow> rows, final AttributeKey riverside) { | |
148 | |
149 final double searchStation = findSearchStation(rows, station, riverside); | |
150 if (Double.isNaN(searchStation)) | |
151 return Collections.emptyList(); | |
152 | |
153 final List<ResultRow> found = new ArrayList<>(); | |
154 | |
155 for (final ResultRow row : rows) { // rows are not sorted | |
156 final String riversideStr = String.valueOf(row.getValue(SInfoResultType.riverside)); | |
157 if (riversideStr.equals("null")) | |
158 continue; | |
159 | |
160 if (Math.abs(row.getDoubleValue(GeneralResultType.station) - station) > DELTA_KM) | |
161 continue; | |
162 | |
163 if (riverside.equals(AttributeKey.NONE) || riverside.equals(AttributeKey.valueOf(String.valueOf(row.getValue(SInfoResultType.riverside))))) | |
164 found.add(row); | |
165 } | |
166 return found; | |
167 } | |
168 | |
169 @Deprecated | |
170 private double findSearchStation(final Collection<ResultRow> rows, final double station, final AttributeKey riverside) { | |
171 | |
172 if (!Double.isNaN(station)) | |
173 return station; | |
174 | |
175 for (final ResultRow row : rows) { | |
176 final String riversideStr = String.valueOf(row.getValue(SInfoResultType.riverside)); | |
177 if (riversideStr.equals("null")) | |
178 continue; | |
179 | |
180 if (riverside.equals(AttributeKey.NONE) || riverside.equals(AttributeKey.valueOf(riversideStr))) | |
181 return row.getDoubleValue(GeneralResultType.station); | |
182 } | |
183 | |
184 return Double.NaN; | |
185 } | |
186 } |