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