Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffCalculation.java @ 7919:868f55932fe6
Removed serverside path for bed height epochs.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 06 Jun 2014 16:59:16 +0200 |
parents | 1aba75321441 |
children | b5cba2690347 |
comparison
equal
deleted
inserted
replaced
7918:5813c206ff64 | 7919:868f55932fe6 |
---|---|
27 { | 27 { |
28 private static final Logger logger = | 28 private static final Logger logger = |
29 Logger.getLogger(BedDiffCalculation.class); | 29 Logger.getLogger(BedDiffCalculation.class); |
30 | 30 |
31 protected String river; | 31 protected String river; |
32 protected String yearEpoch; | |
33 protected int [][] heightIds; | 32 protected int [][] heightIds; |
34 | 33 |
35 public BedDiffCalculation() { | 34 public BedDiffCalculation() { |
36 } | 35 } |
37 | 36 |
38 public CalculationResult calculate(BedDifferencesAccess access, CallContext context) { | 37 public CalculationResult calculate(BedDifferencesAccess access, CallContext context) { |
39 logger.info("BedDiffCalculation.calculate"); | 38 logger.info("BedDiffCalculation.calculate"); |
40 | 39 |
41 String river = access.getRiverName(); | 40 String river = access.getRiverName(); |
42 String yearEpoch = access.getYearEpoch(); | |
43 int [][] heightIds = access.extractHeightIds(context); | 41 int [][] heightIds = access.extractHeightIds(context); |
44 | 42 |
45 if (river == null) { | 43 if (river == null) { |
46 // TODO: i18n | 44 // TODO: i18n |
47 addProblem("minfo.missing.river"); | 45 addProblem("minfo.missing.river"); |
48 } | 46 } |
49 | 47 |
50 if (yearEpoch == null) { | |
51 addProblem("minfo.missing.year_epoch"); | |
52 } | |
53 | |
54 if (!hasProblems()) { | 48 if (!hasProblems()) { |
55 this.river = river; | 49 this.river = river; |
56 this.yearEpoch = yearEpoch; | |
57 this.heightIds = heightIds; | 50 this.heightIds = heightIds; |
58 return internalCalculate(); | 51 return internalCalculate(); |
59 } | 52 } |
60 | 53 |
61 return new CalculationResult(); | 54 return new CalculationResult(); |
62 } | 55 } |
63 | 56 |
64 private CalculationResult internalCalculate() { | 57 private CalculationResult internalCalculate() { |
65 | |
66 BedDiffYearResult [] results = new BedDiffYearResult[heightIds.length]; | 58 BedDiffYearResult [] results = new BedDiffYearResult[heightIds.length]; |
67 | 59 |
68 for (int i = 0; i < heightIds.length; i++) { | 60 for (int i = 0; i < heightIds.length; i++) { |
69 BedHeightData [] pair = getHeightPair(heightIds[i], "single"); | 61 BedHeightData [] pair = getHeightPair(heightIds[i], "single"); |
70 results[i] = calculateYearDifference(pair); | 62 results[i] = calculateYearDifference(pair); |
71 } | 63 } |
72 return new CalculationResult(results, this); | 64 return new CalculationResult(results, this); |
73 // Currently epochs are handled like single years. To handle epochs | |
74 // uncomment the follwing code and use an if-clause in the code above. | |
75 /* | |
76 if (yearEpoch.equals("epoch")) { | |
77 BedDiffEpochResult [] results = new BedDiffEpochResult[heightIds.length]; | |
78 | |
79 for (int i = 0; i < heightIds.length; i++) { | |
80 BedHeight[] pair = getHeightPair(heightIds[i], "epoch"); | |
81 results[i] = calculateEpochDifference(pair); | |
82 } | |
83 return new CalculationResult(results, this); | |
84 } | |
85 | |
86 return new CalculationResult(); | |
87 */ | |
88 } | 65 } |
89 | 66 |
90 /** Get two BedHeights from factory. */ | 67 /** Get two BedHeights from factory. */ |
91 private static BedHeightData [] getHeightPair(int [] ids, String type) { | 68 private static BedHeightData [] getHeightPair(int [] ids, String type) { |
92 return new BedHeightData [] { | 69 return new BedHeightData [] { |
93 BedHeightFactory.getHeight(type, ids[0], 0), | 70 BedHeightFactory.getHeight(type, ids[0], 0), |
94 BedHeightFactory.getHeight(type, ids[1], 0) | 71 BedHeightFactory.getHeight(type, ids[1], 0) |
95 }; | 72 }; |
96 } | |
97 | |
98 private BedDiffEpochResult calculateEpochDifference(BedHeightData[] pair) { | |
99 | |
100 BedHeightData bh1 = pair[0]; | |
101 BedHeightData bh2 = pair[1]; | |
102 | |
103 TDoubleArrayList stations = bh1.getStations(); | |
104 int size = stations.size(); | |
105 | |
106 TDoubleArrayList diffRes = new TDoubleArrayList(size); | |
107 TDoubleArrayList kms = new TDoubleArrayList(size); | |
108 TDoubleArrayList heights1 = new TDoubleArrayList(size); | |
109 TDoubleArrayList heights2 = new TDoubleArrayList(size); | |
110 | |
111 for (int i = 0; i < size; i++) { | |
112 double station = stations.getQuick(i); | |
113 double h1 = bh1.getHeight(station); | |
114 double h2 = bh2.getHeight(station); | |
115 double hDiff = h1 - h2; | |
116 if (!Double.isNaN(hDiff)) { | |
117 diffRes.add(hDiff); | |
118 kms.add(station); | |
119 heights1.add(h1); | |
120 heights2.add(h2); | |
121 } | |
122 } | |
123 Date start = ((BedHeightEpochData)bh1).getStart(); | |
124 Date end = ((BedHeightEpochData)bh2).getEnd(); | |
125 return new BedDiffEpochResult(kms, diffRes, heights1, heights2, start, end); | |
126 } | 73 } |
127 | 74 |
128 private BedDiffYearResult calculateYearDifference(BedHeightData[] pair) { | 75 private BedDiffYearResult calculateYearDifference(BedHeightData[] pair) { |
129 logger.debug("BedDiffCalculation.calculateYearDifference"); | 76 logger.debug("BedDiffCalculation.calculateYearDifference"); |
130 BedHeightSingleData s1 = (BedHeightSingleData) pair[0]; | 77 BedHeightSingleData s1 = (BedHeightSingleData) pair[0]; |