annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/GaugeMainValueFinder.java @ 9206:b38be7ea53e2

Fixed approx char restaurated, findValue condition for zone name corrected
author mschaefer
date Mon, 02 Jul 2018 19:02:24 +0200
parents b4402594213b
children d9fda7af24ca
rev   line source
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
2 * Software engineering by
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
5 *
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
9 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
10 package org.dive4elements.river.artifacts.sinfo.common;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
11
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
12 import java.util.Map.Entry;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
13 import java.util.NavigableMap;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
14 import java.util.TreeMap;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
15
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
16 import org.dive4elements.river.artifacts.model.Calculation;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
17 import org.dive4elements.river.model.Gauge;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
18 import org.dive4elements.river.model.MainValue;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
19 import org.dive4elements.river.model.MainValueType.MainValueTypeKey;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
20
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
21 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
22 * Loading the main values of a gauge to find relative positions of a value and build a corresponding zone name
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
23 *
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
24 * @author Matthias Schäfer
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
25 *
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
26 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
27 public final class GaugeMainValueFinder {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
28
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
29 /***** FIELDS *****/
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
30
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
31 // private static Logger log = Logger.getLogger(GaugeMainValueNameFinder.class);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
32
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
33 private final Gauge gauge;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
34
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
35 private Calculation problems;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
36
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
37 private final NavigableMap<Double, MainValue> mainValues;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
38
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
39 private final MainValueTypeKey keyType;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
40
9206
b38be7ea53e2 Fixed approx char restaurated, findValue condition for zone name corrected
mschaefer
parents: 9202
diff changeset
41 private final String approxPrefix = "\u2248";
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
42
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
43 private Entry<Double, MainValue> foundCeiling;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
44
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
45 private Entry<Double, MainValue> foundFloor;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
46
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
47 private double foundRelativeDistance;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
48
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
49
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
50 /***** CONSTRUCTORS *****/
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
51
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
52 private GaugeMainValueFinder(final MainValueTypeKey keyType, final Gauge gauge, final Calculation problems) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
53 this.gauge = gauge;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
54 this.problems = problems;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
55 this.keyType = keyType;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
56 this.mainValues = new TreeMap<>();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
57 for (final MainValue mainValue : MainValue.getValuesOfGaugeAndType(gauge, keyType))
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
58 this.mainValues.put(Double.valueOf(mainValue.getValue().doubleValue()), mainValue);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
59 if (this.mainValues.isEmpty() && (this.problems != null)) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
60 this.problems.addProblem("gauge_main_values.missing", gauge.getName());
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
61 // Report only once
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
62 this.problems = null;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
63 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
64 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
65
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
66
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
67 /***** METHODS *****/
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
68
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
69 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
70 * Loads the the main values table of a type and a gauge (GAUGE.sta)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
71 *
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
72 * @return The main values finder of a type and a gauge, or null
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
73 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
74 public static GaugeMainValueFinder loadValues(final MainValueTypeKey type, final Gauge gauge, final Calculation problems) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
75 return new GaugeMainValueFinder(type, gauge, problems);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
76 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
77
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
78 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
79 * If this provider may return valid data at all.
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
80 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
81 public boolean isValid() {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
82 return (this.mainValues != null);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
83 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
84
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
85 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
86 * Searches the main value zone for a value, and returns a textual description of the zone
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
87 * (name for an exact match, circa expression for +/- 10% match, less-than/between/greater-than expression otherwise)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
88 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
89 public String findZoneName(final double value) {
9206
b38be7ea53e2 Fixed approx char restaurated, findValue condition for zone name corrected
mschaefer
parents: 9202
diff changeset
90 this.findValue(value);
b38be7ea53e2 Fixed approx char restaurated, findValue condition for zone name corrected
mschaefer
parents: 9202
diff changeset
91 if (Double.isNaN(this.foundRelativeDistance))
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
92 return "";
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
93
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
94 // Clearly below or just (max. 10%) below lowest named value
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
95 if (this.foundFloor == null) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
96 if (Double.isInfinite(this.foundRelativeDistance))
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
97 return "<" + this.foundCeiling.getValue().getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
98 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
99 return this.approxPrefix + this.foundCeiling.getValue().getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
100 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
101
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
102 // Clearly above or just (max. 10%) above highest named value
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
103 if (this.foundCeiling == null) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
104 if (Double.isInfinite(this.foundRelativeDistance))
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
105 return ">" + this.foundFloor.getValue().getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
106 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
107 return this.approxPrefix + this.foundFloor.getValue().getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
108 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
109
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
110 // Exact match
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
111 if (this.mainValues.containsKey(Double.valueOf(value)))
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
112 return this.mainValues.get(Double.valueOf(value)).getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
113
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
114 // Near (10%) one of the borders of a zone interval, or clearly within a zone
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
115 if (this.foundRelativeDistance <= 0.001)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
116 return this.foundFloor.getValue().getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
117 else if (this.foundRelativeDistance <= 0.1)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
118 return this.approxPrefix + this.foundFloor.getValue().getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
119 else if (this.foundRelativeDistance >= 0.9)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
120 return this.approxPrefix + this.foundCeiling.getValue().getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
121 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
122 return this.foundFloor.getValue().getMainValue().getName() + "-" + this.foundCeiling.getValue().getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
123 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
124
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
125 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
126 * Searches the main value zone for a value, and returns the zone name for an exact match, the nomatchReturn otherwise
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
127 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
128 public String findExactZoneName(final double value, final String noMatchReturn) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
129 this.findValue(value);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
130 if ((this.foundFloor != null) && (this.foundFloor.getKey() == this.foundCeiling.getKey()))
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
131 return this.foundFloor.getValue().getMainValue().getName();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
132 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
133 return noMatchReturn;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
134 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
135
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
136 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
137 * Searches the interval of a main value and its relative distance from the lower value
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
138 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
139 public boolean findValue(final double value) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
140 this.foundFloor = null;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
141 this.foundCeiling = null;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
142 this.foundRelativeDistance = Double.NaN;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
143 if (!this.isValid())
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
144 return false;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
145 if (Double.isNaN(value))
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
146 return false;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
147
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
148 // Clearly below or just (max. 10%) below lowest named value
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
149 this.foundFloor = this.mainValues.floorEntry(Double.valueOf(value));
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
150 if (this.foundFloor == null) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
151 this.foundCeiling = this.mainValues.firstEntry();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
152 if (value >= this.mainValues.firstKey().doubleValue() * 0.9) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
153 this.foundRelativeDistance = 0.9;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
154 return true;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
155 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
156 else {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
157 this.foundRelativeDistance = Double.NEGATIVE_INFINITY;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
158 return false;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
159 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
160 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
161
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
162 // Clearly above or just (max. 10%) above highest named value
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
163 this.foundCeiling = this.mainValues.ceilingEntry(Double.valueOf(value));
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
164 if (this.foundCeiling == null) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
165 if (value <= this.mainValues.lastKey().doubleValue() * 1.1) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
166 this.foundRelativeDistance = 0.1;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
167 return true;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
168 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
169 else {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
170 this.foundRelativeDistance = Double.POSITIVE_INFINITY;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
171 return false;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
172 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
173 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
174
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
175 // Exact match or within an interval
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
176 if (this.foundCeiling.getKey() == this.foundFloor.getKey())
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
177 this.foundRelativeDistance = 0.0;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
178 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
179 this.foundRelativeDistance = (value - this.foundFloor.getKey().doubleValue())
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
180 / (this.foundCeiling.getKey().doubleValue() - this.foundFloor.getKey().doubleValue());
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
181 return true;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
182 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
183
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
184 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
185 * Floor value of the last findValue
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
186 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
187 public MainValue getFoundFloorValue() {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
188 if (this.foundFloor != null)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
189 return this.foundFloor.getValue();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
190 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
191 return null;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
192 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
193
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
194 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
195 * Ceiling value of the last findValue
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
196 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
197 public MainValue getFoundCeilingValue() {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
198 if (this.foundCeiling != null)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
199 return this.foundCeiling.getValue();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
200 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
201 return null;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
202 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
203
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
204 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
205 * Relative distance of the last findValue
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
206 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
207 public double getFoundRelativeDistance() {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
208 return this.getFoundRelativeDistance();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
209 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
210
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
211 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
212 * Searches a pair of zone names and return the a value within the interval by a relative distance, or NaN
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
213 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
214 public double findValue(final String floorZone, final String ceilingZone, final double relativeDistance) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
215 this.foundFloor = null;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
216 this.foundCeiling = null;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
217 this.foundRelativeDistance = relativeDistance;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
218 for (final Entry<Double, MainValue> mainValue : this.mainValues.entrySet()) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
219 if (mainValue.getValue().getMainValue().getName().equalsIgnoreCase(floorZone)) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
220 this.foundFloor = mainValue;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
221 break;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
222 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
223 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
224 if (this.foundFloor == null)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
225 return Double.NaN;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
226 if (floorZone.equalsIgnoreCase(ceilingZone))
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
227 return this.foundFloor.getKey().doubleValue();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
228 for (final Entry<Double, MainValue> mainValue : this.mainValues.entrySet()) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
229 if (mainValue.getValue().getMainValue().getName().equalsIgnoreCase(ceilingZone)) {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
230 this.foundCeiling = mainValue;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
231 break;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
232 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
233 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
234 if (this.foundCeiling == null)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
235 return Double.NaN;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
236 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
237 return (this.foundCeiling.getKey().doubleValue() - this.foundFloor.getKey().doubleValue()) * this.foundRelativeDistance
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
238 + this.foundFloor.getKey().doubleValue();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
239 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
240 }

http://dive4elements.wald.intevation.org