Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedDiffCalculation.java @ 3898:95d699c769fb
Bedheight difference calculation has chart outpus now.
flys-artifacts/trunk@5562 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 21 Sep 2012 14:29:32 +0000 |
parents | a1c79d84e3cd |
children |
comparison
equal
deleted
inserted
replaced
3897:bce2dd4310a6 | 3898:95d699c769fb |
---|---|
1 package de.intevation.flys.artifacts.model.minfo; | 1 package de.intevation.flys.artifacts.model.minfo; |
2 | 2 |
3 import gnu.trove.TDoubleArrayList; | 3 import gnu.trove.TDoubleArrayList; |
4 | 4 |
5 import java.util.Date; | |
5 import java.util.LinkedList; | 6 import java.util.LinkedList; |
6 import java.util.List; | 7 import java.util.List; |
7 | 8 |
8 import org.apache.log4j.Logger; | 9 import org.apache.log4j.Logger; |
9 | 10 |
16 public class BedDiffCalculation | 17 public class BedDiffCalculation |
17 extends Calculation | 18 extends Calculation |
18 { | 19 { |
19 | 20 |
20 private static final Logger logger = Logger | 21 private static final Logger logger = Logger |
21 .getLogger(BedQualityCalculation.class); | 22 .getLogger(BedDiffCalculation.class); |
22 | 23 |
23 protected String river; | 24 protected String river; |
24 protected String yearEpoch; | 25 protected String yearEpoch; |
25 protected FLYSArtifact[][] artifacts; | 26 protected FLYSArtifact[][] artifacts; |
26 | 27 |
27 public BedDiffCalculation() { | 28 public BedDiffCalculation() { |
28 } | 29 } |
29 | 30 |
30 public CalculationResult calculate(BedDifferencesAccess access) { | 31 public CalculationResult calculate(BedDifferencesAccess access) { |
31 logger.info("BedQualityCalculation.calculate"); | 32 logger.info("BedDiffCalculation.calculate"); |
32 | 33 |
33 String river = access.getRiver(); | 34 String river = access.getRiver(); |
34 String yearEpoch = access.getYearEpoch(); | 35 String yearEpoch = access.getYearEpoch(); |
35 FLYSArtifact[][] artifacts = access.getDifferenceArtifacts(); | 36 FLYSArtifact[][] artifacts = access.getDifferenceArtifacts(); |
36 | 37 |
38 logger.debug("got artifacts: " + artifacts.length + "; " + artifacts[0].length); | |
37 if (river == null) { | 39 if (river == null) { |
38 // TODO: i18n | 40 // TODO: i18n |
39 addProblem("minfo.missing.river"); | 41 addProblem("minfo.missing.river"); |
40 } | 42 } |
41 | 43 |
56 | 58 |
57 return new CalculationResult(); | 59 return new CalculationResult(); |
58 } | 60 } |
59 | 61 |
60 private CalculationResult internalCalculate() { | 62 private CalculationResult internalCalculate() { |
61 List<BedDifferencesResult> results = | |
62 new LinkedList<BedDifferencesResult>(); | |
63 | 63 |
64 if (yearEpoch.equals("year")) { | 64 if (yearEpoch.equals("year")) { |
65 List<BedDiffYearResult> results = | |
66 new LinkedList<BedDiffYearResult>(); | |
67 | |
65 for (int i = 0; i < artifacts.length; i++) { | 68 for (int i = 0; i < artifacts.length; i++) { |
66 BedHeight[] pair = | 69 BedHeight[] pair = |
67 getHeightPair(artifacts[i][0], artifacts[i][1], "single"); | 70 getHeightPair(artifacts[i][0], artifacts[i][1], "single"); |
68 BedDifferencesResult res = calculateYearDifference(pair); | 71 BedDiffYearResult res = calculateYearDifference(pair); |
69 results.add(res); | 72 results.add(res); |
70 } | 73 } |
74 return new CalculationResult( | |
75 results.toArray(new BedDiffYearResult[results.size()]), this); | |
71 } | 76 } |
72 if (yearEpoch.equals("epoch")) { | 77 if (yearEpoch.equals("epoch")) { |
78 List<BedDiffEpochResult> results = | |
79 new LinkedList<BedDiffEpochResult>(); | |
73 for (int i = 0; i < artifacts.length; i++) { | 80 for (int i = 0; i < artifacts.length; i++) { |
74 BedHeight[] pair = | 81 BedHeight[] pair = |
75 getHeightPair(artifacts[i][0], artifacts[i][1], "epoch"); | 82 getHeightPair(artifacts[i][0], artifacts[i][1], "epoch"); |
76 BedDifferencesResult res = calculateEpochDifference(pair); | 83 BedDiffEpochResult res = calculateEpochDifference(pair); |
77 results.add(res); | 84 results.add(res); |
78 } | 85 } |
86 return new CalculationResult( | |
87 results.toArray(new BedDiffEpochResult[results.size()]), this); | |
79 } | 88 } |
80 | 89 |
81 return new CalculationResult( | 90 return new CalculationResult(); |
82 results.toArray(new BedDifferencesResult[results.size()]), this); | |
83 } | 91 } |
84 | 92 |
85 private BedHeight[] getHeightPair( | 93 private BedHeight[] getHeightPair( |
86 FLYSArtifact art1, | 94 FLYSArtifact art1, |
87 FLYSArtifact art2, | 95 FLYSArtifact art2, |
99 private BedDiffEpochResult calculateEpochDifference(BedHeight[] pair) { | 107 private BedDiffEpochResult calculateEpochDifference(BedHeight[] pair) { |
100 | 108 |
101 TDoubleArrayList stations = pair[0].getStations(); | 109 TDoubleArrayList stations = pair[0].getStations(); |
102 TDoubleArrayList diffRes = new TDoubleArrayList(); | 110 TDoubleArrayList diffRes = new TDoubleArrayList(); |
103 TDoubleArrayList kms = new TDoubleArrayList(); | 111 TDoubleArrayList kms = new TDoubleArrayList(); |
104 TDoubleArrayList morphs = new TDoubleArrayList(); | 112 TDoubleArrayList heights1 = new TDoubleArrayList(); |
113 TDoubleArrayList heights2 = new TDoubleArrayList(); | |
114 | |
105 for (int i = 0; i < stations.size(); i++) { | 115 for (int i = 0; i < stations.size(); i++) { |
106 if (!Double.isNaN(pair[0].getHeight(stations.get(i))) && | 116 if (!Double.isNaN(pair[0].getHeight(stations.get(i))) && |
107 !Double.isNaN(pair[1].getHeight(stations.get(i)))) { | 117 !Double.isNaN(pair[1].getHeight(stations.get(i)))) { |
108 double hDiff = | 118 double hDiff = |
109 pair[0].getHeight(stations.get(i)) - | 119 pair[0].getHeight(stations.get(i)) - |
110 pair[1].getHeight(stations.get(i)); | 120 pair[1].getHeight(stations.get(i)); |
111 diffRes.add(hDiff); | 121 diffRes.add(hDiff); |
112 kms.add(stations.get(i)); | 122 kms.add(stations.get(i)); |
113 if (pair[0].getMorphWidth(i) > pair[1].getMorphWidth(i)) { | 123 heights1.add(pair[0].getHeight(stations.get(i))); |
114 morphs.add(pair[0].getMorphWidth(i)); | 124 heights2.add(pair[1].getHeight(stations.get(i))); |
115 } | |
116 else { | |
117 morphs.add(pair[1].getMorphWidth(i)); | |
118 } | |
119 } | 125 } |
120 } | 126 } |
121 return new BedDiffEpochResult(kms, diffRes, morphs); | 127 Date start = ((BedHeightEpoch)pair[0]).getStart(); |
128 Date end = ((BedHeightEpoch)pair[1]).getEnd(); | |
129 return new BedDiffEpochResult(kms, diffRes, heights1, heights2, start, end); | |
122 } | 130 } |
123 | 131 |
124 private BedDiffYearResult calculateYearDifference(BedHeight[] pair) { | 132 private BedDiffYearResult calculateYearDifference(BedHeight[] pair) { |
125 | 133 |
126 TDoubleArrayList stations = pair[0].getStations(); | 134 TDoubleArrayList stations = pair[0].getStations(); |
127 TDoubleArrayList diffRes = new TDoubleArrayList(); | 135 TDoubleArrayList diffRes = new TDoubleArrayList(); |
128 TDoubleArrayList kms = new TDoubleArrayList(); | 136 TDoubleArrayList kms = new TDoubleArrayList(); |
129 TDoubleArrayList morphs = new TDoubleArrayList(); | 137 TDoubleArrayList morphs = new TDoubleArrayList(); |
130 TDoubleArrayList heights = new TDoubleArrayList(); | 138 TDoubleArrayList absolute = new TDoubleArrayList(); |
131 TDoubleArrayList gap = new TDoubleArrayList(); | 139 TDoubleArrayList gap = new TDoubleArrayList(); |
140 TDoubleArrayList heights1 = new TDoubleArrayList(); | |
141 TDoubleArrayList heights2 = new TDoubleArrayList(); | |
142 | |
132 BedHeightSingle s1 = (BedHeightSingle)pair[0]; | 143 BedHeightSingle s1 = (BedHeightSingle)pair[0]; |
133 BedHeightSingle s2 = (BedHeightSingle)pair[1]; | 144 BedHeightSingle s2 = (BedHeightSingle)pair[1]; |
134 int range = s1.getYear() - s2.getYear(); | 145 int range = s1.getYear() - s2.getYear(); |
135 if (range < 0) { | 146 if (range < 0) { |
136 range = range * -1; | 147 range = range * -1; |
137 } | 148 } |
138 for (int i = 0; i < stations.size(); i++) { | 149 for (int i = 0; i < stations.size(); i++) { |
139 if (!Double.isNaN(pair[0].getHeight(stations.get(i))) && | 150 if (!Double.isNaN(s1.getHeight(stations.get(i))) && |
140 !Double.isNaN(pair[1].getHeight(stations.get(i)))) { | 151 !Double.isNaN(s2.getHeight(stations.get(i)))) { |
141 double hDiff = | 152 double hDiff = |
142 pair[0].getHeight(stations.get(i)) - | 153 s1.getHeight(stations.get(i)) - |
143 pair[1].getHeight(stations.get(i)); | 154 s2.getHeight(stations.get(i)); |
144 diffRes.add(hDiff); | 155 diffRes.add(hDiff); |
145 kms.add(stations.get(i)); | 156 double km = stations.get(i); |
146 if (pair[0].getMorphWidth(i) > pair[1].getMorphWidth(i)) { | 157 kms.add(km); |
147 morphs.add(pair[0].getMorphWidth(i)); | 158 if (s1.getMorphWidth(km) > |
159 s2.getMorphWidth(km)) { | |
160 morphs.add(s1.getMorphWidth(km)); | |
148 } | 161 } |
149 else { | 162 else { |
150 morphs.add(pair[1].getMorphWidth(i)); | 163 morphs.add(s2.getMorphWidth(km)); |
151 } | 164 } |
152 if (pair[0].getDataGap(i) > pair[1].getDataGap(i)) { | 165 if (s1.getDataGap(km) > s2.getDataGap(km)) { |
153 gap.add(pair[0].getDataGap(i)); | 166 gap.add(s1.getDataGap(km)); |
154 } | 167 } |
155 else { | 168 else { |
156 gap.add(pair[1].getDataGap(i)); | 169 gap.add(s2.getDataGap(km)); |
157 } | 170 } |
158 heights.add(hDiff / range); | 171 absolute.add((hDiff / range) * 100); |
172 heights1.add(s1.getHeight(km)); | |
173 heights2.add(s2.getHeight(km)); | |
159 } | 174 } |
160 } | 175 } |
161 return new BedDiffYearResult(kms, diffRes, morphs, heights, gap); | 176 return new BedDiffYearResult( |
177 kms, | |
178 diffRes, | |
179 heights1, | |
180 heights2, | |
181 morphs, | |
182 absolute, | |
183 gap, | |
184 s1.getYear(), | |
185 s2.getYear()); | |
162 } | 186 } |
163 } | 187 } |