annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java @ 5863:4897a58c8746

River artifacts: Added new copyright headers.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:40:59 +0200
parents 5aa05a7a34b7
children af13ceeba52a
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
9 package org.dive4elements.river.artifacts.model.fixings;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
11 import org.dive4elements.artifacts.common.utils.StringUtils;
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
12
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
13 import org.dive4elements.river.artifacts.access.FixAccess;
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
14
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
15 import org.dive4elements.river.artifacts.math.fitting.Function;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
16 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
18 import org.dive4elements.river.artifacts.model.Calculation;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
19 import org.dive4elements.river.artifacts.model.CalculationResult;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
20 import org.dive4elements.river.artifacts.model.FixingsColumn;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
21 import org.dive4elements.river.artifacts.model.FixingsColumnFactory;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
22
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
23 import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing.Filter;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
24
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
25 import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
26 import org.dive4elements.river.artifacts.model.FixingsOverview.IdsFilter;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
27
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
28 import org.dive4elements.river.artifacts.model.FixingsOverview;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
29 import org.dive4elements.river.artifacts.model.FixingsOverviewFactory;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
30 import org.dive4elements.river.artifacts.model.Parameters;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
31
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
32 import org.dive4elements.river.utils.DoubleUtil;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5741
diff changeset
33 import org.dive4elements.river.utils.KMIndex;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 import java.util.ArrayList;
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
36 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
37 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
38 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
39 import java.util.Map;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 import org.apache.log4j.Logger;
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
5150
345f3bba6f15 Doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3970
diff changeset
43 /** 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
44 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
45 extends Calculation
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 {
2786
f9e62e76ee1f FixA: Return correct data structure from calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2783
diff changeset
47 private static Logger log = Logger.getLogger(FixCalculation.class);
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
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
49 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
50
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
51 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
52 "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
53 };
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 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
56
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 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
58 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
59 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
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 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
62 }
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
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 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
65 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
66 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
67 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
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 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
70 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
71 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
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
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
74 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
75 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
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
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 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
79 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
80 }
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
81
3729
e727e3ebdf85 Factored out a pure QW model to be more reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3604
diff changeset
82 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
83 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
84 }
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
85 } // 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
86
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
87 /** 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
88 * 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
89 */
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
90 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
91
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
92 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
93 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
94 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
95
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
96 public Column() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
97 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
98
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
99 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
100 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
101 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
102 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
103 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
104
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
105 public Date getDate() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
106 return meta.getStartTime();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
107 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
108
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
109 public String getDescription() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
110 return meta.getDescription();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
111 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
112
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
113 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
114 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
115 }
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
116
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
117 public boolean getQW(
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
118 double km,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
119 double [] qs,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
120 double [] ws,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
121 int index
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
122 ) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
123 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
124 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
125 }
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 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
128 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
129 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
130 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
131 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
132 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
133 } // class Column
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
134
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
135 /**
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
136 * 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
137 */
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
138 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
139
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
140 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
141
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
142 public ColumnCache() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
143 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
144 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
145
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
146 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
147 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
148 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
149 if (column == null) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
150 FixingsColumn data = FixingsColumnFactory
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
151 .getInstance()
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
152 .getColumnData(meta);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
153 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
154 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
155 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
156 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
157 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
158 return column;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
159 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
160 } // class ColumnCache
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
161
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
162
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 protected int qSectorEnd;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 public FixCalculation() {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 public FixCalculation(FixAccess access) {
3451
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
177 String river = access.getRiver();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
178 Double from = access.getFrom();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
179 Double to = access.getTo();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
180 Double step = access.getStep();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
181 String function = access.getFunction();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
182 int [] events = access.getEvents();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
183 Integer qSectorStart = access.getQSectorStart();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
184 Integer qSectorEnd = access.getQSectorEnd();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
185 Boolean preprocessing = access.getPreprocessing();
2729
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 (river == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 addProblem("fix.missing.river");
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 (from == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 addProblem("fix.missing.from");
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 (to == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 addProblem("fix.missing.to");
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 (step == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 addProblem("fix.missing.step");
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
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 if (function == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 addProblem("fix.missing.function");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207 if (events == null || events.length < 1) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 addProblem("fix.missing.events");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
210
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
211 if (qSectorStart == null) {
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
212 addProblem("fix.missing.qstart.sector");
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
213 }
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
214
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
215 if (qSectorEnd == null) {
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
216 addProblem("fix.missing.qend.sector");
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
217 }
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
218
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
219 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
220 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
221 }
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 this.preprocessing = preprocessing;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
234 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
236 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
237 String [] parameterNames,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
238 double [] values
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
239 ) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
240 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
241 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
242 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
243 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
244 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
245 return sb.toString();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
246 }
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
247
5733
b7d631e45ee7 FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5150
diff changeset
248
5741
6e6753b9757f FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5733
diff changeset
249 /** Create filter to accept only the chosen events.
6e6753b9757f FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5733
diff changeset
250 * This factored out out to be overwritten.
6e6753b9757f FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5733
diff changeset
251 */
6e6753b9757f FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5733
diff changeset
252 protected Filter createFilter() {
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
253 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
254 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
255
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
256 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
257 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
258 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
259 ) {
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
260 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
261
5741
6e6753b9757f FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5733
diff changeset
262 Filter filter = createFilter();
3434
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 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
265
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
266 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
267
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
268 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
269
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
270 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
271 if (data == null) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
272 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
273 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
274 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
275 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
276 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
277 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
278
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
279 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
280 }
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
5733
b7d631e45ee7 FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5150
diff changeset
282 // 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
283 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
284 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
285 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
286 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
287 ) {
2792
fe987587ebc9 Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2788
diff changeset
288 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
289
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
290 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
291
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 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
293 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
294 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
295 }
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
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 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
298 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
299 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
300
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 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
302 @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
303 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
304 // 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
305 // 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
306 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
307 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
308 && 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
309 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
310 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
311 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
312 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
313 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
314 interpolated[i],
3604
2382b26079ac FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3603
diff changeset
315 0d,
2382b26079ac FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3603
diff changeset
316 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
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 }
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 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
320 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
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 };
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 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
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 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
327
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 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
329 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
330 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
331
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 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
333
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 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
335
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 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
337 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
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
3729
e727e3ebdf85 Factored out a pure QW model to be more reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3604
diff changeset
340 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
341 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
342
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 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
344 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
345 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
346 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
347 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
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 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
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 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
352 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
353
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 // 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
355 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
356 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
357 }
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 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
360
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 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
362 ++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
363 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
364 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
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
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 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
368
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 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
370 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
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
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 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
374 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
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 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
377 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
378 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
379 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
380 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
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 (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
383 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
384 }
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 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
388 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
389 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
390 }
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
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 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
393 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
394 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
395 }
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
396
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
397 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
398 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
399
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
400 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
401 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
402 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
403 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
404 }
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
405
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
406 public CalculationResult calculate() {
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
407 FixingsOverview overview =
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
408 FixingsOverviewFactory.getOverview(river);
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 if (overview == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
411 addProblem("fix.no.overview.available");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
412 }
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 Function func = FunctionFactory.getInstance()
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
415 .getFunction(function);
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
416
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
417 if (func == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
418 addProblem("fix.invalid.function.name");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
419 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
420
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
421 if (hasProblems()) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
422 return new CalculationResult(this);
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
423 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
424
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
425 return innerCalculate(overview, func);
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
426 }
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
427
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
428 protected abstract CalculationResult innerCalculate(
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
429 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
430 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
431 );
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
432 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
433 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org