comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/GaugeDurationValuesFinder.java @ 9202:b4402594213b

More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
author mschaefer
date Mon, 02 Jul 2018 07:33:53 +0200
parents a4121ec450d6
children 9b16f58c62a7
comparison
equal deleted inserted replaced
9201:491e1a434457 9202:b4402594213b
19 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; 19 import org.dive4elements.river.model.MainValueType.MainValueTypeKey;
20 20
21 import gnu.trove.TDoubleArrayList; 21 import gnu.trove.TDoubleArrayList;
22 22
23 /** 23 /**
24 * Loading and search/interpolate the duration main values of a gauge 24 * Search/interpolation of the duration main values of a gauge
25 * 25 *
26 * @author Matthias Schäfer 26 * @author Matthias Schäfer
27 * 27 *
28 */ 28 */
29 public final class GaugeDurationValuesFinder { 29 public final class GaugeDurationValuesFinder {
47 private final String approxPrefix = "\u2248";// "ca."; 47 private final String approxPrefix = "\u2248";// "ca.";
48 48
49 /***** CONSTRUCTORS *****/ 49 /***** CONSTRUCTORS *****/
50 50
51 private GaugeDurationValuesFinder(final Gauge gauge, final Calculation problems) { 51 private GaugeDurationValuesFinder(final Gauge gauge, final Calculation problems) {
52 // Load the duration main values from the database (each duration has a Q)
52 this.gauge = gauge; 53 this.gauge = gauge;
53 this.problems = problems; 54 this.problems = problems;
54 final TDoubleArrayList qs = new TDoubleArrayList(); 55 final TDoubleArrayList qs = new TDoubleArrayList();
55 final TDoubleArrayList durs = new TDoubleArrayList(); 56 final TDoubleArrayList durs = new TDoubleArrayList();
56 for (final MainValue v : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.DURATION)) { 57 for (final MainValue v : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.DURATION)) {
57 qs.add(v.getValue().doubleValue()); 58 qs.add(v.getValue().doubleValue());
58 durs.add(Integer.valueOf(v.getMainValue().getName()).doubleValue()); 59 durs.add(Integer.valueOf(v.getMainValue().getName()).doubleValue());
59 } 60 }
61 // Build the duration-by-Q interpolator
60 try { 62 try {
61 this.qInterpolator = new LinearInterpolator().interpolate(qs.toNativeArray(), durs.toNativeArray()); 63 this.qInterpolator = new LinearInterpolator().interpolate(qs.toNativeArray(), durs.toNativeArray());
62 this.qRange = new DoubleRange(qs.get(0), qs.get(qs.size() - 1)); 64 this.qRange = new DoubleRange(qs.get(0), qs.get(qs.size() - 1));
63 } 65 }
64 catch (final Exception e) { 66 catch (final Exception e) {
65 this.qInterpolator = null; 67 this.qInterpolator = null;
66 this.qRange = null; 68 this.qRange = null;
67 } 69 }
70 // Load the Q values by duration from the database
68 qs.clear(); 71 qs.clear();
69 durs.clear(); 72 durs.clear();
70 for (final MainValue v : MainValue.getDurationDischargesOfGauge(gauge)) { 73 for (final MainValue v : MainValue.getDurationDischargesOfGauge(gauge)) {
71 durs.add(Integer.valueOf(v.getMainValue().getName()).doubleValue()); 74 durs.add(Integer.valueOf(v.getMainValue().getName()).doubleValue());
72 qs.add(v.getValue().doubleValue()); 75 qs.add(v.getValue().doubleValue());
73 } 76 }
77 // Build the Q-by-duration interpolator
74 try { 78 try {
75 this.durInterpolator = new LinearInterpolator().interpolate(durs.toNativeArray(), qs.toNativeArray()); 79 this.durInterpolator = new LinearInterpolator().interpolate(durs.toNativeArray(), qs.toNativeArray());
76 this.durRange = new DoubleRange(durs.get(0), durs.get(durs.size() - 1)); 80 this.durRange = new DoubleRange(durs.get(0), durs.get(durs.size() - 1));
77 } 81 }
78 catch (final Exception e) { 82 catch (final Exception e) {
79 this.durInterpolator = null; 83 this.durInterpolator = null;
80 this.durRange = null; 84 this.durRange = null;
81 } 85 }
86 // Report problems
82 if (((this.qInterpolator == null) || (this.durInterpolator == null)) && (this.problems != null)) { 87 if (((this.qInterpolator == null) || (this.durInterpolator == null)) && (this.problems != null)) {
83 this.problems.addProblem("gauge_duration.missing", gauge.getName()); 88 this.problems.addProblem("gauge_duration.missing", gauge.getName());
84 // Report only once 89 // Report only once
85 this.problems = null; 90 this.problems = null;
86 } 91 }
87 } 92 }
88 93
89 /***** METHODS *****/ 94 /***** METHODS *****/
90 95
91 /** 96 /**
92 * Loads the the discharge-duration table of a gauge (GAUGE.glt) 97 * Loads the the discharge-duration table of a gauge ({gauge}.sta)
93 * 98 *
94 * @return The main values finder of a a gauge, or null 99 * @return The main values finder of a a gauge, or null
95 */ 100 */
96 public static GaugeDurationValuesFinder loadValues(final Gauge gauge, final Calculation problems) { 101 public static GaugeDurationValuesFinder loadValues(final Gauge gauge, final Calculation problems) {
97 return new GaugeDurationValuesFinder(gauge, problems); 102 return new GaugeDurationValuesFinder(gauge, problems);

http://dive4elements.wald.intevation.org