comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityCalculation.java @ 2702:4c00cf83fff1

Added state, calculation and csv exporter for MINFO flow velociy calculation. flys-artifacts/trunk@4418 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 16 May 2012 08:37:27 +0000
parents
children b888c5eb65b3
comparison
equal deleted inserted replaced
2701:c553d4fa3957 2702:4c00cf83fff1
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.flys.model.DischargeZone;
9 import de.intevation.flys.model.FlowVelocityModel;
10 import de.intevation.flys.model.FlowVelocityModelValue;
11 import de.intevation.flys.model.River;
12
13 import de.intevation.flys.artifacts.MINFOArtifact;
14 import de.intevation.flys.artifacts.model.FlowVelocityData;
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(MINFOArtifact artifact) {
25 logger.info("FlowVelocityCalculation.calculate");
26
27 int[] mainIds = artifact.getMainChannels();
28 int[] totalIds = artifact.getTotalChannels();
29
30 if (logger.isDebugEnabled()) {
31 logger.debug("Artifact '" + artifact.identifier() + "' contains:");
32 if (mainIds != null) {
33 logger.debug(" " + mainIds.length + " main channel ids");
34 }
35
36 if (totalIds != null) {
37 logger.debug(" " + totalIds.length + " total channel ids");
38 }
39 }
40
41 List<DischargeZone> zones = getDischargeZones(mainIds, totalIds);
42 List<FlowVelocityModel> models = getFlowVelocityModels(artifact, zones);
43
44 return buildCalculationResult(artifact, models);
45 }
46
47
48 protected List<DischargeZone> getDischargeZones(
49 int[] mainIds,
50 int[] totalIds
51 ) {
52 List<DischargeZone> zones = new ArrayList<DischargeZone>();
53
54 if (mainIds != null) {
55 for (int id: mainIds) {
56 DischargeZone zone = DischargeZone.getDischargeZoneById(id);
57
58 if (zone != null) {
59 zones.add(zone);
60 }
61 }
62 }
63
64 if (totalIds != null) {
65 for (int id: totalIds) {
66 DischargeZone zone = DischargeZone.getDischargeZoneById(id);
67
68 if (zone != null) {
69 zones.add(zone);
70 }
71 }
72 }
73
74 return zones;
75 }
76
77
78 protected List<FlowVelocityModel> getFlowVelocityModels(
79 MINFOArtifact artifact,
80 List<DischargeZone> zones
81 ) {
82 River river = FLYSUtils.getRiver(artifact);
83
84 List<FlowVelocityModel> models = new ArrayList<FlowVelocityModel>();
85
86 for (DischargeZone zone: zones) {
87 List<FlowVelocityModel> model =
88 FlowVelocityModel.getModels(river, zone);
89
90 if (model != null) {
91 models.addAll(model);
92 }
93 }
94
95 return models;
96 }
97
98
99 protected void prepareData(
100 FlowVelocityData data,
101 FlowVelocityModel model,
102 double kmLo,
103 double kmHi
104 ) {
105 List<FlowVelocityModelValue> values =
106 FlowVelocityModelValue.getValues(model, kmLo, kmHi);
107
108 logger.debug("Found " + values.size() + " values for model.");
109
110 for (FlowVelocityModelValue value: values) {
111 data.addKM(value.getStation().doubleValue());
112 data.addQ(value.getQ().doubleValue());
113 data.addVTotal(value.getTotalChannel().doubleValue());
114 data.addVMain(value.getMainChannel().doubleValue());
115 data.addTauMain(value.getShearStress().doubleValue());
116 }
117
118 DischargeZone zone = model.getDischargeZone();
119 String lo = zone.getLowerDischarge();
120 String hi = zone.getUpperDischarge();
121
122 if (lo.equals(hi)) {
123 data.setZone(lo);
124 }
125 else {
126 data.setZone(lo + " - " + hi);
127 }
128 }
129
130
131 protected CalculationResult buildCalculationResult(
132 MINFOArtifact artifact,
133 List<FlowVelocityModel> models
134 ) {
135 double kmLo = artifact.getDataAsDouble("ld_from");
136 double kmHi = artifact.getDataAsDouble("ld_to");
137
138 logger.debug("Prepare data for km range: " + kmLo + " - " + kmHi);
139
140 FlowVelocityData[] data = new FlowVelocityData[models.size()];
141
142 for (int i = 0, n = models.size(); i < n; i++) {
143 FlowVelocityData d = new FlowVelocityData();
144
145 prepareData(d, models.get(i), kmLo, kmHi);
146
147 data[i] = d;
148 }
149
150 logger.debug("Calculation contains " + data.length + " data items.");
151
152 return new CalculationResult(data, this);
153 }
154 }
155 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org