comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9257:ef7b65576d4b

Added W and Q main values to S-Info flood duration curve chart
author mschaefer
date Fri, 13 Jul 2018 18:38:05 +0200
parents c2a0028bfa9f
children 66b003701546
comparison
equal deleted inserted replaced
9256:6c24c857ccf9 9257:ef7b65576d4b
31 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; 31 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider;
32 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; 32 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
33 import org.dive4elements.river.artifacts.sinfo.common.WQBaseTableFinder; 33 import org.dive4elements.river.artifacts.sinfo.common.WQBaseTableFinder;
34 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; 34 import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey;
35 import org.dive4elements.river.exports.WaterlevelDescriptionBuilder; 35 import org.dive4elements.river.exports.WaterlevelDescriptionBuilder;
36 import org.dive4elements.river.jfree.RiverAnnotation;
37 import org.dive4elements.river.jfree.StickyAxisAnnotation;
38 import org.dive4elements.river.jfree.StickyAxisAnnotation.SimpleAxis;
36 import org.dive4elements.river.model.Attribute.AttributeKey; 39 import org.dive4elements.river.model.Attribute.AttributeKey;
37 import org.dive4elements.river.model.Gauge; 40 import org.dive4elements.river.model.Gauge;
38 import org.dive4elements.river.model.sinfo.InfrastructureValue; 41 import org.dive4elements.river.model.sinfo.InfrastructureValue;
39 42
40 import gnu.trove.TDoubleArrayList; 43 import gnu.trove.TDoubleArrayList;
114 this.rows.add(row2); 117 this.rows.add(row2);
115 } 118 }
116 } 119 }
117 results.addResult(new FloodDurationCalculationResult(label, mainValueLabels, this.rows), problems); 120 results.addResult(new FloodDurationCalculationResult(label, mainValueLabels, this.rows), problems);
118 calcWQDays(problems, stationsSorted[0], AttributeKey.LEFT, winfo, results); 121 calcWQDays(problems, stationsSorted[0], AttributeKey.LEFT, winfo, results);
119 } 122 calcMainValueAnnotations(label, problems, 0, AttributeKey.LEFT, wqkmsArray, mainValueLabels, results);
120 123 // TODO Infrastrukturhoehe
121 public void calcWQDays(final Calculation problems, final double station, final AttributeKey riverside, final WINFOArtifact winfo, 124 }
125
126 /**
127 * Calculate duration curve for a station and add to result collection
128 */
129 private void calcWQDays(final Calculation problems, final double station, final AttributeKey riverside, final WINFOArtifact winfo,
122 final FloodDurationCalculationResults results) { 130 final FloodDurationCalculationResults results) {
123 131
132 // Same processing as in W-Info DurationCurveState
124 winfo.addStringData("ld_locations", Double.toString(station)); 133 winfo.addStringData("ld_locations", Double.toString(station));
125 final CalculationResult res = winfo.getDurationCurveData(); 134 final CalculationResult res = winfo.getDurationCurveData();
126 final WQDay underflow = (WQDay) res.getData(); 135 final WQDay underflow = (WQDay) res.getData();
127 // Transform underflow days into overflow days and re-sort 136 // Transform underflow days into overflow days and re-sort
128 final int[] days = new int[underflow.getWs().length]; 137 final int[] days = new int[underflow.getWs().length];
132 days[j] = 365 - underflow.getDay(i); 141 days[j] = 365 - underflow.getDay(i);
133 ws[j] = underflow.getW(i); 142 ws[j] = underflow.getW(i);
134 qs[j] = underflow.getQ(i); 143 qs[j] = underflow.getQ(i);
135 } 144 }
136 res.setData(new WQDay(days, ws, qs)); 145 res.setData(new WQDay(days, ws, qs));
137 // TODO Infrastrukturhoehe
138 // TODO WSPL/Hauptwerte
139 results.setDurationCurve(res); 146 results.setDurationCurve(res);
147 }
148
149 /**
150 * Calculate the data for the W and Q main value lines in the duration curve chart and add to result collection
151 */
152 private void calcMainValueAnnotations(final String label, final Calculation problems, final int stationIndex, final AttributeKey riverside,
153 final WQKms[] wqkmsArray, final String[] mainValueLabels, final FloodDurationCalculationResults results) {
154
155 // Same way as in MainValueWFacet and ..QFacet
156 final List<StickyAxisAnnotation> ws = new ArrayList<>();
157 final List<StickyAxisAnnotation> qs = new ArrayList<>();
158 for (int i = 0; i <= wqkmsArray.length - 1; i++) {
159 final StickyAxisAnnotation qAnnotation = new StickyAxisAnnotation(mainValueLabels[i], (float) wqkmsArray[i].getQ(stationIndex), SimpleAxis.Y_AXIS,
160 FloodDurationCurveGenerator.YAXIS.Q.idx);
161 qs.add(qAnnotation);
162 setHitPoint((WQDay) results.getDurationCurve().getData(), qAnnotation);
163 final StickyAxisAnnotation wAnnotation = new StickyAxisAnnotation(mainValueLabels[i], (float) wqkmsArray[i].getW(stationIndex), SimpleAxis.Y_AXIS,
164 FloodDurationCurveGenerator.YAXIS.W.idx);
165 ws.add(wAnnotation);
166 setHitPoint((WQDay) results.getDurationCurve().getData(), wAnnotation);
167 }
168 // TODO RiverAnnotation ersetzen weil das eine NotSerializableException erzeugt
169 results.setMainValueQAnnotation(new RiverAnnotation(label, qs));
170 results.setMainValueWAnnotation(new RiverAnnotation(label, ws));
171 }
172
173 /**
174 * Set the hit-point in Q where a line drawn from the axis would hit the
175 * curve in WQDay (if hit).
176 * Employ linear interpolation.
177 */
178 private static void setHitPoint(final WQDay wqday, final StickyAxisAnnotation annotation) {
179
180 final float q = annotation.getPos();
181 final Double day = wqday.interpolateDayByQ(q);
182 if (day != null) {
183 annotation.setHitPoint(day.floatValue());
184 }
185 // else if (log.isDebugEnabled()) {
186 // log.debug("StickyAnnotation does not hit wqday curve: " + q);
187 // }
140 } 188 }
141 189
142 /** 190 /**
143 * Adds to a stations map all stations corresponding to the active range and step 191 * Adds to a stations map all stations corresponding to the active range and step
144 */ 192 */

http://dive4elements.wald.intevation.org