Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedDiffCalculation.java @ 3887:a1c79d84e3cd
New calcultion in MINFO: Bed height difference calculation.
flys-artifacts/trunk@5538 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 20 Sep 2012 09:34:48 +0000 |
parents | |
children | 95d699c769fb |
comparison
equal
deleted
inserted
replaced
3886:633fbb61a0cc | 3887:a1c79d84e3cd |
---|---|
1 package de.intevation.flys.artifacts.model.minfo; | |
2 | |
3 import gnu.trove.TDoubleArrayList; | |
4 | |
5 import java.util.LinkedList; | |
6 import java.util.List; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 import de.intevation.flys.artifacts.FLYSArtifact; | |
11 import de.intevation.flys.artifacts.access.BedDifferencesAccess; | |
12 import de.intevation.flys.artifacts.model.Calculation; | |
13 import de.intevation.flys.artifacts.model.CalculationResult; | |
14 | |
15 | |
16 public class BedDiffCalculation | |
17 extends Calculation | |
18 { | |
19 | |
20 private static final Logger logger = Logger | |
21 .getLogger(BedQualityCalculation.class); | |
22 | |
23 protected String river; | |
24 protected String yearEpoch; | |
25 protected FLYSArtifact[][] artifacts; | |
26 | |
27 public BedDiffCalculation() { | |
28 } | |
29 | |
30 public CalculationResult calculate(BedDifferencesAccess access) { | |
31 logger.info("BedQualityCalculation.calculate"); | |
32 | |
33 String river = access.getRiver(); | |
34 String yearEpoch = access.getYearEpoch(); | |
35 FLYSArtifact[][] artifacts = access.getDifferenceArtifacts(); | |
36 | |
37 if (river == null) { | |
38 // TODO: i18n | |
39 addProblem("minfo.missing.river"); | |
40 } | |
41 | |
42 if (yearEpoch == null) { | |
43 addProblem("minfo.missing.year_epoch"); | |
44 } | |
45 | |
46 if (artifacts == null) { | |
47 addProblem("minfo.missing.differences"); | |
48 } | |
49 | |
50 if (!hasProblems()) { | |
51 this.river = river; | |
52 this.yearEpoch = yearEpoch; | |
53 this.artifacts = artifacts; | |
54 return internalCalculate(); | |
55 } | |
56 | |
57 return new CalculationResult(); | |
58 } | |
59 | |
60 private CalculationResult internalCalculate() { | |
61 List<BedDifferencesResult> results = | |
62 new LinkedList<BedDifferencesResult>(); | |
63 | |
64 if (yearEpoch.equals("year")) { | |
65 for (int i = 0; i < artifacts.length; i++) { | |
66 BedHeight[] pair = | |
67 getHeightPair(artifacts[i][0], artifacts[i][1], "single"); | |
68 BedDifferencesResult res = calculateYearDifference(pair); | |
69 results.add(res); | |
70 } | |
71 } | |
72 if (yearEpoch.equals("epoch")) { | |
73 for (int i = 0; i < artifacts.length; i++) { | |
74 BedHeight[] pair = | |
75 getHeightPair(artifacts[i][0], artifacts[i][1], "epoch"); | |
76 BedDifferencesResult res = calculateEpochDifference(pair); | |
77 results.add(res); | |
78 } | |
79 } | |
80 | |
81 return new CalculationResult( | |
82 results.toArray(new BedDifferencesResult[results.size()]), this); | |
83 } | |
84 | |
85 private BedHeight[] getHeightPair( | |
86 FLYSArtifact art1, | |
87 FLYSArtifact art2, | |
88 String type | |
89 ) { | |
90 int id1 = BedDifferencesAccess.getHeightId(art1); | |
91 int id2 = BedDifferencesAccess.getHeightId(art2); | |
92 | |
93 BedHeight[] heights = new BedHeight[2]; | |
94 heights[0] = BedHeightFactory.getHeight(type, id1, 0); | |
95 heights[1] = BedHeightFactory.getHeight(type, id2, 0); | |
96 return heights; | |
97 } | |
98 | |
99 private BedDiffEpochResult calculateEpochDifference(BedHeight[] pair) { | |
100 | |
101 TDoubleArrayList stations = pair[0].getStations(); | |
102 TDoubleArrayList diffRes = new TDoubleArrayList(); | |
103 TDoubleArrayList kms = new TDoubleArrayList(); | |
104 TDoubleArrayList morphs = new TDoubleArrayList(); | |
105 for (int i = 0; i < stations.size(); i++) { | |
106 if (!Double.isNaN(pair[0].getHeight(stations.get(i))) && | |
107 !Double.isNaN(pair[1].getHeight(stations.get(i)))) { | |
108 double hDiff = | |
109 pair[0].getHeight(stations.get(i)) - | |
110 pair[1].getHeight(stations.get(i)); | |
111 diffRes.add(hDiff); | |
112 kms.add(stations.get(i)); | |
113 if (pair[0].getMorphWidth(i) > pair[1].getMorphWidth(i)) { | |
114 morphs.add(pair[0].getMorphWidth(i)); | |
115 } | |
116 else { | |
117 morphs.add(pair[1].getMorphWidth(i)); | |
118 } | |
119 } | |
120 } | |
121 return new BedDiffEpochResult(kms, diffRes, morphs); | |
122 } | |
123 | |
124 private BedDiffYearResult calculateYearDifference(BedHeight[] pair) { | |
125 | |
126 TDoubleArrayList stations = pair[0].getStations(); | |
127 TDoubleArrayList diffRes = new TDoubleArrayList(); | |
128 TDoubleArrayList kms = new TDoubleArrayList(); | |
129 TDoubleArrayList morphs = new TDoubleArrayList(); | |
130 TDoubleArrayList heights = new TDoubleArrayList(); | |
131 TDoubleArrayList gap = new TDoubleArrayList(); | |
132 BedHeightSingle s1 = (BedHeightSingle)pair[0]; | |
133 BedHeightSingle s2 = (BedHeightSingle)pair[1]; | |
134 int range = s1.getYear() - s2.getYear(); | |
135 if (range < 0) { | |
136 range = range * -1; | |
137 } | |
138 for (int i = 0; i < stations.size(); i++) { | |
139 if (!Double.isNaN(pair[0].getHeight(stations.get(i))) && | |
140 !Double.isNaN(pair[1].getHeight(stations.get(i)))) { | |
141 double hDiff = | |
142 pair[0].getHeight(stations.get(i)) - | |
143 pair[1].getHeight(stations.get(i)); | |
144 diffRes.add(hDiff); | |
145 kms.add(stations.get(i)); | |
146 if (pair[0].getMorphWidth(i) > pair[1].getMorphWidth(i)) { | |
147 morphs.add(pair[0].getMorphWidth(i)); | |
148 } | |
149 else { | |
150 morphs.add(pair[1].getMorphWidth(i)); | |
151 } | |
152 if (pair[0].getDataGap(i) > pair[1].getDataGap(i)) { | |
153 gap.add(pair[0].getDataGap(i)); | |
154 } | |
155 else { | |
156 gap.add(pair[1].getDataGap(i)); | |
157 } | |
158 heights.add(hDiff / range); | |
159 } | |
160 } | |
161 return new BedDiffYearResult(kms, diffRes, morphs, heights, gap); | |
162 } | |
163 } |