Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/GaugeDischargeArtifact.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/GaugeDischargeArtifact.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.artifacts; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.Arrays; | |
5 import java.util.List; | |
6 import java.util.Map; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 import org.w3c.dom.Document; | |
11 | |
12 import org.dive4elements.artifactdatabase.state.Facet; | |
13 | |
14 import org.dive4elements.artifacts.Artifact; | |
15 import org.dive4elements.artifacts.ArtifactFactory; | |
16 import org.dive4elements.artifacts.CallMeta; | |
17 | |
18 import org.dive4elements.river.artifacts.model.FacetTypes; | |
19 import org.dive4elements.river.artifacts.model.WQKms; | |
20 | |
21 import org.dive4elements.river.artifacts.states.DefaultState; | |
22 | |
23 import org.dive4elements.river.artifacts.model.Calculation; | |
24 import org.dive4elements.river.artifacts.model.CalculationResult; | |
25 | |
26 import org.dive4elements.river.artifacts.model.DischargeTables; | |
27 | |
28 import org.dive4elements.river.model.Gauge; | |
29 import org.dive4elements.river.model.River; | |
30 | |
31 import org.dive4elements.river.utils.FLYSUtils; | |
32 | |
33 | |
34 /** | |
35 * Artifact to get discharge curves at gauges. | |
36 */ | |
37 public class GaugeDischargeArtifact | |
38 extends WINFOArtifact | |
39 implements FacetTypes | |
40 { | |
41 /** The logger for this class. */ | |
42 private static Logger logger = Logger.getLogger(GaugeDischargeArtifact.class); | |
43 | |
44 /** The name of the artifact. */ | |
45 public static final String ARTIFACT_NAME = "gaugedischarge"; | |
46 | |
47 | |
48 /** | |
49 * Trivial Constructor. | |
50 */ | |
51 public GaugeDischargeArtifact() { | |
52 logger.debug("GaugeDischargeArtifact.GaugeDischargeArtifact()"); | |
53 } | |
54 | |
55 | |
56 /** | |
57 * Gets called from factory, to set things up. | |
58 * Especially, when loaded via datacage mechanisms, provide the | |
59 * data document. | |
60 * @param data filled with stuff from dc, if any. | |
61 */ | |
62 @Override | |
63 public void setup( | |
64 String identifier, | |
65 ArtifactFactory factory, | |
66 Object context, | |
67 CallMeta callMeta, | |
68 Document data) | |
69 { | |
70 logger.debug("GaugeDischargeArtifact.setup"); | |
71 String ids = StaticFLYSArtifact.getDatacageIDValue(data); | |
72 addStringData("ids", ids); | |
73 logger.debug("id for gaugedischarge: " + ids); | |
74 super.setup(identifier, factory, context, callMeta, data); | |
75 } | |
76 | |
77 | |
78 /** Return the name of this artifact. */ | |
79 public String getName() { | |
80 return ARTIFACT_NAME; | |
81 } | |
82 | |
83 | |
84 /** | |
85 * Setup state and facet, copy from master artifact. | |
86 */ | |
87 @Override | |
88 protected void initialize(Artifact art, Object context, CallMeta meta) { | |
89 logger.debug("GaugeDischargeArtifact.initialize"); | |
90 List<Facet> fs = new ArrayList<Facet>(); | |
91 FLYSArtifact artifact = (FLYSArtifact) art; | |
92 importData(artifact, "river"); | |
93 | |
94 // Get the location(s) | |
95 //importData(artifact, "ld_mode", ld_from, ld_to, ld_locations | |
96 addStringData("ld_from", "0"); | |
97 addStringData("ld_to", "1000"); | |
98 addStringData("ld_mode", "distance"); | |
99 | |
100 DefaultState state = (DefaultState) getCurrentState(context); | |
101 state.computeInit(this, hash(), context, meta, fs); | |
102 if (!fs.isEmpty()) { | |
103 logger.debug("Facets to add in GaugeDischargeArtifact.initialize. (" | |
104 + state.getID() + "/ " + getCurrentStateId() + ")."); | |
105 addFacets(getCurrentStateId(), fs); | |
106 } | |
107 else { | |
108 logger.debug("No facets to add in GaugeDischargeArtifact.initialize (" | |
109 + state.getID() + "/ "+getCurrentStateId()+")."); | |
110 } | |
111 } | |
112 | |
113 | |
114 /** Get the Gauges name which came with datacage data-document. */ | |
115 public String getGaugeName() { | |
116 return this.getDataAsString("ids"); | |
117 } | |
118 | |
119 | |
120 /** Get the Gauges which came with datacage data-document. */ | |
121 public Gauge getGauge() { | |
122 River river = FLYSUtils.getRiver(this); | |
123 return river.determineGaugeByName(getGaugeName()); | |
124 } | |
125 | |
126 | |
127 /** | |
128 * Returns the data that is used to create discharge curves. | |
129 * @return CalculationResult with WQKms. | |
130 */ | |
131 public CalculationResult getDischargeCurveData() { | |
132 | |
133 River river = FLYSUtils.getRiver(this); | |
134 if (river == null) { | |
135 return error(new WQKms[0], "no.river.selected"); | |
136 } | |
137 /* | |
138 // This one would allow to automatically pick the right Gauge. | |
139 double [] distance = FLYSUtils.getKmRange(this); | |
140 logger.debug("getDischargeCurveData: get range"); | |
141 | |
142 if (distance == null) { | |
143 return error(new WQKms[0], "no.range.found"); | |
144 } | |
145 | |
146 List<Gauge> gauges = river.determineGauges(distance[0], distance[1]); | |
147 logger.debug("getDischargeCurveData: got " + gauges.size() + " gauges"); | |
148 | |
149 if (gauges.isEmpty()) { | |
150 return error(new WQKms[0], "no.gauge.selected"); | |
151 } | |
152 | |
153 String [] names = new String[gauges.size()]; | |
154 | |
155 for (int i = 0; i < names.length; ++i) { | |
156 names[i] = gauges.get(i).getName(); | |
157 logger.debug("getDischargeCurveData: name " + names[i]); | |
158 } | |
159 */ | |
160 | |
161 DischargeTables dt = new DischargeTables(river.getName(), getDataAsString("ids")); | |
162 | |
163 Map<String, double [][]> map = dt.getValues(100); | |
164 | |
165 ArrayList<WQKms> res = new ArrayList<WQKms>(); | |
166 | |
167 Gauge gauge = river.determineGaugeByName(this.getDataAsString("ids")); | |
168 | |
169 String name = getGaugeName(); | |
170 double [][] values = map.get(name); | |
171 if (values == null) { | |
172 logger.error("No values for this gauge / discharge found."); | |
173 return error(new WQKms[0], "no.gauge.found"); | |
174 } | |
175 for (int i = 0 ; i < values[0].length; i++) { | |
176 values[0][i] += gauge.getDatum().doubleValue(); | |
177 } | |
178 double [] kms = new double[values[0].length]; | |
179 Arrays.fill(kms, gauge.getStation().doubleValue()); | |
180 res.add(new WQKms(kms, values[0], values[1], name)); | |
181 | |
182 return new CalculationResult( | |
183 res.toArray(new WQKms[res.size()]), | |
184 new Calculation()); | |
185 } | |
186 } | |
187 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |