annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedQualityCalculation.java @ 3874:2c40832cb596

Fixed some stupid bugs in bed quality data factory and calculation. flys-artifacts/trunk@5507 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 18 Sep 2012 15:03:20 +0000
parents 44e68dc1d87e
children d12f108ccc9c
rev   line source
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model.minfo;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
3 import gnu.trove.TDoubleArrayList;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
4
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 import java.util.LinkedList;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 import java.util.List;
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
7 import java.util.Map;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 import org.apache.log4j.Logger;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import de.intevation.flys.artifacts.access.BedQualityAccess;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import de.intevation.flys.artifacts.model.Calculation;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import de.intevation.flys.artifacts.model.CalculationResult;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import de.intevation.flys.artifacts.model.DateRange;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import de.intevation.flys.backend.SedDBSessionHolder;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 public class BedQualityCalculation extends Calculation {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 private static final Logger logger = Logger
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 .getLogger(BedQualityCalculation.class);
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 protected String river;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 protected double from;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 protected double to;
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
26 protected List<String> bedDiameter;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
27 protected List<String> bedloadDiameter;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 protected List<DateRange> ranges;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 public BedQualityCalculation() {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 public CalculationResult calculate(BedQualityAccess access) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 logger.info("BedQualityCalculation.calculate");
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 String river = access.getRiver();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 Double from = access.getFrom();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 Double to = access.getTo();
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
39 List<String> bedDiameter = access.getBedDiameter();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
40 List<String> bedloadDiameter = access.getBedloadDiameter();
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 List<DateRange> ranges = access.getDateRanges();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 if (river == null) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 // TODO: i18n
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 addProblem("minfo.missing.river");
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 if (from == null) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 // TODO: i18n
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 addProblem("minfo.missing.from");
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 if (to == null) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 // TODO: i18n
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 addProblem("minfo.missing.to");
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 if (ranges == null) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 // TODO: i18n
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 addProblem("minfo.missing.periods");
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 if (!hasProblems()) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 this.river = river;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 this.from = from;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 this.to = to;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 this.ranges = ranges;
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
68 this.bedDiameter = bedDiameter;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
69 this.bedloadDiameter = bedloadDiameter;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 SedDBSessionHolder.acquire();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 try {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 return internalCalculate();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 finally {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 SedDBSessionHolder.release();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 return new CalculationResult();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 protected CalculationResult internalCalculate() {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 List<BedQualityResult> results = new LinkedList<BedQualityResult>();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 // Calculate for all time periods.
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 for (DateRange dr : ranges) {
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
88 QualityMeasurements loadMeasurements =
3874
2c40832cb596 Fixed some stupid bugs in bed quality data factory and calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3868
diff changeset
89 QualityMeasurementFactory.getBedloadMeasurements(
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
90 river,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
91 from,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
92 to,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
93 dr.getFrom(),
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
94 dr.getTo());
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
95 QualityMeasurements bedMeasurements =
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
96 QualityMeasurementFactory.getBedMeasurements(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
97 river,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
98 from,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
99 to,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
100 dr.getFrom(),
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
101 dr.getTo());
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
102 BedQualityResult result = new BedQualityResult();
3868
44e68dc1d87e Fixed date range in minfo bed quality result.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3867
diff changeset
103 result.setDateRange(dr);
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
104 if (bedDiameter != null) {
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
105 result.add(calculateBedParameter(bedMeasurements, dr));
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
106 for (String bd : bedDiameter) {
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
107 BedDiameterResult bedResult =
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
108 calculateBed(bedMeasurements, bd, dr);
3772
5a8f8fd5310c The usual wipe after for ill configured Eclipses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3769
diff changeset
109
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
110 // Avoid adding empty result sets.
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
111 if (!bedResult.isEmpty()) {
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
112 result.add(bedResult);
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
113 }
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
114 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
115 }
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
116 if (bedloadDiameter != null) {
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
117 for (String bld : bedloadDiameter) {
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
118 BedloadDiameterResult loadResult =
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
119 calculateBedload(loadMeasurements, bld, dr);
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
120 result.add(loadResult);
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
121 }
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
122 }
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
123 results.add(result);
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 return new CalculationResult(
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 results.toArray(new BedQualityResult[results.size()]), this);
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
130 private BedParametersResult calculateBedParameter(
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
131 QualityMeasurements qm,
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
132 DateRange dr
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
133 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
134 List<Double> kms = qm.getKms();
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
135 QualityMeasurements capFiltered = filterCapMeasurements(qm);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
136 QualityMeasurements subFiltered = filterSubMeasurements(qm);
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
137 TDoubleArrayList location = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
138 TDoubleArrayList porosityCap = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
139 TDoubleArrayList porositySub = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
140 TDoubleArrayList densityCap = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
141 TDoubleArrayList densitySub = new TDoubleArrayList();
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
142
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
143 for(double km : kms) {
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
144 double[] pCap = calculatePorosity(capFiltered, km);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
145 double[] pSub = calculatePorosity(subFiltered, km);
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
146 double[] dCap = calculateDensity(capFiltered, pCap);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
147 double[] dSub = calculateDensity(subFiltered, pSub);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
148
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
149 double pCapRes = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
150 double pSubRes = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
151 double dCapRes = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
152 double dSubRes = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
153 for (int i = 0; i < pCap.length; i++) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
154 pCapRes += pCap[i];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
155 dCapRes += dCap[i];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
156 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
157 for (int i = 0; i < pSub.length; i++) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
158 pSubRes += pSub[i];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
159 dSubRes += dSub[i];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
160 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
161 location.add(km);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
162 porosityCap.add((pCapRes / pCap.length) * 100 );
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
163 porositySub.add((pSubRes / pSub.length) * 100);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
164 densityCap.add((dCapRes / dCap.length) / 1000);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
165 densitySub.add((dSubRes / dSub.length) / 1000);
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
166
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
167 }
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
168
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
169 return new BedParametersResult(
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
170 location,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
171 porosityCap,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
172 porositySub,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
173 densityCap,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
174 densitySub);
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
175 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
176
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
177 protected BedDiameterResult calculateBed(
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
178 QualityMeasurements qm,
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
179 String diameter,
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
180 DateRange range
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
181 ) {
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
182 List<Double> kms = qm.getKms();
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
183 TDoubleArrayList location = new TDoubleArrayList();
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
184 TDoubleArrayList avDiameterCap = new TDoubleArrayList();
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
185 TDoubleArrayList avDiameterSub = new TDoubleArrayList();
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
186 for (double km : kms) {
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
187 //Filter cap and sub measurements.
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
188 QualityMeasurements capFiltered = filterCapMeasurements(qm);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
189 QualityMeasurements subFiltered = filterSubMeasurements(qm);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
190
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
191 List<QualityMeasurement> cm = capFiltered.getMeasurements(km);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
192 List<QualityMeasurement> sm = subFiltered.getMeasurements(km);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
193
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
194 double avCap = calculateAverage(cm, diameter);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
195 double avSub = calculateAverage(sm, diameter);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
196 location.add(km);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
197 avDiameterCap.add(avCap);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
198 avDiameterSub.add(avSub);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
199 }
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
200 return new BedDiameterResult(
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
201 diameter,
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
202 avDiameterCap,
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
203 avDiameterSub,
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
204 location);
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
205 }
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
206
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
207 private double[] calculateDensity(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
208 QualityMeasurements capFiltered,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
209 double[] porosity
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
210 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
211 double[] density = new double[porosity.length];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
212 for (int i = 0; i < porosity.length; i++) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
213 density[i] = (1 - porosity[i]) * 2650;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
214 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
215 return density;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
216 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
217
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
218 private double[] calculatePorosity(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
219 QualityMeasurements capFiltered,
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
220 double km
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
221 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
222 List<QualityMeasurement> list = capFiltered.getMeasurements(km);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
223 double[] results = new double[list.size()];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
224 int i = 0;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
225 for (QualityMeasurement qm : list) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
226 double deviation = calculateDeviation(qm);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
227 double p = calculateP(qm);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
228 double porosity = 0.353 - 0.068 * deviation + 0.146 * p;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
229 results[i] = porosity;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
230 i++;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
231 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
232
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
233 return results;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
234 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
235
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
236 protected BedloadDiameterResult calculateBedload(
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
237 QualityMeasurements qm,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
238 String diameter,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
239 DateRange range
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
240 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
241 List<Double> kms = qm.getKms();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
242 TDoubleArrayList location = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
243 TDoubleArrayList avDiameter = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
244 for (double km : kms) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
245 List<QualityMeasurement> measurements = qm.getMeasurements(km);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
246 double mid = calculateAverage(measurements, diameter);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
247 location.add(km);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
248 avDiameter.add(mid);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
249 }
3867
d8c99ff18db8 Refactor MINFO bed quality resultsets and facets.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3780
diff changeset
250 return new BedloadDiameterResult(
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
251 diameter,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
252 avDiameter,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
253 location,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
254 range);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
255 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
256
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
257 protected double calculateAverage(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
258 List<QualityMeasurement> list,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
259 String diameter
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
260 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
261 double av = 0;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
262 for (QualityMeasurement qm : list) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
263 av += qm.getDiameter(diameter);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
264 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
265 return av/list.size();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
266 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
267
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
268 protected QualityMeasurements filterCapMeasurements(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
269 QualityMeasurements qms
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
270 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
271 List<QualityMeasurement> result = new LinkedList<QualityMeasurement>();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
272 for (QualityMeasurement qm : qms.getMeasurements()) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
273 if (qm.getDepth1() == 0d && qm.getDepth2() <= 0.3) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
274 result.add(qm);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
275 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
276 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
277 return new QualityMeasurements(result);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
278 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
279
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
280 protected QualityMeasurements filterSubMeasurements(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
281 QualityMeasurements qms
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
282 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
283 List<QualityMeasurement> result = new LinkedList<QualityMeasurement>();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
284 for (QualityMeasurement qm : qms.getMeasurements()) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
285 if (qm.getDepth1() > 0d && qm.getDepth2() <= 0.5) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
286 result.add(qm);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
287 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
288 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
289 return new QualityMeasurements(result);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
290 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
291
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
292 public double calculateDeviation(QualityMeasurement qm) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
293 Map<String, Double> dm = qm.getAllDiameter();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
294 double phiM = 0;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
295 double[] phis = new double[dm.size()];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
296 double[] ps = new double[dm.size()];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
297 int i = 0;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
298 for (String key : dm.keySet()) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
299 double d = dm.get(key);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
300 double phi = -Math.log(d)/Math.log(2);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
301 phis[i] = phi;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
302 double p = calculateWeight(qm, key);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
303 ps[i] = p;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
304 phiM += phi * p;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
305 i++;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
306 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
307
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
308 double sig = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
309 for (i = 0; i < dm.size(); i++) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
310 sig += ps[i] * Math.exp(phis[i] - phiM);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
311 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
312 double deviation = Math.sqrt(sig);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
313 return deviation;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
314 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
315
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
316 protected double calculateP(QualityMeasurement qm) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
317 return calculateWeight(qm, "dmin");
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
318 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
319
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
320 public double calculateWeight(QualityMeasurement qm, String diameter) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
321 Map<String, Double> dm = qm.getAllDiameter();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
322 double value = qm.getDiameter(diameter);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
323
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
324 double sum = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
325 for (Double d : dm.values()) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
326 sum =+ d.doubleValue();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
327 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
328 double weight = sum/100*value;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
329 return weight;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
330 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
331 }

http://dive4elements.wald.intevation.org