comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/MiddleBedHeightCalculation.java @ 8559:6d8d7425a6b5

Bed heights are just bed heights since a while ('single' is obsolete).
author "Tom Gottfried <tom@intevation.de>"
date Mon, 16 Feb 2015 11:08:33 +0100
parents 3a0522f1a532
children 6fcf4717605f
comparison
equal deleted inserted replaced
8558:d0ea092a32f5 8559:6d8d7425a6b5
12 import java.util.List; 12 import java.util.List;
13 13
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.river.model.BedHeightSingle; 17 import org.dive4elements.river.model.BedHeight;
18 import org.dive4elements.river.model.BedHeightSingleValue; 18 import org.dive4elements.river.model.BedHeightValue;
19 import org.dive4elements.river.artifacts.access.BedHeightAccess; 19 import org.dive4elements.river.artifacts.access.BedHeightAccess;
20 import org.dive4elements.river.artifacts.model.Calculation; 20 import org.dive4elements.river.artifacts.model.Calculation;
21 import org.dive4elements.river.artifacts.model.CalculationResult; 21 import org.dive4elements.river.artifacts.model.CalculationResult;
22 22
23 23
28 28
29 29
30 public CalculationResult calculate(BedHeightAccess access) { 30 public CalculationResult calculate(BedHeightAccess access) {
31 log.info("MiddleBedHeightCalculation.calculate"); 31 log.info("MiddleBedHeightCalculation.calculate");
32 32
33 int[] singleIds = access.getBedHeightSingleIDs(); 33 int[] singleIds = access.getBedHeightIDs();
34 34
35 35
36 if (log.isDebugEnabled()) { 36 if (log.isDebugEnabled()) {
37 Artifact artifact = access.getArtifact(); 37 Artifact artifact = access.getArtifact();
38 38
40 if (singleIds != null) { 40 if (singleIds != null) {
41 log.debug(" " + singleIds.length + " single bedheight ids"); 41 log.debug(" " + singleIds.length + " single bedheight ids");
42 } 42 }
43 } 43 }
44 44
45 List<BedHeightSingle> singles = getSingles(access, singleIds); 45 List<BedHeight> singles = getSingles(access, singleIds);
46 46
47 return buildCalculationResult(access, singles); 47 return buildCalculationResult(access, singles);
48 } 48 }
49 49
50 50
51 protected List<BedHeightSingle> getSingles( 51 protected List<BedHeight> getSingles(
52 BedHeightAccess access, 52 BedHeightAccess access,
53 int[] ids 53 int[] ids
54 ) { 54 ) {
55 List<BedHeightSingle> singles = new ArrayList<BedHeightSingle>(); 55 List<BedHeight> singles = new ArrayList<BedHeight>();
56 56
57 for (int id: ids) { 57 for (int id: ids) {
58 BedHeightSingle s = BedHeightSingle.getBedHeightSingleById(id); 58 BedHeight s = BedHeight.getBedHeightById(id);
59 59
60 if (s != null) { 60 if (s != null) {
61 singles.add(s); 61 singles.add(s);
62 } 62 }
63 else { 63 else {
70 } 70 }
71 71
72 72
73 protected CalculationResult buildCalculationResult( 73 protected CalculationResult buildCalculationResult(
74 BedHeightAccess access, 74 BedHeightAccess access,
75 List<BedHeightSingle> singles 75 List<BedHeight> singles
76 ) { 76 ) {
77 log.info("MiddleBedHeightCalculation.buildCalculationResult"); 77 log.info("MiddleBedHeightCalculation.buildCalculationResult");
78 78
79 double kmLo = access.getLowerKM(); 79 double kmLo = access.getLowerKM();
80 double kmHi = access.getUpperKM(); 80 double kmHi = access.getUpperKM();
81 81
82 List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>(); 82 List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>();
83 83
84 for (BedHeightSingle single: singles) { 84 for (BedHeight single: singles) {
85 MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi); 85 MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi);
86 86
87 if (d != null) { 87 if (d != null) {
88 data.add(d); 88 data.add(d);
89 } 89 }
95 data.toArray(new MiddleBedHeightData[data.size()]), this); 95 data.toArray(new MiddleBedHeightData[data.size()]), this);
96 } 96 }
97 97
98 98
99 protected MiddleBedHeightData prepareSingleData( 99 protected MiddleBedHeightData prepareSingleData(
100 BedHeightSingle single, 100 BedHeight single,
101 double kmLo, 101 double kmLo,
102 double kmHi 102 double kmHi
103 ) { 103 ) {
104 log.debug("Prepare data for single: " + single.getDescription()); 104 log.debug("Prepare data for single: " + single.getDescription());
105 105
106 List<BedHeightSingleValue> values = 106 List<BedHeightValue> values =
107 BedHeightSingleValue.getBedHeightSingleValues(single, kmLo, kmHi); 107 BedHeightValue.getBedHeightValues(single, kmLo, kmHi);
108 108
109 int year = single.getYear() != null ? single.getYear() : 0; 109 int year = single.getYear() != null ? single.getYear() : 0;
110 110
111 String curElevModel = single.getCurElevationModel() != null ? 111 String curElevModel = single.getCurElevationModel() != null ?
112 single.getCurElevationModel().getName() : ""; 112 single.getCurElevationModel().getName() : "";
128 riverElevModel, 128 riverElevModel,
129 type, 129 type,
130 locationSystem, 130 locationSystem,
131 single.getSoundingWidth()); 131 single.getSoundingWidth());
132 132
133 for (BedHeightSingleValue value: values) { 133 for (BedHeightValue value: values) {
134 if (value.getHeight() != null) { 134 if (value.getHeight() != null) {
135 double uncert = value.getUncertainty() != null ? 135 double uncert = value.getUncertainty() != null ?
136 value.getUncertainty().doubleValue() : Double.NaN; 136 value.getUncertainty().doubleValue() : Double.NaN;
137 double sounding = value.getSoundingWidth() != null ? 137 double sounding = value.getSoundingWidth() != null ?
138 value.getSoundingWidth().doubleValue() : Double.NaN; 138 value.getSoundingWidth().doubleValue() : Double.NaN;

http://dive4elements.wald.intevation.org