Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FacetCalculator.java @ 9612:f8308db94634
#20 UI, Diagramme
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 09 Oct 2019 16:17:16 +0200 |
parents | |
children | d889ffe2fb05 |
comparison
equal
deleted
inserted
replaced
9611:8ed6c45136fa | 9612:f8308db94634 |
---|---|
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", | |
115 "sinfo.chart.flood_duration.curve.infrastructure", | |
116 SInfoResultType.infrastructuretype.exportValue(this.m_context, row.getValue(SInfoResultType.infrastructuretype)) + " - " | |
117 + SInfoResultType.infrastructurepart.exportValue(this.m_context, row.getValue(SInfoResultType.infrastructurepart)) + " (" | |
118 + SInfoResultType.riverside.exportValue(this.m_context, row.getValue(SInfoResultType.riverside)) + ")"); | |
119 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.floodDischarge), SimpleAxis.Y_AXIS, | |
120 FloodDurationCurveGenerator.YAXIS.Q.idx); | |
121 annotation.setHitPoint((float) row.getDoubleValue(SInfoResultType.floodDuration)); | |
122 return annotation; | |
123 } | |
124 | |
125 /** | |
126 * Calculates the W annotation lines of an infrastructure | |
127 */ | |
128 private StickyAxisAnnotation calcInfrastructureWAnnotation(final ResultRow row) { | |
129 final String label = Resources.getMsg(this.m_context.getMeta(), "sinfo.chart.flood_duration.curve.infrastructure", | |
130 "sinfo.chart.flood_duration.curve.infrastructure", | |
131 SInfoResultType.infrastructuretype.exportValue(this.m_context, row.getValue(SInfoResultType.infrastructuretype)) + " - " | |
132 + SInfoResultType.infrastructurepart.exportValue(this.m_context, row.getValue(SInfoResultType.infrastructurepart)) + " (" | |
133 + SInfoResultType.riverside.exportValue(this.m_context, row.getValue(SInfoResultType.riverside)) + ")"); | |
134 final StickyAxisAnnotation annotation = new StickyAxisAnnotation(label, (float) row.getDoubleValue(SInfoResultType.infrastructureHeight), | |
135 SimpleAxis.Y_AXIS, FloodDurationCurveGenerator.YAXIS.W.idx); | |
136 annotation.setHitPoint((float) row.getDoubleValue(SInfoResultType.floodDuration)); | |
137 return annotation; | |
138 } | |
139 | |
140 /** | |
141 * Searches the one or two rows of a station in a result rows collection | |
142 * | |
143 * @param m_riverside | |
144 */ | |
145 private List<ResultRow> searchStation(final double station, final Collection<ResultRow> rows, final AttributeKey riverside) { | |
146 | |
147 final double searchStation = findSearchStation(rows, station, riverside); | |
148 if (Double.isNaN(searchStation)) | |
149 return Collections.emptyList(); | |
150 | |
151 final List<ResultRow> found = new ArrayList<>(); | |
152 | |
153 for (final ResultRow row : rows) { // rows are not sorted | |
154 final String riversideStr = String.valueOf(row.getValue(SInfoResultType.riverside)); | |
155 if (riversideStr.equals("null")) | |
156 continue; | |
157 | |
158 if (Math.abs(row.getDoubleValue(GeneralResultType.station) - station) > DELTA_KM) | |
159 continue; | |
160 | |
161 if (riverside.equals(AttributeKey.NONE) || riverside.equals(AttributeKey.valueOf(String.valueOf(row.getValue(SInfoResultType.riverside))))) | |
162 found.add(row); | |
163 } | |
164 return found; | |
165 } | |
166 | |
167 @Deprecated | |
168 private double findSearchStation(final Collection<ResultRow> rows, final double station, final AttributeKey riverside) { | |
169 | |
170 if (!Double.isNaN(station)) | |
171 return station; | |
172 | |
173 for (final ResultRow row : rows) { | |
174 final String riversideStr = String.valueOf(row.getValue(SInfoResultType.riverside)); | |
175 if (riversideStr.equals("null")) | |
176 continue; | |
177 | |
178 if (riverside.equals(AttributeKey.NONE) || riverside.equals(AttributeKey.valueOf(riversideStr))) | |
179 return row.getDoubleValue(GeneralResultType.station); | |
180 } | |
181 | |
182 return Double.NaN; | |
183 } | |
184 } |