Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java @ 9363:0274c7444b2d
Fixed: missing commit
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
Removed old outliers theme.
Also consider showpoints property.
Also consider pointsize property.
author | gernotbelger |
---|---|
date | Thu, 02 Aug 2018 09:59:48 +0200 |
parents | 202fd59b4f21 |
children | 9744ce3c3853 |
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 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.ArrayList; |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
12 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
|
13 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
|
14 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
|
15 import java.util.Map; |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import org.apache.log4j.Logger; |
9099 | 18 import org.dive4elements.artifacts.common.utils.StringUtils; |
19 import org.dive4elements.river.artifacts.access.FixAccess; | |
20 import org.dive4elements.river.artifacts.math.fitting.Function; | |
21 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory; | |
22 import org.dive4elements.river.artifacts.model.Calculation; | |
23 import org.dive4elements.river.artifacts.model.CalculationResult; | |
24 import org.dive4elements.river.artifacts.model.FixingsColumn; | |
25 import org.dive4elements.river.artifacts.model.FixingsColumnFactory; | |
26 import org.dive4elements.river.artifacts.model.FixingsOverview; | |
27 import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing; | |
28 import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing.Filter; | |
29 import org.dive4elements.river.artifacts.model.FixingsOverview.IdsFilter; | |
30 import org.dive4elements.river.artifacts.model.FixingsOverviewFactory; | |
31 import org.dive4elements.river.artifacts.model.Parameters; | |
32 import org.dive4elements.river.utils.DoubleUtil; | |
33 import org.dive4elements.river.utils.KMIndex; | |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
5150
345f3bba6f15
Doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3970
diff
changeset
|
35 /** Calculation base class for fix. */ |
9099 | 36 public abstract class FixCalculation extends Calculation { |
2786
f9e62e76ee1f
FixA: Return correct data structure from calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
37 private static Logger log = Logger.getLogger(FixCalculation.class); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
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
|
39 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
|
40 |
9099 | 41 public static final String[] STANDARD_COLUMNS = { "km", "chi_sqr", "max_q", "std-dev" }; |
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
|
42 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
43 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
|
44 |
9363 | 45 private final Parameters parameters; |
46 private final KMIndex<QWD[]> fixings; | |
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
|
47 |
9363 | 48 public FitResult(final Parameters parameters, final KMIndex<QWD[]> fixings) { |
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 this.parameters = parameters; |
9363 | 50 this.fixings = fixings; |
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
|
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 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
53 public Parameters getParameters() { |
9099 | 54 return this.parameters; |
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
|
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 |
9363 | 57 public KMIndex<QWD[]> getFixings() { |
58 return this.fixings; | |
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
|
59 } |
9363 | 60 } |
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 |
9099 | 62 /** |
63 * Helper class to bundle the meta information of a column | |
64 * and the real data. | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
65 */ |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
66 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
|
67 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
68 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
|
69 protected FixingsColumn data; |
9099 | 70 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
|
71 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
72 public Column() { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
73 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
74 |
9099 | 75 public Column(final Fixing.Column meta, final FixingsColumn data, final int index) { |
76 this.meta = meta; | |
77 this.data = 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
|
78 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
|
79 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
80 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
81 public Date getDate() { |
9099 | 82 return this.meta.getStartTime(); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
83 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
84 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
85 public String getDescription() { |
9099 | 86 return this.meta.getDescription(); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
87 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
88 |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
89 public int getIndex() { |
9099 | 90 return this.index; |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
91 } |
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
92 |
6875
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
93 public int getId() { |
9099 | 94 return this.meta.getId(); |
6875
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
95 } |
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
96 |
9099 | 97 public boolean getQW(final double km, final double[] qs, final double[] ws, final int index) { |
98 qs[index] = this.data.getQ(km); | |
99 return this.data.getW(km, ws, index); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
100 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
101 |
9099 | 102 public boolean getQW(final double km, final double[] wq) { |
103 this.data.getW(km, wq, 0); | |
104 if (Double.isNaN(wq[0])) | |
105 return false; | |
106 wq[1] = this.data.getQ(km); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
107 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
|
108 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
109 } // class Column |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
110 |
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 * 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
|
113 */ |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
114 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
|
115 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
116 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
|
117 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
118 public ColumnCache() { |
9099 | 119 this.columns = new HashMap<>(); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
120 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
121 |
9099 | 122 public Column getColumn(final Fixing.Column meta) { |
123 final Integer key = meta.getId(); | |
124 Column column = this.columns.get(key); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
125 if (column == null) { |
9099 | 126 final FixingsColumn data = FixingsColumnFactory.getInstance().getColumnData(meta); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
127 if (data != null) { |
9099 | 128 column = new Column(meta, data, this.columns.size()); |
129 this.columns.put(key, column); | |
3434
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 return column; |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
133 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
134 } // class ColumnCache |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
135 |
9099 | 136 protected String river; |
137 protected double from; | |
138 protected double to; | |
139 protected double step; | |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 protected boolean preprocessing; |
9099 | 141 protected String function; |
142 protected int[] events; | |
143 protected int qSectorStart; | |
144 protected int qSectorEnd; | |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 public FixCalculation() { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 |
9099 | 149 public FixCalculation(final FixAccess access) { |
150 final String river = access.getRiverName(); | |
151 final Double from = access.getLowerKm(); | |
152 final Double to = access.getUpperKm(); | |
153 final Double step = access.getStep(); | |
154 final String function = access.getFunction(); | |
155 final int[] events = access.getEvents(); | |
156 final Integer qSectorStart = access.getQSectorStart(); | |
157 final Integer qSectorEnd = access.getQSectorEnd(); | |
158 final Boolean preprocessing = access.getPreprocessing(); | |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 if (river == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 addProblem("fix.missing.river"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 if (from == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 addProblem("fix.missing.from"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 if (to == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 addProblem("fix.missing.to"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 if (step == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 addProblem("fix.missing.step"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 if (function == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 addProblem("fix.missing.function"); |
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 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 if (events == null || events.length < 1) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 addProblem("fix.missing.events"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
184 if (qSectorStart == null) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
185 addProblem("fix.missing.qstart.sector"); |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
186 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
187 |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
188 if (qSectorEnd == null) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
189 addProblem("fix.missing.qend.sector"); |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
190 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
191 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 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
|
193 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
|
194 } |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 if (!hasProblems()) { |
9099 | 197 this.river = river; |
198 this.from = from; | |
199 this.to = to; | |
200 this.step = step; | |
201 this.function = function; | |
202 this.events = events; | |
203 this.qSectorStart = qSectorStart; | |
204 this.qSectorEnd = qSectorEnd; | |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 this.preprocessing = preprocessing; |
2729
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 |
9099 | 209 protected static String toString(final String[] parameterNames, final double[] values) { |
210 final StringBuilder sb = new StringBuilder(); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
211 for (int i = 0; i < parameterNames.length; ++i) { |
9099 | 212 if (i > 0) |
213 sb.append(", "); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
214 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
|
215 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
216 return sb.toString(); |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
217 } |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 |
9099 | 219 /** |
220 * Create filter to accept only the chosen events. | |
221 * This factored out out to be overwritten. | |
5741
6e6753b9757f
FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5733
diff
changeset
|
222 */ |
6e6753b9757f
FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5733
diff
changeset
|
223 protected Filter createFilter() { |
9099 | 224 return new IdsFilter(this.events); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
225 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
226 |
9099 | 227 protected List<Column> getEventColumns(final FixingsOverview overview, final ColumnCache cc) { |
228 final 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
|
229 |
9099 | 230 final List<Fixing.Column> metas = overview.filter(null, filter); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
231 |
9099 | 232 final List<Column> columns = new ArrayList<>(metas.size()); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
233 |
9099 | 234 for (final Fixing.Column meta : metas) { |
235 | |
236 final 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
|
237 if (data == null) { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
238 addProblem("fix.cannot.load.data"); |
9099 | 239 } 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
|
240 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
|
241 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
242 } |
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 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
|
245 } |
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
|
246 |
5733
b7d631e45ee7
FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5150
diff
changeset
|
247 // Fit a function to the given points from fixation. |
9099 | 248 protected FitResult doFitting(final FixingsOverview overview, final ColumnCache cc, final Function func) { |
249 final boolean debug = log.isDebugEnabled(); | |
2792
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2788
diff
changeset
|
250 |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
251 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
|
252 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
253 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
|
254 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
|
255 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
|
256 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
257 |
9099 | 258 final double[] qs = new double[eventColumns.size()]; |
259 final double[] ws = new double[qs.length]; | |
260 final boolean[] interpolated = new boolean[ws.length]; | |
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
|
261 |
9099 | 262 final Fitting.QWDFactory qwdFactory = new Fitting.QWDFactory() { |
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
|
263 @Override |
9363 | 264 public QWD create(final double q, final double w, double deltaW, boolean isOutlier) { |
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
|
265 // 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
|
266 // 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
|
267 for (int i = 0; i < qs.length; ++i) { |
9099 | 268 if (Math.abs(qs[i] - q) < EPSILON && Math.abs(ws[i] - w) < EPSILON) { |
269 final Column column = eventColumns.get(i); | |
9363 | 270 return new QWD(qs[i], ws[i], column.getDescription(), column.getDate(), interpolated[i], deltaW, column.getId(), isOutlier); // 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
|
271 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
272 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
273 log.warn("cannot find column for (" + q + ", " + w + ")"); |
9356 | 274 return new QWD(q, w, isOutlier); |
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
|
275 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
276 }; |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
277 |
9099 | 278 final String[] parameterNames = func.getParameterNames(); |
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
|
279 |
9099 | 280 final Parameters results = new Parameters(StringUtils.join(STANDARD_COLUMNS, parameterNames)); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
281 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
282 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
|
283 |
9099 | 284 final double[] kms = DoubleUtil.explode(this.from, this.to, this.step / 1000.0); |
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 |
262e7d7e58fe
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 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
|
287 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
|
288 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
289 |
9363 | 290 final KMIndex<QWD[]> fixings = new KMIndex<>(); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
291 |
9099 | 292 final int kmIndex = results.columnIndex("km"); |
293 final int chiSqrIndex = results.columnIndex("chi_sqr"); | |
294 final int maxQIndex = results.columnIndex("max_q"); | |
295 final int stdDevIndex = results.columnIndex("std-dev"); | |
296 final int[] parameterIndices = results.columnIndices(parameterNames); | |
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
|
297 |
262e7d7e58fe
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 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
|
299 |
9363 | 300 for (final double km : kms) { |
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
|
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 // Fill Qs and Ws from event columns. |
9363 | 303 for (int j = 0; j < ws.length; ++j) |
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
|
304 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
|
305 |
9363 | 306 final Fitting fitting = Fitting.fit(func, qwdFactory, this.preprocessing, qs, ws); |
307 if (fitting == null) { | |
7300
83bb52fa0c32
(issue1529) Be more tolerant in the fitting.
Andre Heinecke <aheinecke@intevation.de>
parents:
7261
diff
changeset
|
308 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
|
309 ++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
|
310 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
|
311 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
|
312 } |
9363 | 313 |
314 final QWD[] fixingsArray = fitting.getFixingsArray(); | |
315 fixings.add(km, fixingsArray); | |
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
|
316 |
9099 | 317 final int row = results.newRow(); |
318 final double[] values = fitting.getParameters(); | |
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
|
319 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
320 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
|
321 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
|
322 results.set(row, stdDevIndex, fitting.getStandardDeviation()); |
9099 | 323 results.set(row, maxQIndex, fitting.getMaxQ()); |
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
|
324 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
|
325 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
326 if (debug) { |
9099 | 327 log.debug("km: " + km + " " + toString(parameterNames, values)); |
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
|
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 } |
262e7d7e58fe
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 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
|
332 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
|
333 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
|
334 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
335 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
336 if (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
|
337 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
|
338 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
|
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 |
9363 | 341 fixings.sort(); |
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
|
342 |
9363 | 343 return new FitResult(results, fixings); |
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
|
344 } |
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
|
345 |
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
|
346 public CalculationResult calculate() { |
9099 | 347 final FixingsOverview overview = FixingsOverviewFactory.getOverview(this.river); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
348 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
349 if (overview == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
350 addProblem("fix.no.overview.available"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
351 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
352 |
9099 | 353 final Function func = FunctionFactory.getInstance().getFunction(this.function); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
354 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
355 if (func == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
356 addProblem("fix.invalid.function.name"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
357 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
358 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
359 if (hasProblems()) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
360 return new CalculationResult(this); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
361 } |
9099 | 362 final CalculationResult result = innerCalculate(overview, func); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
363 |
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
|
364 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
|
365 // Workaraound to deal with same dates in data set |
9099 | 366 final Object o = result.getData(); |
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
|
367 if (o instanceof FixResult) { |
9099 | 368 final FixResult fr = (FixResult) o; |
9363 | 369 fr.makeEventsDatesUnique(); |
370 fr.remapEventIndicesToRank(); | |
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
|
371 } |
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
|
372 } |
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
|
373 |
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
|
374 return result; |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
375 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
376 |
9099 | 377 protected abstract CalculationResult innerCalculate(FixingsOverview overview, Function function); |
9363 | 378 } |