annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java @ 5733:b7d631e45ee7

FixCalculation: Cosmetics, renamed function, doc.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 16 Apr 2013 12:45:51 +0200
parents 345f3bba6f15
children 6e6753b9757f
rev   line source
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model.fixings;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
3 import de.intevation.artifacts.common.utils.StringUtils;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
4
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import de.intevation.flys.artifacts.access.FixAccess;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import de.intevation.flys.artifacts.math.fitting.Function;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import de.intevation.flys.artifacts.model.Calculation;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import de.intevation.flys.artifacts.model.CalculationResult;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import de.intevation.flys.artifacts.model.FixingsColumn;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import de.intevation.flys.artifacts.model.FixingsColumnFactory;
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
14
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
15 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing.Filter;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
16
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
17 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
18 import de.intevation.flys.artifacts.model.FixingsOverview.IdsFilter;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
19
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import de.intevation.flys.artifacts.model.FixingsOverview;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 import de.intevation.flys.artifacts.model.FixingsOverviewFactory;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 import de.intevation.flys.artifacts.model.Parameters;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 import de.intevation.flys.utils.DoubleUtil;
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
25 import de.intevation.flys.utils.KMIndex;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 import java.util.ArrayList;
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
28 import java.util.Date;
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
29 import java.util.HashMap;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
30 import java.util.List;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
31 import java.util.Map;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 import org.apache.log4j.Logger;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
5150
345f3bba6f15 Doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3970
diff changeset
35 /** Calculation base class for fix. */
3437
e111902834d3 FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3435
diff changeset
36 public abstract class FixCalculation
e111902834d3 FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3435
diff changeset
37 extends Calculation
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 {
2786
f9e62e76ee1f FixA: Return correct data structure from calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2783
diff changeset
39 private static Logger log = Logger.getLogger(FixCalculation.class);
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
41 public static final double EPSILON = 1e-4;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
42
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
43 public static final String [] STANDARD_COLUMNS = {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
44 "km", "chi_sqr", "max_q", "std-dev"
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
45 };
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
46
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
47 protected static class FitResult {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
48
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
49 protected Parameters parameters;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
50 protected KMIndex<QWD []> referenced;
3729
e727e3ebdf85 Factored out a pure QW model to be more reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3604
diff changeset
51 protected KMIndex<QWI []> outliers;
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
52
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
53 public FitResult() {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
54 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
55
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
56 public FitResult(
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
57 Parameters parameters,
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
58 KMIndex<QWD []> referenced,
3729
e727e3ebdf85 Factored out a pure QW model to be more reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3604
diff changeset
59 KMIndex<QWI []> outliers
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
60 ) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
61 this.parameters = parameters;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
62 this.referenced = referenced;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
63 this.outliers = outliers;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
64 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
65
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
66 public Parameters getParameters() {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
67 return parameters;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
68 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
69
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
70 public KMIndex<QWD []> getReferenced() {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
71 return referenced;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
72 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
73
3729
e727e3ebdf85 Factored out a pure QW model to be more reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3604
diff changeset
74 public KMIndex<QWI []> getOutliers() {
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
75 return outliers;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
76 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
77 } // class FitResult
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
78
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
79 /** Helper class to bundle the meta information of a column
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
80 * and the real data.
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
81 */
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
82 protected static class Column {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
83
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
84 protected Fixing.Column meta;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
85 protected FixingsColumn data;
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
86 protected int index;
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
87
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
88 public Column() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
89 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
90
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
91 public Column(Fixing.Column meta, FixingsColumn data, int index) {
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
92 this.meta = meta;
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
93 this.data = data;
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
94 this.index = index;
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
95 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
96
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
97 public Date getDate() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
98 return meta.getStartTime();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
99 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
100
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
101 public String getDescription() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
102 return meta.getDescription();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
103 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
104
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
105 public int getIndex() {
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
106 return index;
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
107 }
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
108
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
109 public boolean getQW(
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
110 double km,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
111 double [] qs,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
112 double [] ws,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
113 int index
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
114 ) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
115 qs[index] = data.getQ(km);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
116 return data.getW(km, ws, index);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
117 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
118
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
119 public boolean getQW(double km, double [] wq) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
120 data.getW(km, wq, 0);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
121 if (Double.isNaN(wq[0])) return false;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
122 wq[1] = data.getQ(km);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
123 return !Double.isNaN(wq[1]);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
124 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
125 } // class Column
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
126
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
127 /**
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
128 * Helper class to find the data belonging to meta info more quickly.
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
129 */
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
130 protected static class ColumnCache {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
131
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
132 protected Map<Integer, Column> columns;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
133
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
134 public ColumnCache() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
135 columns = new HashMap<Integer, Column>();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
136 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
137
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
138 public Column getColumn(Fixing.Column meta) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
139 Integer key = meta.getId();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
140 Column column = columns.get(key);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
141 if (column == null) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
142 FixingsColumn data = FixingsColumnFactory
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
143 .getInstance()
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
144 .getColumnData(meta);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
145 if (data != null) {
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
146 column = new Column(meta, data, columns.size());
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
147 columns.put(key, column);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
148 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
149 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
150 return column;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
151 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
152 } // class ColumnCache
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
153
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
154
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 protected String river;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 protected double from;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 protected double to;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 protected double step;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 protected boolean preprocessing;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 protected String function;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 protected int [] events;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 protected int qSectorStart;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 protected int qSectorEnd;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 public FixCalculation() {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 public FixCalculation(FixAccess access) {
3451
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
169 String river = access.getRiver();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
170 Double from = access.getFrom();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
171 Double to = access.getTo();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
172 Double step = access.getStep();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
173 String function = access.getFunction();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
174 int [] events = access.getEvents();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
175 Integer qSectorStart = access.getQSectorStart();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
176 Integer qSectorEnd = access.getQSectorEnd();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
177 Boolean preprocessing = access.getPreprocessing();
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 if (river == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 addProblem("fix.missing.river");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 if (from == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 addProblem("fix.missing.from");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 if (to == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 addProblem("fix.missing.to");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 if (step == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 addProblem("fix.missing.step");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 if (function == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 addProblem("fix.missing.function");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 if (events == null || events.length < 1) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 addProblem("fix.missing.events");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
203 if (qSectorStart == null) {
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
204 addProblem("fix.missing.qstart.sector");
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
205 }
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
206
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
207 if (qSectorEnd == null) {
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
208 addProblem("fix.missing.qend.sector");
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
209 }
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
210
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
211 if (preprocessing == null) {
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212 addProblem("fix.missing.preprocessing");
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 }
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215 if (!hasProblems()) {
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
216 this.river = river;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
217 this.from = from;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
218 this.to = to;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
219 this.step = step;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220 this.function = function;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 this.events = events;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222 this.qSectorStart = qSectorStart;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 this.qSectorEnd = qSectorEnd;
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 this.preprocessing = preprocessing;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
227
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
228 protected static String toString(
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
229 String [] parameterNames,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
230 double [] values
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
231 ) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
232 StringBuilder sb = new StringBuilder();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
233 for (int i = 0; i < parameterNames.length; ++i) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
234 if (i > 0) sb.append(", ");
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
235 sb.append(parameterNames[i]).append(": ").append(values[i]);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
236 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
237 return sb.toString();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
238 }
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239
5733
b7d631e45ee7 FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5150
diff changeset
240
b7d631e45ee7 FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5150
diff changeset
241 /** Create an ID Filter to accept only the chosen event ids. */
b7d631e45ee7 FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5150
diff changeset
242 protected Filter createEventIDFilter() {
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
243 return new IdsFilter(events);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
244 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
245
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
246 protected List<Column> getEventColumns(
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
247 FixingsOverview overview,
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
248 ColumnCache cc
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
249 ) {
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
250 FixingsColumnFactory fcf = FixingsColumnFactory.getInstance();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
251
5733
b7d631e45ee7 FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5150
diff changeset
252 Filter filter = createEventIDFilter();
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
253
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
254 List<Fixing.Column> metas = overview.filter(null, filter);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
255
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
256 List<Column> columns = new ArrayList<Column>(metas.size());
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
257
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
258 for (Fixing.Column meta: metas) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
259
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
260 Column data = cc.getColumn(meta);
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
261 if (data == null) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
262 addProblem("fix.cannot.load.data");
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
263 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
264 else {
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
265 columns.add(data);
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
266 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
267 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
268
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
269 return columns;
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
270 }
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
271
5733
b7d631e45ee7 FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5150
diff changeset
272 // Fit a function to the given points from fixation.
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
273 protected FitResult doFitting(
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
274 FixingsOverview overview,
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
275 ColumnCache cc,
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
276 Function func
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
277 ) {
2792
fe987587ebc9 Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2788
diff changeset
278 boolean debug = log.isDebugEnabled();
fe987587ebc9 Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2788
diff changeset
279
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
280 final List<Column> eventColumns = getEventColumns(overview, cc);
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
281
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
282 if (eventColumns.size() < 2) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
283 addProblem("fix.too.less.data.columns");
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
284 return null;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
285 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
286
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
287 final double [] qs = new double[eventColumns.size()];
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
288 final double [] ws = new double[qs.length];
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
289 final boolean [] interpolated = new boolean[ws.length];
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
290
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
291 Fitting.QWDFactory qwdFactory = new Fitting.QWDFactory() {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
292 @Override
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
293 public QWD create(double q, double w) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
294 // Check all the event columns for close match
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
295 // and take the description and the date from meta.
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
296 for (int i = 0; i < qs.length; ++i) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
297 if (Math.abs(qs[i]-q) < EPSILON
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
298 && Math.abs(ws[i]-w) < EPSILON) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
299 Column column = eventColumns.get(i);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
300 return new QWD(
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
301 qs[i], ws[i],
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
302 column.getDescription(),
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
303 column.getDate(),
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
304 interpolated[i],
3604
2382b26079ac FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3603
diff changeset
305 0d,
2382b26079ac FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3603
diff changeset
306 column.getIndex());
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
307 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
308 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
309 log.warn("cannot find column for (" + q + ", " + w + ")");
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
310 return new QWD(q, w);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
311 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
312 };
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
313
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
314 Fitting fitting = new Fitting(func, qwdFactory, preprocessing);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
315
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
316 String [] parameterNames = func.getParameterNames();
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
317
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
318 Parameters results =
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
319 new Parameters(
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
320 StringUtils.join(STANDARD_COLUMNS, parameterNames));
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
321
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
322 boolean invalid = false;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
323
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
324 double [] kms = DoubleUtil.explode(from, to, step / 1000.0);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
325
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
326 if (debug) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
327 log.debug("number of kms: " + kms.length);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
328 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
329
3729
e727e3ebdf85 Factored out a pure QW model to be more reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3604
diff changeset
330 KMIndex<QWI []> outliers = new KMIndex<QWI []>();
3435
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
331 KMIndex<QWD []> referenced = new KMIndex<QWD []>(kms.length);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
332
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
333 int kmIndex = results.columnIndex("km");
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
334 int chiSqrIndex = results.columnIndex("chi_sqr");
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
335 int maxQIndex = results.columnIndex("max_q");
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
336 int stdDevIndex = results.columnIndex("std-dev");
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
337 int [] parameterIndices = results.columnIndices(parameterNames);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
338
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
339 int numFailed = 0;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
340
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
341 for (int i = 0; i < kms.length; ++i) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
342 double km = kms[i];
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
343
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
344 // Fill Qs and Ws from event columns.
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
345 for (int j = 0; j < ws.length; ++j) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
346 interpolated[j] = !eventColumns.get(j).getQW(km, qs, ws, j);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
347 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
348
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
349 fitting.reset();
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
350
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
351 if (!fitting.fit(qs, ws)) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
352 ++numFailed;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
353 addProblem(km, "fix.fitting.failed");
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
354 continue;
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
355 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
356
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
357 referenced.add(km, fitting.referencedToArray());
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
358
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
359 if (fitting.hasOutliers()) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
360 outliers.add(km, fitting.outliersToArray());
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
361 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
362
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
363 int row = results.newRow();
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
364 double [] values = fitting.getParameters();
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
365
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
366 results.set(row, kmIndex, km);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
367 results.set(row, chiSqrIndex, fitting.getChiSquare());
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
368 results.set(row, stdDevIndex, fitting.getStandardDeviation());
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
369 results.set(row, maxQIndex, fitting.getMaxQ());
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
370 invalid |= results.set(row, parameterIndices, values);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
371
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
372 if (debug) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
373 log.debug("km: "+km+" " + toString(parameterNames, values));
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
374 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
375 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
376
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
377 if (debug) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
378 log.debug("success: " + (kms.length - numFailed));
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
379 log.debug("failed: " + numFailed);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
380 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
381
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
382 if (invalid) {
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
383 addProblem("fix.invalid.values");
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
384 results.removeNaNs();
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
385 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
386
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
387 outliers.sort();
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
388 referenced.sort();
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
389
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
390 return new FitResult(
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
391 results,
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
392 referenced,
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
393 outliers);
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
394 }
3437
e111902834d3 FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3435
diff changeset
395
e111902834d3 FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3435
diff changeset
396 public CalculationResult calculate() {
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
397 FixingsOverview overview =
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
398 FixingsOverviewFactory.getOverview(river);
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
399
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
400 if (overview == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
401 addProblem("fix.no.overview.available");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
402 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
403
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
404 Function func = FunctionFactory.getInstance()
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
405 .getFunction(function);
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
406
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
407 if (func == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
408 addProblem("fix.invalid.function.name");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
409 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
410
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
411 if (hasProblems()) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
412 return new CalculationResult(this);
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
413 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
414
3437
e111902834d3 FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3435
diff changeset
415 return innerCalculate(overview, func);
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
416 }
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
417
3437
e111902834d3 FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3435
diff changeset
418 protected abstract CalculationResult innerCalculate(
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
419 FixingsOverview overview,
3437
e111902834d3 FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3435
diff changeset
420 Function function
e111902834d3 FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3435
diff changeset
421 );
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
422 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
423 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org