annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 339:4509ba8fae68

Implementation of "Abflusskurve/Abflusstafel" calculation. flys-artifacts/trunk@1738 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 20 Apr 2011 14:26:51 +0000
parents 64cfbd631f29
children 79401797f4e1
rev   line source
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.io.Serializable;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import de.intevation.flys.model.River;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import de.intevation.flys.model.Wst;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import de.intevation.flys.model.WstColumn;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import de.intevation.flys.backend.SessionHolder;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
11 import java.util.Arrays;
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import java.util.ArrayList;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.util.Comparator;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.util.List;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.util.Collections;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import java.util.Iterator;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
339
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
18 import org.apache.log4j.Logger;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
19
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
20 import org.apache.commons.math.analysis.interpolation.SplineInterpolator;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
21
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
22 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
23
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
24 import org.apache.commons.math.ArgumentOutsideDomainException;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
25
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 import org.hibernate.Session;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 import org.hibernate.Query;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 import org.hibernate.SQLQuery;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 import org.hibernate.type.StandardBasicTypes;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 public class WstValueTable
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 implements Serializable
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 {
339
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
35 private static Logger log = Logger.getLogger(WstValueTable.class);
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 // TODO: put this into a property file
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 public static final String SQL_POS_WQ =
327
e09634fbf6bc Moved the query complexity of creating a w/q value table into view
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 326
diff changeset
39 "SELECT position, w, q, column_pos" +
e09634fbf6bc Moved the query complexity of creating a w/q value table into view
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 326
diff changeset
40 " FROM wst_value_table" +
e09634fbf6bc Moved the query complexity of creating a w/q value table into view
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 326
diff changeset
41 " WHERE wst_id = :wst_id";
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
339
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
43 public static final double DEFAULT_STEP_WIDTH = 0.01;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
44
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 public static class Column
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 implements Serializable
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 protected String name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 public Column() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 public Column(String name) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 this.name = name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 public String getName() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 return name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public void setName(String name) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 this.name = name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 // class Column
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 public static class Row
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
68 implements Serializable, Comparable<Row>
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 double km;
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
71 double [] ws;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
72 double [] qs;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
73 boolean qSorted;
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 public Row() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
78 public Row(double km) {
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 this.km = km;
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
80 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
81
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
82 public Row(double km, double [] ws, double [] qs) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
83 this(km);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
84 this.ws = ws;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
85 this.qs = qs;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
86 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
87
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
88 public static final double linear(
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
89 double x,
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
90 double x1, double x2,
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
91 double y1, double y2
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
92 ) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
93 // y1 = m*x1 + b
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
94 // y2 = m*x2 + b
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
95 // y2 - y1 = m*(x2 - x1)
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
96 // m = (y2 - y1)/(x2 - x1) # x2 != x1
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
97 // b = y1 - m*x1
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
98
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
99 if (x1 == x2) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
100 return 0.5*(y1 + y2);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
101 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
102 double m = (y2 - y1)/(x2 - x1);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
103 double b = y1 - m*x1;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
104 return x*m + b;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
105 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
106
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
107 public static final double factor(double x, double p1, double p2) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
108 // 0 = m*p1 + b <=> b = -m*p1
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
109 // 1 = m*p2 + b
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
110 // 1 = m*(p2 - p1)
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
111 // m = 1/(p2 - p1) # p1 != p2
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
112 // f(x) = x/(p2-p1) - p1/(p2-p1) <=> (x-p1)/(p2-p1)
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
113
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
114 return p1 == p2 ? 0.0 : (x-p1)/(p2-p1);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
115 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
116
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
117 public static final double weight(double factor, double a, double b) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
118 return (1.0-factor)*a + factor*b;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
119 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
120
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
121 public double getWForKM(Row other, int index, double km) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
122 double w1 = ws[index];
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
123 double w2 = other.ws[index];
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
124 double km1 = this.km;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
125 double km2 = other.km;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
126 return linear(km, km1, km2, w1, w2);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
127 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
128
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
129 public void interpolateW(
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
130 Row other,
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
131 double km,
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
132 double [] input,
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
133 double [] output
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
134 ) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
135 double factor = factor(km, this.km, other.km);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
136
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
137 for (int i = 0; i < input.length; ++i) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
138 double q = input[i];
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
139 int idx1 = getQIndex(q);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
140 int idx2 = other.getQIndex(q);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
141
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
142 double w1 = idx1 >= 0
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
143 ? ws[idx1]
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
144 : interpolateW(-idx1-1, q);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
145
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
146 double w2 = idx2 >= 0
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
147 ? other.ws[idx2]
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
148 : other.interpolateW(-idx2-1, q);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
149
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
150 output[i] = weight(factor, w1, w2);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
151 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
152 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
153
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
154 public double interpolateW(int idx, double q) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
155 return idx < 1 || idx >= qs.length
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
156 ? Double.NaN // do not extrapolate
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
157 : linear(q, qs[idx-1], qs[idx], ws[idx-1], ws[idx]);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
158 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
159
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
160 public double interpolateW(double q) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
161 if (Double.isNaN(q)) return Double.NaN;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
162 int index = getQIndex(q);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
163 return index >= 0 ? ws[index] : interpolateW(-index -1);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
164 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
165
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
166 public int getQIndex(double q) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
167 return qSorted ? binaryQIndex(q) : linearQIndex(q);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
168 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
169
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
170 public int binaryQIndex(double q) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
171 return Arrays.binarySearch(qs, q);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
172 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
173
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
174 public int linearQIndex(double q) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
175 switch (qs.length) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
176 case 0: break;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
177 case 1:
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
178 if (qs[0] == q) return 0;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
179 if (qs[0] < q) return -(1+1);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
180 return -(0+1);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
181 default:
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
182 for (int i = 1; i < qs.length; ++i) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
183 double qa = qs[i-1];
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
184 double qb = qs[i];
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
185 if (qa == q) return i-1;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
186 if (qb == q) return i;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
187 if (qa > qb) { double t = qa; qa = qb; qb = t; }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
188 if (q > qa && q < qb) return -(i+1);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
189 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
190 return -qs.length;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
191 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
192
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
193 return -1;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
194 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
195
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
196 public int compareTo(Row other) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
197 double d = km - other.km;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
198 if (d < 0.0) return -1;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
199 if (d > 0.0) return +1;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
200 return 0;
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 }
339
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
202
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
203 public double [][] cloneWQs() {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
204 return new double [][] {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
205 (double [])ws.clone(),
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
206 (double [])ws.clone() };
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
207 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
208
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
209 public double [][] interpolateWQ(Row other, double km, double stepWidth) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
210
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
211 int W1 = ascendingWs();
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
212 int W2 = other.ascendingWs();
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
213
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
214 int W = Math.min(W1, W2);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
215
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
216 if (W < 1) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
217 return new double[2][0];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
218 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
219
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
220 double factor = factor(km, this.km, other.km);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
221
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
222 double minW = weight(factor, ws[0], other.ws[0]);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
223 double maxW = weight(factor, ws[W-1], other.ws[W-1]);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
224
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
225 if (minW > maxW) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
226 double t = minW;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
227 minW = maxW;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
228 maxW = t;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
229 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
230 double [] x = new double[W];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
231 double [] y = new double[W];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
232
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
233 for (int i = 0; i < W; ++i) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
234 x[i] = weight(factor, ws[i], other.ws[i]);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
235 y[i] = weight(factor, qs[i], other.qs[i]);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
236 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
237
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
238 SplineInterpolator interpolator = new SplineInterpolator();
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
239 PolynomialSplineFunction spline = interpolator.interpolate(x, y);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
240
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
241 double [] outWs =
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
242 new double[(int)Math.ceil((maxW - minW)/stepWidth)];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
243 double [] outQs =
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
244 new double[outWs.length];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
245
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
246 try {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
247 double w = minW;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
248 for (int i = 0; i < outWs.length; ++i, w += stepWidth) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
249 outQs[i] = spline.value(outWs[i] = w);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
250 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
251 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
252 catch (ArgumentOutsideDomainException aode) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
253 log.error("Spline interpolation failed.", aode);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
254 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
255
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
256 return new double [][] { outWs, outQs };
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
257
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
258 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
259
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
260 public double [][] interpolateWQ(double stepWidth) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
261 int W = ascendingWs(); // ignore back jumps
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
262
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
263 if (W < 1) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
264 return new double[2][0];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
265 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
266
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
267 double [] x = new double[W];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
268 double [] y = new double[W];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
269
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
270 for (int i = 0; i < W; ++i) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
271 x[i] = ws[i];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
272 y[i] = qs[i];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
273 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
274
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
275 SplineInterpolator interpolator = new SplineInterpolator();
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
276
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
277 PolynomialSplineFunction spline = interpolator.interpolate(x, y);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
278
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
279 double minW = ws[0];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
280 double maxW = ws[W-1];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
281
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
282 double [] outWs =
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
283 new double[(int)Math.ceil((maxW - minW)/stepWidth)];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
284 double [] outQs =
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
285 new double[outWs.length];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
286
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
287 try {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
288 double w = minW;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
289 for (int i = 0; i < outWs.length; ++i, w += stepWidth) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
290 outQs[i] = spline.value(outWs[i] = w);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
291 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
292 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
293 catch (ArgumentOutsideDomainException aode) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
294 log.error("Spline interpolation failed.", aode);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
295 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
296
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
297 return new double [][] { outWs, outQs };
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
298 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
299
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
300 public int ascendingWs() {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
301 if (ws.length < 2) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
302 return ws.length;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
303 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
304
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
305 int idx = 1;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
306
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
307 for (; idx < ws.length; ++idx) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
308 if (Double.isNaN(ws[idx]) || ws[idx] < ws[idx-1]) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
309 return idx;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
310 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
311 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
312
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
313 return idx;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
314 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
315
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
316 public double [][] weightWQs(Row other, double km) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
317 int W = Math.min(ws.length, other.ws.length);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
318 double factor = factor(km, this.km, other.km);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
319
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
320 double [] outWs = new double[W];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
321 double [] outQs = new double[W];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
322
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
323 for (int i = 0; i < W; ++i) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
324 outWs[i] = weight(factor, ws[i], other.ws[i]);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
325 outQs[i] = weight(factor, qs[i], other.qs[i]);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
326 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
327
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
328 return new double [][] { outWs, outQs };
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
329 }
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
330 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
331 // class Row
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
332
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
333 protected List<Row> rows;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
334
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
335 protected Column [] columns;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
336
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
337 public WstValueTable() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
338 rows = new ArrayList<Row>();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
339 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
340
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
341 public WstValueTable(Column [] columns) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
342 this();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
343 this.columns = columns;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
344 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
345
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
346
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
347 public double [] interpolateW(double km, double [] qs) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
348
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
349 double [] ws = new double[qs.length];
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
350
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
351 int rowIndex = Collections.binarySearch(rows, new Row(km));
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
352
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
353 if (rowIndex >= 0) { // direct row match
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
354 Row row = rows.get(rowIndex);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
355 for (int i = 0; i < qs.length; ++i) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
356 ws[i] = row.interpolateW(qs[i]);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
357 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
358 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
359 else { // needs bilinear interpolation
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
360 rowIndex = -rowIndex -1;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
361
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
362 if (rowIndex < 1 || rowIndex >= rows.size()) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
363 // do not extrapolate
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
364 Arrays.fill(ws, Double.NaN);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
365 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
366 else {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
367 rows.get(rowIndex-1).interpolateW(
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
368 rows.get(rowIndex),
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
369 km, qs, ws);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
370 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
371 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
372
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
373 return ws;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
374 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
375
339
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
376
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
377 public double [][] interpolateWQ(double km) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
378 return interpolateWQ(km, DEFAULT_STEP_WIDTH, true);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
379 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
380
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
381 public double [][] interpolateWQ(
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
382 double km,
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
383 double stepWidth,
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
384 boolean checkAscending
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
385 ) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
386 int rowIndex = Collections.binarySearch(rows, new Row(km));
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
387
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
388 if (rowIndex >= 0) { // direct row match
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
389 Row row = rows.get(rowIndex);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
390 return checkAscending
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
391 ? row.interpolateWQ(stepWidth)
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
392 : row.cloneWQs();
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
393 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
394
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
395 rowIndex = -rowIndex -1;
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
396
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
397 if (rowIndex < 1 || rowIndex >= rows.size()) {
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
398 // do not extrapolate
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
399 return new double[2][0];
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
400 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
401
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
402 Row r1 = rows.get(rowIndex-1);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
403 Row r2 = rows.get(rowIndex);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
404
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
405 return checkAscending
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
406 ? r1.interpolateWQ(r2, km, stepWidth)
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
407 : r1.weightWQs(r2, km);
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
408 }
4509ba8fae68 Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 335
diff changeset
409
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
410 public static WstValueTable getTable(River river) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
411 return getTable(river, 0);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
412 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
413
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
414 public static WstValueTable getTable(River river, int kind) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
415
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
416 Session session = SessionHolder.HOLDER.get();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
417
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
418 Query query = session.createQuery(
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
419 "from Wst where river=:river and kind=:kind");
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
420 query.setParameter("river", river);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
421 query.setInteger("kind", kind);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
422
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
423 List<Wst> wsts = query.list();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
424
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
425 if (wsts.isEmpty()) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
426 return null;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
427 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
428
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
429 Wst wst = wsts.get(0);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
430
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
431 // TODO: Do this sorting at database level
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
432 List<WstColumn> wstColumns = new ArrayList(wst.getColumns());
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
433 Collections.sort(wstColumns, new Comparator<WstColumn>() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
434 public int compare(WstColumn a, WstColumn b) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
435 int pa = a.getPosition();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
436 int pb = b.getPosition();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
437 if (pa < pb) return -1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
438 if (pa > pb) return +1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
439 return 0;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
440 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
441 });
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
442
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
443 Column [] columns = new Column[wstColumns.size()];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
444 for (int i = 0; i < columns.length; ++i) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
445 columns[i] = new Column(wstColumns.get(i).getName());
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
446 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
447
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
448 // using native SQL here to avoid myriad of small objects.
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
449 SQLQuery sqlQuery = session.createSQLQuery(SQL_POS_WQ)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
450 .addScalar("position", StandardBasicTypes.DOUBLE)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
451 .addScalar("w", StandardBasicTypes.DOUBLE)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
452 .addScalar("q", StandardBasicTypes.DOUBLE)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
453 .addScalar("column_pos", StandardBasicTypes.INTEGER);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
454
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
455 sqlQuery.setInteger("wst_id", wst.getId());
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
456
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
457 WstValueTable valueTable = new WstValueTable(columns);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
458
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
459 int lastColumnNo = -1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
460 Row row = null;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
461
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
462 Double lastQ = -Double.MAX_VALUE;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
463 boolean qSorted = true;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
464
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
465 for (Iterator<Object []> iter = sqlQuery.iterate(); iter.hasNext();) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
466 Object [] result = iter.next();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
467 double km = (Double) result[0];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
468 Double w = (Double) result[1];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
469 Double q = (Double) result[2];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
470 int columnNo = (Integer)result[3];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
471
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
472 if (columnNo > lastColumnNo) { // new row
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
473 if (row != null) {
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
474 row.qSorted = qSorted;
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
475 valueTable.rows.add(row);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
476 }
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
477 row = new Row(
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
478 km,
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
479 new double[columnNo+1],
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
480 new double[columnNo+1]);
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
481 lastQ = -Double.MAX_VALUE;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
482 qSorted = true;
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
483 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
484
335
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
485 row.ws[columnNo] = w != null ? w : Double.NaN;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
486 row.qs[columnNo] = q != null ? q : Double.NaN;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
487
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
488 if (qSorted && (q == null || lastQ > q)) {
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
489 qSorted = false;
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
490 }
64cfbd631f29 Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 327
diff changeset
491 lastQ = q;
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
492
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
493 lastColumnNo = columnNo;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
494 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
495
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
496 if (row != null) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
497 valueTable.rows.add(row);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
498 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
499
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
500 return valueTable;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
501 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
502 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
503 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org