annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffCalculation.java @ 6147:073268a137d5

Bed height differences: Some refactoring of the calculation to improve readability and performance.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sat, 01 Jun 2013 18:59:52 +0200
parents 0c3301fe23bd
children b12ec9f240bc
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 */
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: 3898
diff changeset
9 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
10
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import gnu.trove.TDoubleArrayList;
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
13 import java.util.Date;
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import java.util.LinkedList;
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import java.util.List;
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import org.apache.log4j.Logger;
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
19 import org.dive4elements.river.artifacts.D4EArtifact;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3898
diff changeset
20 import org.dive4elements.river.artifacts.access.BedDifferencesAccess;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3898
diff changeset
21 import org.dive4elements.river.artifacts.model.Calculation;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3898
diff changeset
22 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
23
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24
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 {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 private static final Logger logger = Logger
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
30 .getLogger(BedDiffCalculation.class);
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 protected String river;
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 protected String yearEpoch;
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
34 protected D4EArtifact[][] artifacts;
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 public BedDiffCalculation() {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 public CalculationResult calculate(BedDifferencesAccess access) {
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
40 logger.info("BedDiffCalculation.calculate");
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 String river = access.getRiver();
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 String yearEpoch = access.getYearEpoch();
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
44 D4EArtifact[][] artifacts = access.getDifferenceArtifacts();
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
46 logger.debug("got artifacts: " + artifacts.length + "; " + artifacts[0].length);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 if (river == null) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 // TODO: i18n
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 addProblem("minfo.missing.river");
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
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 if (yearEpoch == null) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 addProblem("minfo.missing.year_epoch");
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 if (artifacts == null) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 addProblem("minfo.missing.differences");
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 }
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 if (!hasProblems()) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 this.river = river;
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 this.yearEpoch = yearEpoch;
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 this.artifacts = artifacts;
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 return internalCalculate();
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 return new CalculationResult();
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 private CalculationResult internalCalculate() {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 if (yearEpoch.equals("year")) {
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
73 List<BedDiffYearResult> results =
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
74 new LinkedList<BedDiffYearResult>();
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
75
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 for (int i = 0; i < artifacts.length; i++) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 BedHeight[] pair =
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 getHeightPair(artifacts[i][0], artifacts[i][1], "single");
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
79 BedDiffYearResult res = calculateYearDifference(pair);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 results.add(res);
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 }
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
82 return new CalculationResult(
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
83 results.toArray(new BedDiffYearResult[results.size()]), 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 if (yearEpoch.equals("epoch")) {
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
86 List<BedDiffEpochResult> results =
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
87 new LinkedList<BedDiffEpochResult>();
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 for (int i = 0; i < artifacts.length; i++) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 BedHeight[] pair =
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 getHeightPair(artifacts[i][0], artifacts[i][1], "epoch");
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
91 BedDiffEpochResult res = calculateEpochDifference(pair);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92 results.add(res);
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93 }
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
94 return new CalculationResult(
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
95 results.toArray(new BedDiffEpochResult[results.size()]), this);
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
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
98 return new CalculationResult();
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101 private BedHeight[] getHeightPair(
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
102 D4EArtifact art1,
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
103 D4EArtifact art2,
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 String type
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 ) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 int id1 = BedDifferencesAccess.getHeightId(art1);
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107 int id2 = BedDifferencesAccess.getHeightId(art2);
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 BedHeight[] heights = new BedHeight[2];
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 heights[0] = BedHeightFactory.getHeight(type, id1, 0);
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 heights[1] = BedHeightFactory.getHeight(type, id2, 0);
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 return heights;
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
115 private BedDiffEpochResult calculateEpochDifference(BedHeight[] pair) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116
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
117 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
118 BedHeight bh2 = pair[1];
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
119
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
120 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
121 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
122
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 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
124 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
125 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
126 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
127
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 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
129 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
130 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
131 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
132 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
133 if (!Double.isNaN(hDiff)) {
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134 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
135 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
136 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
137 heights2.add(h2);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
138 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
139 }
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
140 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
141 Date end = ((BedHeightEpoch)bh2).getEnd();
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
142 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
143 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
144
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
145 private BedDiffYearResult calculateYearDifference(BedHeight[] pair) {
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
146
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
147 BedHeightSingle s1 = (BedHeightSingle)pair[0];
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
148 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
149
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 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
151 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
152
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 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
154 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
155 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
156 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
157 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
158 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
159 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
160
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 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
162
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 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
164 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
165 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
166 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
167 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
168
073268a137d5 Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6089
diff changeset
169 if (!Double.isNaN(hDiff)) {
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
170 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
171 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
172
073268a137d5 Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6089
diff changeset
173 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
174 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
175 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
176
073268a137d5 Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6089
diff changeset
177 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
178 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
179 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
180
073268a137d5 Bed height differences: Some refactoring of the calculation to improve readability and performance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6089
diff changeset
181 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
182 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
183 heights2.add(h2);
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
184 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
185 }
3898
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
186 return new BedDiffYearResult(
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
187 kms,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
188 diffRes,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
189 heights1,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
190 heights2,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
191 morphs,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
192 absolute,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
193 gap,
95d699c769fb Bedheight difference calculation has chart outpus now.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3887
diff changeset
194 s1.getYear(),
6089
0c3301fe23bd towards issue1061: Store names of original BedHeights in the BedDiffYearResult.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
195 s2.getYear(),
0c3301fe23bd towards issue1061: Store names of original BedHeights in the BedDiffYearResult.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
196 s1.getName(),
0c3301fe23bd towards issue1061: Store names of original BedHeights in the BedDiffYearResult.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
197 s2.getName());
3887
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
198 }
a1c79d84e3cd New calcultion in MINFO: Bed height difference calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
199 }

http://dive4elements.wald.intevation.org