Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/MiddleBedHeightCalculation.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 | 2c7a16d59f67 |
children |
comparison
equal
deleted
inserted
replaced
7918:5813c206ff64 | 7919:868f55932fe6 |
---|---|
14 import org.apache.log4j.Logger; | 14 import org.apache.log4j.Logger; |
15 | 15 |
16 import org.dive4elements.artifacts.Artifact; | 16 import org.dive4elements.artifacts.Artifact; |
17 import org.dive4elements.artifacts.common.utils.DateUtils; | 17 import org.dive4elements.artifacts.common.utils.DateUtils; |
18 | 18 |
19 import org.dive4elements.river.model.BedHeightEpoch; | |
20 import org.dive4elements.river.model.BedHeightEpochValue; | |
21 import org.dive4elements.river.model.BedHeightSingle; | 19 import org.dive4elements.river.model.BedHeightSingle; |
22 import org.dive4elements.river.model.BedHeightSingleValue; | 20 import org.dive4elements.river.model.BedHeightSingleValue; |
23 import org.dive4elements.river.model.TimeInterval; | 21 import org.dive4elements.river.model.TimeInterval; |
24 | 22 |
25 import org.dive4elements.river.artifacts.access.BedHeightAccess; | 23 import org.dive4elements.river.artifacts.access.BedHeightAccess; |
33 | 31 |
34 public CalculationResult calculate(BedHeightAccess access) { | 32 public CalculationResult calculate(BedHeightAccess access) { |
35 logger.info("MiddleBedHeightCalculation.calculate"); | 33 logger.info("MiddleBedHeightCalculation.calculate"); |
36 | 34 |
37 int[] singleIds = access.getBedHeightSingleIDs(); | 35 int[] singleIds = access.getBedHeightSingleIDs(); |
38 int[] epochIds = access.getBedHeightEpochIDs(); | |
39 | 36 |
40 | 37 |
41 if (logger.isDebugEnabled()) { | 38 if (logger.isDebugEnabled()) { |
42 Artifact artifact = access.getArtifact(); | 39 Artifact artifact = access.getArtifact(); |
43 | 40 |
44 logger.debug("Artifact '" + artifact.identifier() + "' contains:"); | 41 logger.debug("Artifact '" + artifact.identifier() + "' contains:"); |
45 if (singleIds != null) { | 42 if (singleIds != null) { |
46 logger.debug(" " + singleIds.length + " single bedheight ids"); | 43 logger.debug(" " + singleIds.length + " single bedheight ids"); |
47 } | 44 } |
48 | |
49 if (epochIds != null) { | |
50 logger.debug(" " + epochIds.length + " epoch bedheight ids"); | |
51 } | |
52 } | 45 } |
53 | 46 |
54 List<BedHeightSingle> singles = getSingles(access, singleIds); | 47 List<BedHeightSingle> singles = getSingles(access, singleIds); |
55 List<BedHeightEpoch> epochs = getEpochs(access, epochIds); | |
56 | 48 |
57 return buildCalculationResult(access, singles, epochs); | 49 return buildCalculationResult(access, singles); |
58 } | 50 } |
59 | 51 |
60 | 52 |
61 protected List<BedHeightSingle> getSingles( | 53 protected List<BedHeightSingle> getSingles( |
62 BedHeightAccess access, | 54 BedHeightAccess access, |
78 | 70 |
79 return singles; | 71 return singles; |
80 } | 72 } |
81 | 73 |
82 | 74 |
83 protected List<BedHeightEpoch> getEpochs( | |
84 BedHeightAccess access, | |
85 int[] ids | |
86 ) { | |
87 List<BedHeightEpoch> epochs = new ArrayList<BedHeightEpoch>(); | |
88 | |
89 for (int id: ids) { | |
90 BedHeightEpoch e = BedHeightEpoch.getBedHeightEpochById(id); | |
91 | |
92 if (e != null) { | |
93 epochs.add(e); | |
94 } | |
95 else { | |
96 logger.warn("Cannot find Epoch by id: " + id); | |
97 // TODO ADD WARNING | |
98 } | |
99 } | |
100 | |
101 return epochs; | |
102 } | |
103 | |
104 | |
105 protected CalculationResult buildCalculationResult( | 75 protected CalculationResult buildCalculationResult( |
106 BedHeightAccess access, | 76 BedHeightAccess access, |
107 List<BedHeightSingle> singles, | 77 List<BedHeightSingle> singles |
108 List<BedHeightEpoch> epochs | |
109 ) { | 78 ) { |
110 logger.info("MiddleBedHeightCalculation.buildCalculationResult"); | 79 logger.info("MiddleBedHeightCalculation.buildCalculationResult"); |
111 | 80 |
112 double kmLo = access.getLowerKM(); | 81 double kmLo = access.getLowerKM(); |
113 double kmHi = access.getUpperKM(); | 82 double kmHi = access.getUpperKM(); |
114 | 83 |
115 List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>(); | 84 List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>(); |
116 | 85 |
117 for (BedHeightSingle single: singles) { | 86 for (BedHeightSingle single: singles) { |
118 MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi); | 87 MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi); |
119 | |
120 if (d != null) { | |
121 data.add(d); | |
122 } | |
123 } | |
124 | |
125 for (BedHeightEpoch epoch: epochs) { | |
126 MiddleBedHeightData d = prepareEpochData(epoch, kmLo, kmHi); | |
127 | 88 |
128 if (d != null) { | 89 if (d != null) { |
129 data.add(d); | 90 data.add(d); |
130 } | 91 } |
131 } | 92 } |
184 | 145 |
185 logger.debug("Single contains " + values.size() + " values"); | 146 logger.debug("Single contains " + values.size() + " values"); |
186 | 147 |
187 return data; | 148 return data; |
188 } | 149 } |
189 | |
190 | |
191 /** Create MiddleBedHeightData to return. */ | |
192 protected MiddleBedHeightData prepareEpochData( | |
193 BedHeightEpoch epoch, | |
194 double kmLo, | |
195 double kmHi | |
196 ) { | |
197 logger.debug("Prepare data for epoch: " + epoch.getDescription()); | |
198 | |
199 TimeInterval ti = epoch.getTimeInterval(); | |
200 | |
201 List<BedHeightEpochValue> values = | |
202 BedHeightEpochValue.getBedHeightEpochValues(epoch, kmLo, kmHi); | |
203 | |
204 MiddleBedHeightData data = new MiddleBedHeightData( | |
205 DateUtils.getYearFromDate(ti.getStartTime()), | |
206 DateUtils.getYearFromDate(ti.getStopTime()), | |
207 epoch.getEvaluationBy(), | |
208 epoch.getDescription() | |
209 ); | |
210 | |
211 for (BedHeightEpochValue value: values) { | |
212 data.addKM(value.getStation().doubleValue()); | |
213 if (value.getHeight() != null) { | |
214 data.addMiddleHeight(value.getHeight().doubleValue()); | |
215 data.addIsEmpty(false); | |
216 } | |
217 else { | |
218 data.addMiddleHeight(Double.NaN); | |
219 data.addIsEmpty(true); | |
220 } | |
221 } | |
222 | |
223 logger.debug("Epoch contains " + values.size() + " values"); | |
224 | |
225 return data; | |
226 } | |
227 } | 150 } |
228 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 151 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |