Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffCalculation.java @ 7013:998a9710007e
issue1465: Do not allow null ranges for fraction values, logger.error instead.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 13 Sep 2013 16:07:46 +0200 |
parents | d4108d6c4000 |
children | a56fe3bc6700 |
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:
5867
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:
5867
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 */ |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3898
diff
changeset
|
8 package org.dive4elements.river.artifacts.model.minfo; |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 import gnu.trove.TDoubleArrayList; |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 |
3898
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
12 import java.util.Date; |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 import org.apache.log4j.Logger; |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
16 import org.dive4elements.artifacts.CallContext; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3898
diff
changeset
|
17 import org.dive4elements.river.artifacts.access.BedDifferencesAccess; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3898
diff
changeset
|
18 import org.dive4elements.river.artifacts.model.Calculation; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3898
diff
changeset
|
19 import org.dive4elements.river.artifacts.model.CalculationResult; |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 |
6573
7d86ed4537d9
Cosmetics, doc, obsolete import removal.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6215
diff
changeset
|
21 /** |
7d86ed4537d9
Cosmetics, doc, obsolete import removal.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6215
diff
changeset
|
22 * Perform calculation of differences of bed height (german Sohlhoehe). |
7d86ed4537d9
Cosmetics, doc, obsolete import removal.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6215
diff
changeset
|
23 * The input are either single year data or epochs. |
7d86ed4537d9
Cosmetics, doc, obsolete import removal.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6215
diff
changeset
|
24 */ |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 public class BedDiffCalculation |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 extends Calculation |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 { |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
28 private static final Logger logger = |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
29 Logger.getLogger(BedDiffCalculation.class); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
31 protected String river; |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
32 protected String yearEpoch; |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
33 protected int [][] heightIds; |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 public BedDiffCalculation() { |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
38 public CalculationResult calculate(BedDifferencesAccess access, CallContext context) { |
3898
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
39 logger.info("BedDiffCalculation.calculate"); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
41 String river = access.getRiver(); |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
42 String yearEpoch = access.getYearEpoch(); |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
43 int [][] heightIds = access.extractHeightIds(context); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 if (river == null) { |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 // TODO: i18n |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 addProblem("minfo.missing.river"); |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 if (yearEpoch == null) { |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 addProblem("minfo.missing.year_epoch"); |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 if (!hasProblems()) { |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
55 this.river = river; |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 this.yearEpoch = yearEpoch; |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
57 this.heightIds = heightIds; |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 return internalCalculate(); |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 return new CalculationResult(); |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 private CalculationResult internalCalculate() { |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 |
6215
0f5cacdd60a9
I999: Epochs and single years are handled in the same way in difference calc.
Raimund Renkert <rrenkert@intevation.de>
parents:
6148
diff
changeset
|
66 BedDiffYearResult [] results = new BedDiffYearResult[heightIds.length]; |
3898
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
67 |
6215
0f5cacdd60a9
I999: Epochs and single years are handled in the same way in difference calc.
Raimund Renkert <rrenkert@intevation.de>
parents:
6148
diff
changeset
|
68 for (int i = 0; i < heightIds.length; i++) { |
0f5cacdd60a9
I999: Epochs and single years are handled in the same way in difference calc.
Raimund Renkert <rrenkert@intevation.de>
parents:
6148
diff
changeset
|
69 BedHeight [] pair = getHeightPair(heightIds[i], "single"); |
0f5cacdd60a9
I999: Epochs and single years are handled in the same way in difference calc.
Raimund Renkert <rrenkert@intevation.de>
parents:
6148
diff
changeset
|
70 results[i] = calculateYearDifference(pair); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 } |
6215
0f5cacdd60a9
I999: Epochs and single years are handled in the same way in difference calc.
Raimund Renkert <rrenkert@intevation.de>
parents:
6148
diff
changeset
|
72 return new CalculationResult(results, this); |
0f5cacdd60a9
I999: Epochs and single years are handled in the same way in difference calc.
Raimund Renkert <rrenkert@intevation.de>
parents:
6148
diff
changeset
|
73 // Currently epochs are handled like single years. To handle epochs |
0f5cacdd60a9
I999: Epochs and single years are handled in the same way in difference calc.
Raimund Renkert <rrenkert@intevation.de>
parents:
6148
diff
changeset
|
74 // uncomment the follwing code and use an if-clause in the code above. |
0f5cacdd60a9
I999: Epochs and single years are handled in the same way in difference calc.
Raimund Renkert <rrenkert@intevation.de>
parents:
6148
diff
changeset
|
75 /* |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 if (yearEpoch.equals("epoch")) { |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
77 BedDiffEpochResult [] results = new BedDiffEpochResult[heightIds.length]; |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
78 |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
79 for (int i = 0; i < heightIds.length; i++) { |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
80 BedHeight[] pair = getHeightPair(heightIds[i], "epoch"); |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
81 results[i] = calculateEpochDifference(pair); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 } |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
83 return new CalculationResult(results, this); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 |
3898
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
86 return new CalculationResult(); |
6215
0f5cacdd60a9
I999: Epochs and single years are handled in the same way in difference calc.
Raimund Renkert <rrenkert@intevation.de>
parents:
6148
diff
changeset
|
87 */ |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
88 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
89 |
6573
7d86ed4537d9
Cosmetics, doc, obsolete import removal.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6215
diff
changeset
|
90 /** Get two BedHeights from factory. */ |
6148
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
91 private static BedHeight [] getHeightPair(int [] ids, String type) { |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
92 return new BedHeight [] { |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
93 BedHeightFactory.getHeight(type, ids[0], 0), |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
94 BedHeightFactory.getHeight(type, ids[1], 0) |
b12ec9f240bc
Bed height differences: DO NOT STORE ARTIFACTS IN CALCULATION RESULTS!!! This would lead to caching them which is _really_ wrong.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6147
diff
changeset
|
95 }; |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 private BedDiffEpochResult calculateEpochDifference(BedHeight[] pair) { |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
99 |
6147
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
100 BedHeight bh1 = pair[0]; |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
101 BedHeight bh2 = pair[1]; |
3898
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
102 |
6147
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
103 TDoubleArrayList stations = bh1.getStations(); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
104 int size = stations.size(); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
105 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
106 TDoubleArrayList diffRes = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
107 TDoubleArrayList kms = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
108 TDoubleArrayList heights1 = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
109 TDoubleArrayList heights2 = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
110 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
111 for (int i = 0; i < size; i++) { |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
112 double station = stations.getQuick(i); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
113 double h1 = bh1.getHeight(station); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
114 double h2 = bh2.getHeight(station); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
115 double hDiff = h1 - h2; |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
116 if (!Double.isNaN(hDiff)) { |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
117 diffRes.add(hDiff); |
6147
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
118 kms.add(station); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
119 heights1.add(h1); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
120 heights2.add(h2); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
121 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
122 } |
6147
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
123 Date start = ((BedHeightEpoch)bh1).getStart(); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
124 Date end = ((BedHeightEpoch)bh2).getEnd(); |
3898
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
125 return new BedDiffEpochResult(kms, diffRes, heights1, heights2, start, end); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
126 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
127 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
128 private BedDiffYearResult calculateYearDifference(BedHeight[] pair) { |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
129 |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
130 BedHeightSingle s1 = (BedHeightSingle)pair[0]; |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
131 BedHeightSingle s2 = (BedHeightSingle)pair[1]; |
6147
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
132 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
133 TDoubleArrayList stations = s1.getStations(); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
134 int size = stations.size(); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
135 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
136 TDoubleArrayList diffRes = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
137 TDoubleArrayList kms = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
138 TDoubleArrayList morphs = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
139 TDoubleArrayList absolute = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
140 TDoubleArrayList gap = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
141 TDoubleArrayList heights1 = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
142 TDoubleArrayList heights2 = new TDoubleArrayList(size); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
143 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
144 int range = Math.abs(s1.getYear() - s2.getYear()); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
145 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
146 for (int i = 0; i < size; i++) { |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
147 double station = stations.getQuick(i); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
148 double h1 = s1.getHeight(station); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
149 double h2 = s2.getHeight(station); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
150 double hDiff = h1 - h2; |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
151 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
152 if (!Double.isNaN(hDiff)) { |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
153 diffRes.add(hDiff); |
6147
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
154 kms.add(station); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
155 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
156 morphs.add(Math.max( |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
157 s1.getMorphWidth(station), |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
158 s2.getMorphWidth(station))); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
159 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
160 gap.add(Math.max( |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
161 s1.getDataGap(station), |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
162 s2.getDataGap(station))); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
163 |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
164 absolute.add((hDiff / range) * 100d); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
165 heights1.add(h1); |
073268a137d5
Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6089
diff
changeset
|
166 heights2.add(h2); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
167 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
168 } |
3898
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
169 return new BedDiffYearResult( |
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
170 kms, |
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
171 diffRes, |
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
172 heights1, |
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
173 heights2, |
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
174 morphs, |
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
175 absolute, |
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
176 gap, |
95d699c769fb
Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3887
diff
changeset
|
177 s1.getYear(), |
6089
0c3301fe23bd
towards issue1061: Store names of original BedHeights in the BedDiffYearResult.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
178 s2.getYear(), |
0c3301fe23bd
towards issue1061: Store names of original BedHeights in the BedDiffYearResult.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
179 s1.getName(), |
0c3301fe23bd
towards issue1061: Store names of original BedHeights in the BedDiffYearResult.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
180 s2.getName()); |
3887
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
181 } |
a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
182 } |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6573
diff
changeset
|
183 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |