annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffCalculation.java @ 6215:0f5cacdd60a9

I999: Epochs and single years are handled in the same way in difference calc.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 06 Jun 2013 13:28:05 +0200
parents b12ec9f240bc
children 7d86ed4537d9
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
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 public class BedDiffCalculation
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 extends Calculation
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 {
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
25 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
26 Logger.getLogger(BedDiffCalculation.class);
3887
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 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
29 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
30 protected int [][] heightIds;
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 public BedDiffCalculation() {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34
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
35 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
36 logger.info("BedDiffCalculation.calculate");
3887
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 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
39 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
40 int [][] heightIds = access.extractHeightIds(context);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 if (river == null) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 // TODO: i18n
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 addProblem("minfo.missing.river");
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 if (yearEpoch == null) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 addProblem("minfo.missing.year_epoch");
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
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 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
52 this.river = river;
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 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
54 this.heightIds = heightIds;
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 return internalCalculate();
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 return new CalculationResult();
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 private CalculationResult internalCalculate() {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62
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
63 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
64
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
65 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
66 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
67 results[i] = calculateYearDifference(pair);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 }
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
69 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
70 // 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
71 // 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
72 /*
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 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
74 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
75
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
76 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
77 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
78 results[i] = calculateEpochDifference(pair);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 }
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
80 return new CalculationResult(results, this);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
83 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
84 */
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86
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
87 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
88 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
89 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
90 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
91 };
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 private BedDiffEpochResult calculateEpochDifference(BedHeight[] pair) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95
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
96 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
97 BedHeight bh2 = pair[1];
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
98
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
99 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
100 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
101
073268a137d5 Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6089
diff changeset
102 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
103 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
104 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
105 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
106
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 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
108 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
109 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
110 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
111 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
112 if (!Double.isNaN(hDiff)) {
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 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
114 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
115 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
116 heights2.add(h2);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
117 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
118 }
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
119 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
120 Date end = ((BedHeightEpoch)bh2).getEnd();
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
121 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
122 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 private BedDiffYearResult calculateYearDifference(BedHeight[] pair) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 BedHeightSingle s1 = (BedHeightSingle)pair[0];
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 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
128
073268a137d5 Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6089
diff changeset
129 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
130 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
131
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 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
133 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
134 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
135 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
136 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
137 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
138 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
139
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 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
141
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 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
143 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
144 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
145 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
146 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
147
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 if (!Double.isNaN(hDiff)) {
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
149 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
150 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
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 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
153 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
154 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
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 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
157 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
158 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
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 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
161 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
162 heights2.add(h2);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
163 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
164 }
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
165 return new BedDiffYearResult(
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
166 kms,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
167 diffRes,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
168 heights1,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
169 heights2,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
170 morphs,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
171 absolute,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
172 gap,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
173 s1.getYear(),
6089
0c3301fe23bd towards issue1061: Store names of original BedHeights in the BedDiffYearResult.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
174 s2.getYear(),
0c3301fe23bd towards issue1061: Store names of original BedHeights in the BedDiffYearResult.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
175 s1.getName(),
0c3301fe23bd towards issue1061: Store names of original BedHeights in the BedDiffYearResult.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
176 s2.getName());
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
177 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
178 }

http://dive4elements.wald.intevation.org