comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/GaugeDischargeZoneFinder.java @ 9157:f9bb5d0a6ff3

Added the S-Info collision calculation and chart output
author mschaefer
date Tue, 19 Jun 2018 14:19:32 +0200
parents
children a4121ec450d6
comparison
equal deleted inserted replaced
9156:568961ff709a 9157:f9bb5d0a6ff3
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.collision;
11
12 import java.util.Map.Entry;
13 import java.util.NavigableMap;
14 import java.util.TreeMap;
15
16 import org.dive4elements.river.artifacts.model.Calculation;
17 import org.dive4elements.river.model.Gauge;
18 import org.dive4elements.river.model.MainValue;
19 import org.dive4elements.river.model.MainValueType.MainValueTypeKey;
20
21 /**
22 * Loading and search the discharge zones of a gauge
23 *
24 * @author Matthias Schäfer
25 *
26 */
27 public final class GaugeDischargeZoneFinder {
28
29 /***** FIELDS *****/
30
31 // private static Logger log = Logger.getLogger(GaugeDischargeZoneFinder.class);
32
33 private final Gauge gauge;
34
35 private final Calculation problems;
36
37 private final NavigableMap<Double, MainValue> qZones;
38
39 private final String approxPrefix = "ca."; // "\u2248" geht wohl nicht
40
41
42 /***** CONSTRUCTORS *****/
43
44 private GaugeDischargeZoneFinder(final Gauge gauge, final Calculation problems) {
45 this.gauge = gauge;
46 this.problems = problems;
47 this.qZones = new TreeMap<>();
48 for (final MainValue mainValue : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.Q))
49 this.qZones.put(Double.valueOf(mainValue.getValue().doubleValue()), mainValue);
50 }
51
52
53 /***** METHODS *****/
54
55 /**
56 * Loads the the main discharge table of a gauge (GAUGE.at)
57 *
58 * @return The discharge table values finder of the gauge, or null
59 */
60 public static GaugeDischargeZoneFinder loadValues(final Gauge gauge, final Calculation problems) {
61 return new GaugeDischargeZoneFinder(gauge, problems);
62 }
63
64 /**
65 * If this provider may return valid data at all.
66 */
67 public boolean isValid() {
68 return (this.qZones != null);
69 }
70
71 /**
72 * Discharge zone for a Q.
73 */
74 public String getDischargeZone(final double q) {
75 if (Double.isNaN(q))
76 return "";
77
78 // Exact match
79 if (this.qZones.containsKey(Double.valueOf(q)))
80 return this.qZones.get(Double.valueOf(q)).getMainValue().getName();
81
82 // Clearly below or just (max. 10%) below lowest named discharge
83 final Entry<Double, MainValue> lowerZone = this.qZones.floorEntry(Double.valueOf(q));
84 if (lowerZone == null) {
85 if (q >= this.qZones.firstKey().doubleValue() * 0.9)
86 return this.approxPrefix + this.qZones.firstEntry().getValue().getMainValue().getName();
87 else
88 return "<" + this.qZones.firstEntry().getValue().getMainValue().getName();
89 }
90
91 // Clearly above or just (max. 10%) above highest named discharge
92 final Entry<Double, MainValue> higherZone = this.qZones.ceilingEntry(Double.valueOf(q));
93 if (higherZone == null) {
94 if (q <= this.qZones.lastKey().doubleValue() * 1.1)
95 return this.approxPrefix + this.qZones.lastEntry().getValue().getMainValue().getName();
96 else
97 return ">" + this.qZones.lastEntry().getValue().getMainValue().getName();
98 }
99
100 // Near (10%) one of the borders of a zone interval, or clearly within a zone
101 if (q <= lowerZone.getKey().doubleValue() * 1.1)
102 return this.approxPrefix + lowerZone.getValue().getMainValue().getName();
103 else if (q >= higherZone.getKey().doubleValue() * 0.9)
104 return this.approxPrefix + higherZone.getValue().getMainValue().getName();
105 else
106 return lowerZone.getValue().getMainValue().getName() + "-" + higherZone.getValue().getMainValue().getName();
107 }
108 }

http://dive4elements.wald.intevation.org