comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightCalculation.java @ 3230:b888c5eb65b3

Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact. flys-artifacts/trunk@4859 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 03 Jul 2012 12:13:36 +0000
parents 250a370c377d
children cdbc457e23e2
comparison
equal deleted inserted replaced
3229:ad9640211db3 3230:b888c5eb65b3
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
5 5
6 import org.apache.log4j.Logger; 6 import org.apache.log4j.Logger;
7 7
8 import de.intevation.artifacts.Artifact;
8 import de.intevation.artifacts.common.utils.DateUtils; 9 import de.intevation.artifacts.common.utils.DateUtils;
9 10
10 import de.intevation.flys.model.BedHeightEpoch; 11 import de.intevation.flys.model.BedHeightEpoch;
11 import de.intevation.flys.model.BedHeightEpochValue; 12 import de.intevation.flys.model.BedHeightEpochValue;
12 import de.intevation.flys.model.BedHeightSingle; 13 import de.intevation.flys.model.BedHeightSingle;
13 import de.intevation.flys.model.BedHeightSingleValue; 14 import de.intevation.flys.model.BedHeightSingleValue;
14 import de.intevation.flys.model.TimeInterval; 15 import de.intevation.flys.model.TimeInterval;
15 16
16 import de.intevation.flys.artifacts.MINFOArtifact; 17 import de.intevation.flys.artifacts.access.BedHeightAccess;
17 import de.intevation.flys.artifacts.model.MiddleBedHeightData; 18 import de.intevation.flys.artifacts.model.MiddleBedHeightData;
18 19
19 20
20 public class MiddleBedHeightCalculation extends Calculation { 21 public class MiddleBedHeightCalculation extends Calculation {
21 22
22 private static final Logger logger = 23 private static final Logger logger =
23 Logger.getLogger(MiddleBedHeightCalculation.class); 24 Logger.getLogger(MiddleBedHeightCalculation.class);
24 25
25 26
26 public CalculationResult calculate(MINFOArtifact artifact) { 27 public CalculationResult calculate(BedHeightAccess access) {
27 logger.info("MiddleBedHeightCalculation.calculate"); 28 logger.info("MiddleBedHeightCalculation.calculate");
28 29
29 int[] singleIds = artifact.getBedHeightSingleIDs(); 30 int[] singleIds = access.getBedHeightSingleIDs();
30 int[] epochIds = artifact.getBedHeightEpochIDs(); 31 int[] epochIds = access.getBedHeightEpochIDs();
32
31 33
32 if (logger.isDebugEnabled()) { 34 if (logger.isDebugEnabled()) {
35 Artifact artifact = access.getArtifact();
36
33 logger.debug("Artifact '" + artifact.identifier() + "' contains:"); 37 logger.debug("Artifact '" + artifact.identifier() + "' contains:");
34 if (singleIds != null) { 38 if (singleIds != null) {
35 logger.debug(" " + singleIds.length + " single bedheight ids"); 39 logger.debug(" " + singleIds.length + " single bedheight ids");
36 } 40 }
37 41
38 if (epochIds != null) { 42 if (epochIds != null) {
39 logger.debug(" " + epochIds.length + " epoch bedheight ids"); 43 logger.debug(" " + epochIds.length + " epoch bedheight ids");
40 } 44 }
41 } 45 }
42 46
43 List<BedHeightSingle> singles = getSingles(artifact, singleIds); 47 List<BedHeightSingle> singles = getSingles(access, singleIds);
44 List<BedHeightEpoch> epochs = getEpochs(artifact, epochIds); 48 List<BedHeightEpoch> epochs = getEpochs(access, epochIds);
45 49
46 return buildCalculationResult(artifact, singles, epochs); 50 return buildCalculationResult(access, singles, epochs);
47 } 51 }
48 52
49 53
50 protected List<BedHeightSingle> getSingles(MINFOArtifact minfo, int[] ids) { 54 protected List<BedHeightSingle> getSingles(
55 BedHeightAccess access,
56 int[] ids
57 ) {
51 List<BedHeightSingle> singles = new ArrayList<BedHeightSingle>(); 58 List<BedHeightSingle> singles = new ArrayList<BedHeightSingle>();
52 59
53 for (int id: ids) { 60 for (int id: ids) {
54 BedHeightSingle s = BedHeightSingle.getBedHeightSingleById(id); 61 BedHeightSingle s = BedHeightSingle.getBedHeightSingleById(id);
55 62
64 71
65 return singles; 72 return singles;
66 } 73 }
67 74
68 75
69 protected List<BedHeightEpoch> getEpochs(MINFOArtifact minfo, int[] ids) { 76 protected List<BedHeightEpoch> getEpochs(
77 BedHeightAccess access,
78 int[] ids
79 ) {
70 List<BedHeightEpoch> epochs = new ArrayList<BedHeightEpoch>(); 80 List<BedHeightEpoch> epochs = new ArrayList<BedHeightEpoch>();
71 81
72 for (int id: ids) { 82 for (int id: ids) {
73 BedHeightEpoch e = BedHeightEpoch.getBedHeightEpochById(id); 83 BedHeightEpoch e = BedHeightEpoch.getBedHeightEpochById(id);
74 84
84 return epochs; 94 return epochs;
85 } 95 }
86 96
87 97
88 protected CalculationResult buildCalculationResult( 98 protected CalculationResult buildCalculationResult(
89 MINFOArtifact artifact, 99 BedHeightAccess access,
90 List<BedHeightSingle> singles, 100 List<BedHeightSingle> singles,
91 List<BedHeightEpoch> epochs 101 List<BedHeightEpoch> epochs
92 ) { 102 ) {
93 logger.info("MiddleBedHeightCalculation.buildCalculationResult"); 103 logger.info("MiddleBedHeightCalculation.buildCalculationResult");
94 104
95 int size = singles.size() + epochs.size(); 105 double kmLo = access.getLowerKM();
96 double kmLo = artifact.getDataAsDouble("ld_from"); 106 double kmHi = access.getUpperKM();
97 double kmHi = artifact.getDataAsDouble("ld_to");
98 107
99 List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>(); 108 List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>();
100 109
101 for (BedHeightSingle single: singles) { 110 for (BedHeightSingle single: singles) {
102 MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi); 111 MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi);

http://dive4elements.wald.intevation.org