annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java @ 9726:0a5239a1e46e 3.2.x

Upgrade to Log4j 2
author Tom Gottfried <tom@intevation.de>
date Wed, 02 Mar 2022 10:26:50 +0100
parents 6650485c2c9b
children
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 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
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
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
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
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 7525
diff changeset
41 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 7525
diff changeset
42 import org.apache.logging.log4j.LogManager;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
5150
345f3bba6f15 Doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3970
diff changeset
44 /** 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
45 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
46 extends Calculation
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 {
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 7525
diff changeset
48 private static Logger log = LogManager.getLogger(FixCalculation.class);
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
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
50 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
51
262e7d7e58fe 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 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
53 "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
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 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
57
262e7d7e58fe 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 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
59 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
60 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
61
262e7d7e58fe 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 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
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
262e7d7e58fe 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 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
66 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
67 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
68 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
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 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
71 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
72 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
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
262e7d7e58fe 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 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
76 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
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
262e7d7e58fe 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 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
80 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
81 }
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
82
3729
e727e3ebdf85 Factored out a pure QW model to be more reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3604
diff changeset
83 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
84 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
85 }
262e7d7e58fe 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 } // 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
87
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
88 /** 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
89 * 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
90 */
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
91 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
92
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
93 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
94 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
95 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
96
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
97 public Column() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
98 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
99
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
100 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
101 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
102 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
103 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
104 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
105
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
106 public Date getDate() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
107 return meta.getStartTime();
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
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
110 public String getDescription() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
111 return meta.getDescription();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
112 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
113
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
114 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
115 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
116 }
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
117
6875
437856cec419 FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
118 public int getId() {
437856cec419 FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
119 return meta.getId();
437856cec419 FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
120 }
437856cec419 FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
121
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
122 public boolean getQW(
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
123 double km,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
124 double [] qs,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
125 double [] ws,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
126 int index
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 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
129 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
130 }
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 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
133 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
134 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
135 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
136 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
137 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
138 } // class Column
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 /**
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
141 * 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
142 */
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
143 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
144
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
145 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
146
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
147 public ColumnCache() {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
148 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
149 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
150
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
151 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
152 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
153 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
154 if (column == null) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
155 FixingsColumn data = FixingsColumnFactory
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
156 .getInstance()
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
157 .getColumnData(meta);
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
158 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
159 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
160 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
161 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
162 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
163 return column;
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
164 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
165 } // class ColumnCache
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
166
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
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 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 protected int qSectorEnd;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 public FixCalculation() {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 public FixCalculation(FixAccess access) {
7261
a56fe3bc6700 Refactoring: Let RiverAccess.getRiver return an River.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6875
diff changeset
182 String river = access.getRiverName();
3451
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
183 Double from = access.getFrom();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
184 Double to = access.getTo();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
185 Double step = access.getStep();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
186 String function = access.getFunction();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
187 int [] events = access.getEvents();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
188 Integer qSectorStart = access.getQSectorStart();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
189 Integer qSectorEnd = access.getQSectorEnd();
b5eec54bd4a2 FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3437
diff changeset
190 Boolean preprocessing = access.getPreprocessing();
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 if (river == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 addProblem("fix.missing.river");
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
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 if (from == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 addProblem("fix.missing.from");
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
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 if (to == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 addProblem("fix.missing.to");
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
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 if (step == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205 addProblem("fix.missing.step");
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
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 if (function == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 addProblem("fix.missing.function");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
210 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
211
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212 if (events == null || events.length < 1) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 addProblem("fix.missing.events");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
216 if (qSectorStart == null) {
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
217 addProblem("fix.missing.qstart.sector");
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
218 }
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
219
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
220 if (qSectorEnd == null) {
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
221 addProblem("fix.missing.qend.sector");
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
222 }
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
223
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 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
225 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
226 }
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
227
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228 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
229 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
230 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
231 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
232 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
233 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
234 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
235 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
236 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
237 this.preprocessing = preprocessing;
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
240
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
241 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
242 String [] parameterNames,
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
243 double [] values
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 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
246 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
247 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
248 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
249 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
250 return sb.toString();
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
251 }
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
252
5733
b7d631e45ee7 FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5150
diff changeset
253
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
254 /** Create filter to accept only the chosen events.
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
255 * This factored out out to be overwritten.
5741
6e6753b9757f FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5733
diff changeset
256 */
6e6753b9757f FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5733
diff changeset
257 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
258 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
259 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
260
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
261 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
262 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
263 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
264 ) {
3434
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
265 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
266
5741
6e6753b9757f FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5733
diff changeset
267 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
268
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
269 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
270
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
271 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
272
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
273 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
274
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 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
276 if (data == null) {
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
277 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
278 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
279 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
280 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
281 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
282 }
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
283
1a636be7612b FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
284 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
285 }
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
286
5733
b7d631e45ee7 FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5150
diff changeset
287 // 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
288 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
289 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
290 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
291 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
292 ) {
2792
fe987587ebc9 Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2788
diff changeset
293 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
294
3603
d2ae58f6730d FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3451
diff changeset
295 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
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 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
298 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
299 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
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
262e7d7e58fe 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 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
303 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
304 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
305
262e7d7e58fe 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 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
307 @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
308 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
309 // 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
310 // 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
311 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
312 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
313 && 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
314 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
315 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
316 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
317 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
318 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
319 interpolated[i],
3604
2382b26079ac FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3603
diff changeset
320 0d,
6875
437856cec419 FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
321 column.getId()); // Use database id here
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
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 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
325 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
326 }
262e7d7e58fe 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
262e7d7e58fe 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 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
330
262e7d7e58fe 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 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
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 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
334 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
335 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
336
262e7d7e58fe 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 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
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 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
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 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
342 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
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
3729
e727e3ebdf85 Factored out a pure QW model to be more reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3604
diff changeset
345 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
346 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
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 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
349 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
350 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
351 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
352 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
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 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
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 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
357 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
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 // 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
360 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
361 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
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
262e7d7e58fe 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 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
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 if (!fitting.fit(qs, ws)) {
7300
83bb52fa0c32 (issue1529) Be more tolerant in the fitting.
Andre Heinecke <aheinecke@intevation.de>
parents: 7261
diff changeset
367 log.debug("Fitting for km: " + km + " failed");
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
368 ++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
369 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
370 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
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
6875
437856cec419 FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
373 QWD [] refs = fitting.referencedToArray();
437856cec419 FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
374
437856cec419 FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
375 referenced.add(km, refs);
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
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 (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
378 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
379 }
262e7d7e58fe 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 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
382 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
383
262e7d7e58fe 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.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
385 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
386 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
387 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
388 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
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 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
391 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
392 }
262e7d7e58fe 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 }
262e7d7e58fe 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
262e7d7e58fe 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 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
396 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
397 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
398 }
262e7d7e58fe 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 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
401 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
402 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
403 }
262e7d7e58fe 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
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
405 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
406 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
407
262e7d7e58fe FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3434
diff changeset
408 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
409 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
410 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
411 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
412 }
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
413
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
414 public CalculationResult calculate() {
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
415 FixingsOverview overview =
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
416 FixingsOverviewFactory.getOverview(river);
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
417
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
418 if (overview == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
419 addProblem("fix.no.overview.available");
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
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
422 Function func = FunctionFactory.getInstance()
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
423 .getFunction(function);
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
424
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
425 if (func == null) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
426 addProblem("fix.invalid.function.name");
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
427 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
428
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
429 if (hasProblems()) {
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
430 return new CalculationResult(this);
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
431 }
7525
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
432 CalculationResult result = innerCalculate(overview, func);
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
433
7525
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
434 if (result != null) {
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
435 // Workaraound to deal with same dates in data set
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
436 Object o = result.getData();
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
437 if (o instanceof FixResult) {
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
438 FixResult fr = (FixResult)o;
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
439 fr.makeReferenceEventsDatesUnique();
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
440 fr.remapReferenceIndicesToRank();
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
441 }
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
442 }
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
443
6650485c2c9b Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7300
diff changeset
444 return result;
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
445 }
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
446
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
447 protected abstract CalculationResult innerCalculate(
2744
c1f2e792704a FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2729
diff changeset
448 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
449 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
450 );
2729
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
451 }
a441be7f1589 Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
452 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org