Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java @ 7261:a56fe3bc6700
Refactoring: Let RiverAccess.getRiver return an River.
Renamed getRiver in getRiverName. Update Callers.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 08 Oct 2013 14:50:58 +0200 |
parents | 437856cec419 |
children | 83bb52fa0c32 |
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 |
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 |
6875
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
117 public int getId() { |
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
118 return meta.getId(); |
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
119 } |
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
120 |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
121 public boolean getQW( |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
122 double km, |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
123 double [] qs, |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
124 double [] ws, |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
125 int index |
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 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
|
128 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
|
129 } |
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 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
137 } // class Column |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
138 |
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 * 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
|
141 */ |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
142 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
|
143 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
144 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
|
145 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
146 public ColumnCache() { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
147 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
|
148 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
149 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 if (column == null) { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
154 FixingsColumn data = FixingsColumnFactory |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
155 .getInstance() |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
156 .getColumnData(meta); |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
157 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
|
158 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
|
159 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
|
160 } |
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 return column; |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
163 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
164 } // class ColumnCache |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
165 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
166 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 protected int qSectorEnd; |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 public FixCalculation() { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 public FixCalculation(FixAccess access) { |
7261
a56fe3bc6700
Refactoring: Let RiverAccess.getRiver return an River.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6875
diff
changeset
|
181 String river = access.getRiverName(); |
3451
b5eec54bd4a2
FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
182 Double from = access.getFrom(); |
b5eec54bd4a2
FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
183 Double to = access.getTo(); |
b5eec54bd4a2
FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
184 Double step = access.getStep(); |
b5eec54bd4a2
FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
185 String function = access.getFunction(); |
b5eec54bd4a2
FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
186 int [] events = access.getEvents(); |
b5eec54bd4a2
FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
187 Integer qSectorStart = access.getQSectorStart(); |
b5eec54bd4a2
FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
188 Integer qSectorEnd = access.getQSectorEnd(); |
b5eec54bd4a2
FixA: Removed some inner whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
189 Boolean preprocessing = access.getPreprocessing(); |
2729
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 (river == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 addProblem("fix.missing.river"); |
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 (from == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 addProblem("fix.missing.from"); |
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 (to == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 addProblem("fix.missing.to"); |
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 (step == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 addProblem("fix.missing.step"); |
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 (function == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 addProblem("fix.missing.function"); |
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 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 if (events == null || events.length < 1) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 addProblem("fix.missing.events"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
215 if (qSectorStart == null) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
216 addProblem("fix.missing.qstart.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 |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
219 if (qSectorEnd == null) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
220 addProblem("fix.missing.qend.sector"); |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
221 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
222 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 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
|
224 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
|
225 } |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 this.preprocessing = preprocessing; |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 } |
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 |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
240 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
|
241 String [] parameterNames, |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
242 double [] values |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
243 ) { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 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
|
248 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
249 return sb.toString(); |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
250 } |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 |
5733
b7d631e45ee7
FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5150
diff
changeset
|
252 |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
253 /** Create filter to accept only the chosen events. |
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
254 * This factored out out to be overwritten. |
5741
6e6753b9757f
FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5733
diff
changeset
|
255 */ |
6e6753b9757f
FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5733
diff
changeset
|
256 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
|
257 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
|
258 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
259 |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
260 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
|
261 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
|
262 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
|
263 ) { |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
264 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
|
265 |
5741
6e6753b9757f
FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5733
diff
changeset
|
266 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
|
267 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
268 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
|
269 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
270 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
|
271 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
272 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
|
273 |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
274 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
|
275 if (data == null) { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
276 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
|
277 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
278 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
|
279 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
|
280 } |
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 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
|
284 } |
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
|
285 |
5733
b7d631e45ee7
FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5150
diff
changeset
|
286 // 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 ) { |
2792
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2788
diff
changeset
|
292 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
|
293 |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
294 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
|
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 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
|
297 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
|
298 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
|
299 } |
262e7d7e58fe
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 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
|
302 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
|
303 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
|
304 |
262e7d7e58fe
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 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
|
306 @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
|
307 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
|
308 // 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
|
309 // 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
|
310 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
|
311 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
|
312 && 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 interpolated[i], |
3604
2382b26079ac
FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3603
diff
changeset
|
319 0d, |
6875
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
320 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
|
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 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
|
324 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
|
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 }; |
262e7d7e58fe
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 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
|
329 |
262e7d7e58fe
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 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
|
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 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
|
333 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
|
334 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
|
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 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
|
337 |
262e7d7e58fe
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 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
|
339 |
262e7d7e58fe
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 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
|
341 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
|
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 |
3729
e727e3ebdf85
Factored out a pure QW model to be more reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3604
diff
changeset
|
344 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
|
345 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
|
346 |
262e7d7e58fe
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 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 |
262e7d7e58fe
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 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
|
354 |
262e7d7e58fe
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 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
|
356 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
|
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 // 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
|
359 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
|
360 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
|
361 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
362 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
363 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
|
364 |
262e7d7e58fe
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 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
|
366 ++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
|
367 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
|
368 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
|
369 } |
262e7d7e58fe
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 |
6875
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
371 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
|
372 |
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
373 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
|
374 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
375 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
|
376 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
|
377 } |
262e7d7e58fe
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 |
262e7d7e58fe
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 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
|
380 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
|
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 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 |
262e7d7e58fe
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 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
|
389 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
|
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 |
262e7d7e58fe
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 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
|
394 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
|
395 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
|
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 |
262e7d7e58fe
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 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
|
399 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
|
400 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
|
401 } |
262e7d7e58fe
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 |
262e7d7e58fe
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.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
|
404 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
|
405 |
262e7d7e58fe
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 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
|
407 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
|
408 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
|
409 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
|
410 } |
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
|
411 |
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
|
412 public CalculationResult calculate() { |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
413 FixingsOverview overview = |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
414 FixingsOverviewFactory.getOverview(river); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
415 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
416 if (overview == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
417 addProblem("fix.no.overview.available"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
418 } |
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 Function func = FunctionFactory.getInstance() |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
421 .getFunction(function); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
422 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
423 if (func == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
424 addProblem("fix.invalid.function.name"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
425 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
426 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
427 if (hasProblems()) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
428 return new CalculationResult(this); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
429 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
430 |
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
|
431 return innerCalculate(overview, func); |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
432 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
433 |
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
|
434 protected abstract CalculationResult innerCalculate( |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
435 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
|
436 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
|
437 ); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
438 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
439 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |