comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityCalculation.java @ 3318:dbe2f85bf160

merged flys-artifacts/2.8
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:35 +0200
parents 0f7abd95c6e2
children 048a02e29808
comparison
equal deleted inserted replaced
2987:98c7a46ec5ae 3318:dbe2f85bf160
1 package de.intevation.flys.artifacts.model;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 import de.intevation.artifacts.Artifact;
9 import de.intevation.flys.model.DischargeZone;
10 import de.intevation.flys.model.FlowVelocityModel;
11 import de.intevation.flys.model.FlowVelocityModelValue;
12 import de.intevation.flys.model.River;
13
14 import de.intevation.flys.artifacts.access.FlowVelocityAccess;
15 import de.intevation.flys.utils.FLYSUtils;
16
17
18 public class FlowVelocityCalculation extends Calculation {
19
20 private static final Logger logger =
21 Logger.getLogger(FlowVelocityCalculation.class);
22
23
24 public CalculationResult calculate(FlowVelocityAccess access) {
25 logger.info("FlowVelocityCalculation.calculate");
26
27 int[] mainIds = access.getMainChannels();
28 int[] totalIds = access.getTotalChannels();
29
30 if (logger.isDebugEnabled()) {
31 Artifact a = access.getArtifact();
32 logger.debug("Artifact '" + a.identifier() + "' contains:");
33 if (mainIds != null) {
34 logger.debug(" " + mainIds.length + " main channel ids");
35 }
36
37 if (totalIds != null) {
38 logger.debug(" " + totalIds.length + " total channel ids");
39 }
40 }
41
42 List<DischargeZone> zones = getDischargeZones(mainIds, totalIds);
43 List<FlowVelocityModel> models = getFlowVelocityModels(access, zones);
44
45 return buildCalculationResult(access, models);
46 }
47
48
49 protected List<DischargeZone> getDischargeZones(
50 int[] mainIds,
51 int[] totalIds
52 ) {
53 List<DischargeZone> zones = new ArrayList<DischargeZone>();
54
55 if (mainIds != null) {
56 for (int id: mainIds) {
57 DischargeZone zone = DischargeZone.getDischargeZoneById(id);
58
59 if (zone != null) {
60 zones.add(zone);
61 }
62 }
63 }
64
65 if (totalIds != null) {
66 for (int id: totalIds) {
67 DischargeZone zone = DischargeZone.getDischargeZoneById(id);
68
69 if (zone != null) {
70 zones.add(zone);
71 }
72 }
73 }
74
75 return zones;
76 }
77
78
79 protected List<FlowVelocityModel> getFlowVelocityModels(
80 FlowVelocityAccess access,
81 List<DischargeZone> zones
82 ) {
83 River river = FLYSUtils.getRiver(access.getArtifact());
84
85 List<FlowVelocityModel> models = new ArrayList<FlowVelocityModel>();
86
87 for (DischargeZone zone: zones) {
88 List<FlowVelocityModel> model =
89 FlowVelocityModel.getModels(river, zone);
90
91 if (model != null) {
92 models.addAll(model);
93 }
94 }
95
96 return models;
97 }
98
99
100 protected void prepareData(
101 FlowVelocityData data,
102 FlowVelocityModel model,
103 double kmLo,
104 double kmHi
105 ) {
106 List<FlowVelocityModelValue> values =
107 FlowVelocityModelValue.getValues(model, kmLo, kmHi);
108
109 logger.debug("Found " + values.size() + " values for model.");
110
111 for (FlowVelocityModelValue value: values) {
112 data.addKM(value.getStation().doubleValue());
113 data.addQ(value.getQ().doubleValue());
114 data.addVTotal(value.getTotalChannel().doubleValue());
115 data.addVMain(value.getMainChannel().doubleValue());
116 data.addTauMain(value.getShearStress().doubleValue());
117 }
118
119 DischargeZone zone = model.getDischargeZone();
120 String lo = zone.getLowerDischarge();
121 String hi = zone.getUpperDischarge();
122
123 if (lo.equals(hi)) {
124 data.setZone(lo);
125 }
126 else {
127 data.setZone(lo + " - " + hi);
128 }
129 }
130
131
132 protected CalculationResult buildCalculationResult(
133 FlowVelocityAccess access,
134 List<FlowVelocityModel> models
135 ) {
136 double kmLo = access.getLowerKM();
137 double kmHi = access.getUpperKM();
138
139 logger.debug("Prepare data for km range: " + kmLo + " - " + kmHi);
140
141 FlowVelocityData[] data = new FlowVelocityData[models.size()];
142
143 for (int i = 0, n = models.size(); i < n; i++) {
144 FlowVelocityData d = new FlowVelocityData();
145
146 prepareData(d, models.get(i), kmLo, kmHi);
147
148 data[i] = d;
149 }
150
151 logger.debug("Calculation contains " + data.length + " data items.");
152
153 return new CalculationResult(data, this);
154 }
155 }
156 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org