comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/MiddleBedHeightCalculation.java @ 7983:62befca02480 facet-metadata

Moved MiddleBedHeight classes to minfo package. Facet now returns double[][] data.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 01 Jul 2014 13:25:46 +0200
parents
children 98e25342df73
comparison
equal deleted inserted replaced
7981:45cced06490c 7983:62befca02480
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.artifacts.model.minfo;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.apache.log4j.Logger;
15
16 import org.dive4elements.artifacts.Artifact;
17 import org.dive4elements.artifacts.common.utils.DateUtils;
18
19 import org.dive4elements.river.model.BedHeightSingle;
20 import org.dive4elements.river.model.BedHeightSingleValue;
21 import org.dive4elements.river.model.TimeInterval;
22
23 import org.dive4elements.river.artifacts.access.BedHeightAccess;
24 import org.dive4elements.river.artifacts.model.Calculation;
25 import org.dive4elements.river.artifacts.model.CalculationResult;
26 import org.dive4elements.river.artifacts.model.minfo.MiddleBedHeightData;
27
28
29 public class MiddleBedHeightCalculation extends Calculation {
30
31 private static final Logger logger =
32 Logger.getLogger(MiddleBedHeightCalculation.class);
33
34
35 public CalculationResult calculate(BedHeightAccess access) {
36 logger.info("MiddleBedHeightCalculation.calculate");
37
38 int[] singleIds = access.getBedHeightSingleIDs();
39
40
41 if (logger.isDebugEnabled()) {
42 Artifact artifact = access.getArtifact();
43
44 logger.debug("Artifact '" + artifact.identifier() + "' contains:");
45 if (singleIds != null) {
46 logger.debug(" " + singleIds.length + " single bedheight ids");
47 }
48 }
49
50 List<BedHeightSingle> singles = getSingles(access, singleIds);
51
52 return buildCalculationResult(access, singles);
53 }
54
55
56 protected List<BedHeightSingle> getSingles(
57 BedHeightAccess access,
58 int[] ids
59 ) {
60 List<BedHeightSingle> singles = new ArrayList<BedHeightSingle>();
61
62 for (int id: ids) {
63 BedHeightSingle s = BedHeightSingle.getBedHeightSingleById(id);
64
65 if (s != null) {
66 singles.add(s);
67 }
68 else {
69 logger.warn("Cannot find Single by id: " + id);
70 // TODO ADD WARNING
71 }
72 }
73
74 return singles;
75 }
76
77
78 protected CalculationResult buildCalculationResult(
79 BedHeightAccess access,
80 List<BedHeightSingle> singles
81 ) {
82 logger.info("MiddleBedHeightCalculation.buildCalculationResult");
83
84 double kmLo = access.getLowerKM();
85 double kmHi = access.getUpperKM();
86
87 List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>();
88
89 for (BedHeightSingle single: singles) {
90 MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi);
91
92 if (d != null) {
93 data.add(d);
94 }
95 }
96
97 logger.debug("Calculation results in " + data.size() + " data objects.");
98
99 return new CalculationResult((MiddleBedHeightData[])
100 data.toArray(new MiddleBedHeightData[data.size()]), this);
101 }
102
103
104 protected MiddleBedHeightData prepareSingleData(
105 BedHeightSingle single,
106 double kmLo,
107 double kmHi
108 ) {
109 logger.debug("Prepare data for single: " + single.getDescription());
110
111 List<BedHeightSingleValue> values =
112 BedHeightSingleValue.getBedHeightSingleValues(single, kmLo, kmHi);
113
114 int year = single.getYear() != null ? single.getYear() : 0;
115
116 MiddleBedHeightData data = new MiddleBedHeightData(
117 year,
118 year,
119 single.getEvaluationBy(),
120 single.getDescription());
121
122 for (BedHeightSingleValue value: values) {
123 if (value.getHeight() != null) {
124 double uncert = value.getUncertainty() != null ?
125 value.getUncertainty().doubleValue() : Double.NaN;
126 double sounding = value.getSoundingWidth() != null ?
127 value.getSoundingWidth().doubleValue() : Double.NaN;
128 double gap = value.getDataGap() != null ?
129 value.getDataGap().doubleValue() : Double.NaN;
130 data.addAll(value.getStation().doubleValue(),
131 value.getHeight().doubleValue(),
132 uncert,
133 sounding,
134 gap,
135 value.getWidth().doubleValue(),
136 false);
137 }
138 else {
139 data.addAll(value.getStation().doubleValue(),
140 0,
141 0,
142 0,
143 0,
144 0,
145 true);
146 }
147 }
148
149 logger.debug("Single contains " + values.size() + " values");
150
151 return data;
152 }
153 }
154 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org