Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java @ 2793:6310b1582f2d
merged flys-artifacts/2.7
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:30 +0200 |
parents | 2f7fed1eb4bf |
children | 6e4ad35bcb11 |
comparison
equal
deleted
inserted
replaced
2548:ada02bbd3b7f | 2793:6310b1582f2d |
---|---|
1 package de.intevation.flys.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 de.intevation.artifactdatabase.state.Facet; | |
13 | |
14 import de.intevation.artifacts.Artifact; | |
15 import de.intevation.artifacts.ArtifactFactory; | |
16 import de.intevation.artifacts.CallMeta; | |
17 | |
18 | |
19 import de.intevation.flys.artifacts.StaticFLYSArtifact; | |
20 import de.intevation.flys.artifacts.model.FacetTypes; | |
21 import de.intevation.flys.artifacts.model.WQKms; | |
22 | |
23 import de.intevation.flys.artifacts.states.DefaultState; | |
24 | |
25 import de.intevation.flys.artifacts.model.Calculation; | |
26 import de.intevation.flys.artifacts.model.CalculationResult; | |
27 | |
28 import de.intevation.flys.artifacts.model.DischargeTables; | |
29 | |
30 import de.intevation.flys.model.Gauge; | |
31 import de.intevation.flys.model.River; | |
32 | |
33 import de.intevation.flys.utils.FLYSUtils; | |
34 | |
35 | |
36 /** | |
37 * Artifact to store user-added points. | |
38 */ | |
39 public class GaugeDischargeArtifact | |
40 extends WINFOArtifact | |
41 implements FacetTypes | |
42 { | |
43 /** The logger for this class. */ | |
44 private static Logger logger = Logger.getLogger(GaugeDischargeArtifact.class); | |
45 | |
46 /** The name of the artifact. */ | |
47 public static final String ARTIFACT_NAME = "gaugedischarge"; | |
48 | |
49 | |
50 /** | |
51 * Trivial Constructor. | |
52 */ | |
53 public GaugeDischargeArtifact() { | |
54 logger.debug("GaugeDischargeArtifact.HistoricalQArtifact()"); | |
55 } | |
56 | |
57 | |
58 /** | |
59 * Gets called from factory, to set things up. | |
60 * Especially, when loaded via datacage mechanisms, provide the | |
61 * data document. | |
62 * @param data filled with stuff from dc, if any. | |
63 */ | |
64 @Override | |
65 public void setup( | |
66 String identifier, | |
67 ArtifactFactory factory, | |
68 Object context, | |
69 CallMeta callMeta, | |
70 Document data) | |
71 { | |
72 logger.debug("GaugeDischargeArtifact.setup"); | |
73 super.setup(identifier, factory, context, callMeta, data); | |
74 String ids = StaticFLYSArtifact.getDatacageIDValue(data); | |
75 logger.debug("id for gaugedischarge: " + ids); | |
76 } | |
77 | |
78 | |
79 /** Return the name of this artifact. */ | |
80 public String getName() { | |
81 return ARTIFACT_NAME; | |
82 } | |
83 | |
84 | |
85 /** Access state data storing the jsonstring with points. | |
86 public String getPointsData(String facetName) { | |
87 return getDataAsString(facetName + ".data"); | |
88 }*/ | |
89 | |
90 | |
91 /** | |
92 * Setup state and facet, copy from master artifact. | |
93 */ | |
94 @Override | |
95 protected void initialize(Artifact art, Object context, CallMeta meta) { | |
96 logger.debug("GaugeDischargeArtifact.initialize"); | |
97 List<Facet> fs = new ArrayList<Facet>(); | |
98 FLYSArtifact artifact = (FLYSArtifact) art; | |
99 | |
100 // Get the location(s) | |
101 //importData(artifact, "ld_mode"); | |
102 //importData(artifact, "ld_from"); | |
103 //importData(artifact, "ld_to"); | |
104 //importData(artifact, "ld_locations"); | |
105 addStringData("ld_from", "0"); | |
106 addStringData("ld_to", "1000"); | |
107 addStringData("ld_mode", "distance"); | |
108 | |
109 | |
110 DefaultState state = (DefaultState) getCurrentState(context); | |
111 state.computeInit(this, hash(), context, meta, fs); | |
112 if (!fs.isEmpty()) { | |
113 logger.debug("Facets to add in GaugeDischargeArtifact.initialize. (" | |
114 + state.getID() + ")."); | |
115 facets.put(getCurrentStateId(), fs); | |
116 } | |
117 else { | |
118 logger.debug("No facets to add in GaugeDischargeArtifact.initialize (" | |
119 + state.getID() + ")."); | |
120 } | |
121 } | |
122 | |
123 | |
124 /** | |
125 * Determines Facets initial disposition regarding activity (think of | |
126 * selection in Client ThemeList GUI). This will be checked one time | |
127 * when the facet enters a collections describe document. | |
128 * | |
129 * @param facetName name of the facet. | |
130 * @param index index of the facet. | |
131 * @return 0 if not active | |
132 */ | |
133 @Override | |
134 public int getInitialFacetActivity( | |
135 String outputName, | |
136 String facetName, | |
137 int index) | |
138 { | |
139 return 1; | |
140 } | |
141 | |
142 | |
143 /** | |
144 * Returns the data that is used to create discharge curves. | |
145 * | |
146 */ | |
147 public CalculationResult getDischargeCurveData() { | |
148 | |
149 River river = FLYSUtils.getRiver(this); | |
150 if (river == null) { | |
151 return error(new WQKms[0], "no.river.selected"); | |
152 } | |
153 | |
154 double [] distance = FLYSUtils.getKmRange(this); | |
155 logger.debug("getDischargeCurveData: get range"); | |
156 | |
157 if (distance == null) { | |
158 return error(new WQKms[0], "no.range.found"); | |
159 } | |
160 | |
161 List<Gauge> gauges = river.determineGauges(distance[0], distance[1]); | |
162 logger.debug("getDischargeCurveData: get gauges"); | |
163 | |
164 if (gauges.isEmpty()) { | |
165 return error(new WQKms[0], "no.gauge.selected"); | |
166 } | |
167 | |
168 String [] names = new String[gauges.size()]; | |
169 | |
170 for (int i = 0; i < names.length; ++i) { | |
171 names[i] = gauges.get(i).getName(); | |
172 logger.debug("getDischargeCurveData: name " + names[i]); | |
173 } | |
174 | |
175 DischargeTables dt = new DischargeTables(river.getName(), names); | |
176 | |
177 Map<String, double [][]> map = dt.getValues(100d); | |
178 | |
179 ArrayList<WQKms> res = new ArrayList<WQKms>(); | |
180 | |
181 for (Gauge gauge: gauges) { | |
182 String name = gauge.getName(); | |
183 double [][] values = map.get(name); | |
184 if (values == null) { | |
185 continue; | |
186 } | |
187 double [] kms = new double[values[0].length]; | |
188 Arrays.fill(kms, gauge.getStation().doubleValue()); | |
189 res.add(new WQKms(kms, values[0], values[1], name)); | |
190 logger.debug("getDischargeCurveData: add one res gauge"); | |
191 } | |
192 | |
193 return new CalculationResult( | |
194 res.toArray(new WQKms[res.size()]), | |
195 new Calculation()); | |
196 } | |
197 | |
198 } | |
199 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |