Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java @ 8060:25feef564d09
Sediment load: More of official epochs.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 18 Jul 2014 18:55:39 +0200 |
parents | 555dc5a9b282 |
children | 8489565ff563 |
comparison
equal
deleted
inserted
replaced
8059:bde5f5ec7c72 | 8060:25feef564d09 |
---|---|
19 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData; | 19 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData; |
20 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Value; | 20 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Value; |
21 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station; | 21 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station; |
22 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.And; | 22 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.And; |
23 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.IsEpoch; | 23 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.IsEpoch; |
24 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.IsOfficial; | |
24 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.Not; | 25 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.Not; |
25 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.TimeRangeIntersects; | 26 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.TimeRangeIntersects; |
26 import org.dive4elements.river.model.River; | 27 import org.dive4elements.river.model.River; |
27 import org.dive4elements.river.utils.DoubleUtil; | 28 import org.dive4elements.river.utils.DoubleUtil; |
28 | 29 |
123 GrainFraction.make("minfo.susp.sand.flys", SUSP_SAND_FLYS), | 124 GrainFraction.make("minfo.susp.sand.flys", SUSP_SAND_FLYS), |
124 GrainFraction.make("minfo.susp.sand.bed.flys", SUSP_SAND_BED_FLYS), | 125 GrainFraction.make("minfo.susp.sand.bed.flys", SUSP_SAND_BED_FLYS), |
125 GrainFraction.make("minfo.susp.sediment.flys", SUSP_SEDIMENT_FLYS), | 126 GrainFraction.make("minfo.susp.sediment.flys", SUSP_SEDIMENT_FLYS), |
126 }; | 127 }; |
127 | 128 |
128 public static final class Sum implements Value.Visitor { | 129 public static class Sum implements Value.Visitor { |
129 | 130 |
130 private int n; | 131 protected int n; |
131 private double sum; | 132 protected double sum; |
132 private double scale; | |
133 | 133 |
134 public Sum() { | 134 public Sum() { |
135 } | 135 } |
136 | 136 |
137 public Sum(double scale) { | |
138 this.scale = scale; | |
139 } | |
140 | |
141 public double getSum() { | 137 public double getSum() { |
142 return sum * scale; | 138 return sum; |
143 } | 139 } |
144 | 140 |
145 public int getN() { | 141 public int getN() { |
146 return n; | 142 return n; |
147 } | |
148 | |
149 public double getScale() { | |
150 return scale; | |
151 } | 143 } |
152 | 144 |
153 public void reset() { | 145 public void reset() { |
154 n = 0; | 146 n = 0; |
155 sum = 0.0; | 147 sum = 0.0; |
158 @Override | 150 @Override |
159 public void visit(Value value) { | 151 public void visit(Value value) { |
160 sum += value.getValue(); | 152 sum += value.getValue(); |
161 ++n; | 153 ++n; |
162 } | 154 } |
163 } // class Aggregate | 155 } // class Sum |
156 | |
157 public static final class Avg extends Sum { | |
158 public Avg() { | |
159 } | |
160 | |
161 @Override | |
162 public double getSum() { | |
163 return n == 0 ? 0.0 : sum/(double)n; | |
164 } | |
165 } // class Sum | |
164 | 166 |
165 | 167 |
166 private String river; | 168 private String river; |
167 private String yearEpoch; | 169 private String yearEpoch; |
168 private String unit; | 170 private String unit; |
284 } | 286 } |
285 | 287 |
286 boolean isKmUp = isKmUp(); | 288 boolean isKmUp = isKmUp(); |
287 Set<Integer> missingFractions = new TreeSet<Integer>(); | 289 Set<Integer> missingFractions = new TreeSet<Integer>(); |
288 | 290 |
291 // They are not epochs, they are single years! | |
292 Not notEpochs = new Not(IsEpoch.INSTANCE); | |
293 | |
289 for (int [] epoch: epochs) { | 294 for (int [] epoch: epochs) { |
290 Value.Filter filter = new And() | 295 Value.Filter filter = new And() |
291 .add(IsEpoch.INSTANCE) | 296 .add(notEpochs) |
292 .add(new TimeRangeIntersects(epoch[0], epoch[1])); | 297 .add(new TimeRangeIntersects(epoch[0], epoch[1])); |
293 | 298 |
294 double scale = 1.0/(Math.max(epoch[0], epoch[1]) - Math.min(epoch[0], epoch[1]) + 1); | 299 Avg avg = new Avg(); |
295 | |
296 Sum sum = new Sum(scale); | |
297 | 300 |
298 for (GrainFraction gf: GRAIN_FRACTIONS) { | 301 for (GrainFraction gf: GRAIN_FRACTIONS) { |
299 double [][] result = sum( | 302 double [][] result = sum( |
300 sld, gf.getGrainFractions(), filter, sum, isKmUp, | 303 sld, gf.getGrainFractions(), filter, avg, isKmUp, |
301 missingFractions); | 304 missingFractions); |
302 | 305 |
303 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { | 306 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { |
304 // TODO: resolve i18n | 307 // TODO: resolve i18n |
305 addProblem("minfo.sediment.load.no.fractions", | 308 addProblem("minfo.sediment.load.no.fractions", |
314 // TODO: Bundle sub results. | 317 // TODO: Bundle sub results. |
315 return null; | 318 return null; |
316 } | 319 } |
317 | 320 |
318 private CalculationResult calculateOffEpochs() { | 321 private CalculationResult calculateOffEpochs() { |
322 SedimentLoadData sld = | |
323 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); | |
324 if (sld == null) { | |
325 // TODO: i18n | |
326 return error("minfo.sediment.load.no.data"); | |
327 } | |
328 | |
329 boolean isKmUp = isKmUp(); | |
330 Set<Integer> missingFractions = new TreeSet<Integer>(); | |
331 | |
332 for (int [] epoch: epochs) { | |
333 Value.Filter filter = new And() | |
334 .add(IsOfficial.INSTANCE) | |
335 .add(new TimeRangeIntersects(epoch[0], epoch[1])); | |
336 | |
337 Sum sum = new Sum(); | |
338 | |
339 for (GrainFraction gf: GRAIN_FRACTIONS) { | |
340 double [][] result = sum( | |
341 sld, gf.getGrainFractions(), filter, sum, isKmUp, | |
342 missingFractions); | |
343 | |
344 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { | |
345 // TODO: resolve i18n | |
346 addProblem("minfo.sediment.load.no.fractions", | |
347 gf.getDescription()); | |
348 continue; | |
349 } | |
350 // TODO: Generate result data set for calculation. | |
351 // TODO: Optionally transform units. | |
352 } | |
353 } | |
354 // TODO: Generate messages for missing fractions. | |
355 // TODO: Bundle sub results. | |
319 // TODO: Implement me! | 356 // TODO: Implement me! |
320 return null; | 357 return null; |
321 } | 358 } |
322 | 359 |
323 /** Figure out flow direction of river. */ | 360 /** Figure out flow direction of river. */ |