annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/GaugeMainValueFinder.java @ 9540:0c114309d2a0

Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
author mschaefer
date Wed, 17 Oct 2018 16:07:22 +0200
parents d9fda7af24ca
children
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;
9533
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
20 import org.dive4elements.river.model.River;
9202
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 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
23 * 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
24 *
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
25 * @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
26 *
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
27 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
28 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
29
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
30 /***** FIELDS *****/
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
31
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
32 // 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
33
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
34 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
35
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
36 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
37
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
38 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
39
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
40 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
41
9206
b38be7ea53e2 Fixed approx char restaurated, findValue condition for zone name corrected
mschaefer
parents: 9202
diff changeset
42 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
43
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
44 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
45
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
46 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
47
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
48 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
49
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
50
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
51 /***** CONSTRUCTORS *****/
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
52
9540
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
53 private GaugeMainValueFinder(final MainValueTypeKey keyType, final Gauge gauge, final String gaugeName, final Calculation problems,
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
54 final String... excludingNames) {
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
55 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
56 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
57 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
58 this.mainValues = new TreeMap<>();
9533
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
59 if (gauge != null) {
9540
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
60 boolean skip;
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
61 for (final MainValue mainValue : MainValue.getValuesOfGaugeAndType(gauge, keyType)) {
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
62 skip = false;
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
63 for (final String excluding : excludingNames) {
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
64 if (mainValue.getMainValue().getName().equalsIgnoreCase(excluding)) {
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
65 skip = true;
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
66 break;
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
67 }
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
68 }
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
69 if (!skip)
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
70 this.mainValues.put(Double.valueOf(mainValue.getValue().doubleValue()), mainValue);
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
71 }
9533
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
72 }
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
73 if (this.mainValues.isEmpty() && (this.problems != null)) {
9533
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
74 this.problems.addProblem("gauge_main_values.missing", gaugeName);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
75 // 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
76 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
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
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 /***** METHODS *****/
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
82
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
83 /**
9533
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
84 * Loads the the main values table of a type and a gauge ({gauge}.sta)
9202
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 * @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
87 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
88 public static GaugeMainValueFinder loadValues(final MainValueTypeKey type, final Gauge gauge, final Calculation problems) {
9533
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
89 return new GaugeMainValueFinder(type, gauge, gauge.getName(), problems);
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
90 }
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
91
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
92 /**
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
93 * Loads the the main values table of a type and a river's gauge ({gauge}.sta)
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
94 *
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
95 * @return The main values finder of the type and gauge, or null
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
96 */
9540
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
97 public static GaugeMainValueFinder loadValues(final MainValueTypeKey type, final River river, final String gaugeName, final Calculation problems,
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
98 final String... excludingNames) {
9533
d9fda7af24ca No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents: 9206
diff changeset
99 final Gauge gauge = river.determineGaugeByName(gaugeName);
9540
0c114309d2a0 Discharge zone for sinfo collision output without GLQ (Meilenstein 2, 2.1.4)
mschaefer
parents: 9533
diff changeset
100 return new GaugeMainValueFinder(type, gauge, gaugeName, problems, excludingNames);
9202
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
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
103 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
104 * 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
105 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
106 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
107 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
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 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
111 * 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
112 * (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
113 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
114 public String findZoneName(final double value) {
9206
b38be7ea53e2 Fixed approx char restaurated, findValue condition for zone name corrected
mschaefer
parents: 9202
diff changeset
115 this.findValue(value);
b38be7ea53e2 Fixed approx char restaurated, findValue condition for zone name corrected
mschaefer
parents: 9202
diff changeset
116 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
117 return "";
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
118
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
119 // 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
120 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
121 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
122 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
123 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
124 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
125 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
126
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
127 // 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
128 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
129 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
130 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
131 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
132 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
133 }
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 // Exact match
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
136 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
137 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
138
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
139 // 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
140 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
141 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
142 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
143 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
144 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
145 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
146 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
147 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
148 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
149
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
150 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
151 * 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
152 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
153 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
154 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
155 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
156 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
157 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
158 return noMatchReturn;
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 * 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
163 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
164 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
165 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
166 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
167 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
168 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
169 return false;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
170 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
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 // 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
174 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
175 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
176 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
177 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
178 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
179 return true;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
180 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
181 else {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
182 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
183 return false;
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 }
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 // 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
188 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
189 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
190 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
191 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
192 return true;
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 else {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
195 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
196 return false;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
197 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
198 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
199
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
200 // 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
201 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
202 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
203 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
204 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
205 / (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
206 return true;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
207 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
208
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 * 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
211 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
212 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
213 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
214 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
215 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
216 return null;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
217 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
218
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
219 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
220 * 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
221 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
222 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
223 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
224 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
225 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
226 return null;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
227 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
228
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
229 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
230 * 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
231 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
232 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
233 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
234 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
235
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
236 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
237 * 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
238 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
239 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
240 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
241 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
242 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
243 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
244 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
245 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
246 break;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
247 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
248 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
249 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
250 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
251 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
252 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
253 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
254 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
255 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
256 break;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
257 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
258 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
259 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
260 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
261 else
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
262 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
263 + 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
264 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
265 }

http://dive4elements.wald.intevation.org