Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java @ 3051:49727e9dcfde
Polished Gauge Discharges in computed discharge curves.
flys-artifacts/trunk@4625 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 07 Jun 2012 20:47:17 +0000 |
parents | 6e4ad35bcb11 |
children | 5642a83420f2 |
comparison
equal
deleted
inserted
replaced
3050:02254d763bc0 | 3051:49727e9dcfde |
---|---|
67 Object context, | 67 Object context, |
68 CallMeta callMeta, | 68 CallMeta callMeta, |
69 Document data) | 69 Document data) |
70 { | 70 { |
71 logger.debug("GaugeDischargeArtifact.setup"); | 71 logger.debug("GaugeDischargeArtifact.setup"); |
72 String ids = StaticFLYSArtifact.getDatacageIDValue(data); | |
73 addStringData("ids", ids); | |
74 logger.debug("id for gaugedischarge: " + ids); | |
72 super.setup(identifier, factory, context, callMeta, data); | 75 super.setup(identifier, factory, context, callMeta, data); |
73 String ids = StaticFLYSArtifact.getDatacageIDValue(data); | |
74 logger.debug("id for gaugedischarge: " + ids); | |
75 } | 76 } |
76 | 77 |
77 | 78 |
78 /** Return the name of this artifact. */ | 79 /** Return the name of this artifact. */ |
79 public String getName() { | 80 public String getName() { |
80 return ARTIFACT_NAME; | 81 return ARTIFACT_NAME; |
81 } | 82 } |
82 | |
83 | |
84 /** Access state data storing the jsonstring with points. | |
85 public String getPointsData(String facetName) { | |
86 return getDataAsString(facetName + ".data"); | |
87 }*/ | |
88 | 83 |
89 | 84 |
90 /** | 85 /** |
91 * Setup state and facet, copy from master artifact. | 86 * Setup state and facet, copy from master artifact. |
92 */ | 87 */ |
96 List<Facet> fs = new ArrayList<Facet>(); | 91 List<Facet> fs = new ArrayList<Facet>(); |
97 FLYSArtifact artifact = (FLYSArtifact) art; | 92 FLYSArtifact artifact = (FLYSArtifact) art; |
98 importData(artifact, "river"); | 93 importData(artifact, "river"); |
99 | 94 |
100 // Get the location(s) | 95 // Get the location(s) |
101 //importData(artifact, "ld_mode"); | 96 //importData(artifact, "ld_mode", ld_from, ld_to, ld_locations |
102 //importData(artifact, "ld_from"); | |
103 //importData(artifact, "ld_to"); | |
104 //importData(artifact, "ld_locations"); | |
105 addStringData("ld_from", "0"); | 97 addStringData("ld_from", "0"); |
106 addStringData("ld_to", "1000"); | 98 addStringData("ld_to", "1000"); |
107 addStringData("ld_mode", "distance"); | 99 addStringData("ld_mode", "distance"); |
108 | 100 |
109 DefaultState state = (DefaultState) getCurrentState(context); | 101 DefaultState state = (DefaultState) getCurrentState(context); |
118 + state.getID() + "/ "+getCurrentStateId()+")."); | 110 + state.getID() + "/ "+getCurrentStateId()+")."); |
119 } | 111 } |
120 } | 112 } |
121 | 113 |
122 | 114 |
115 /** Get the Gauges name which came with datacage data-document. */ | |
116 public String getGaugeName() { | |
117 return this.getDataAsString("ids"); | |
118 } | |
119 | |
120 | |
121 /** Get the Gauges which came with datacage data-document. */ | |
122 public Gauge getGauge() { | |
123 River river = FLYSUtils.getRiver(this); | |
124 return river.determineGaugeByName(getGaugeName()); | |
125 } | |
126 | |
127 | |
128 /** | |
129 * Returns the data that is used to create discharge curves. | |
130 * @return CalculationResult with WQKms. | |
131 */ | |
132 public CalculationResult getDischargeCurveData() { | |
133 | |
134 River river = FLYSUtils.getRiver(this); | |
135 if (river == null) { | |
136 return error(new WQKms[0], "no.river.selected"); | |
137 } | |
138 /* | |
139 // This one would allow to automatically pick the right Gauge. | |
140 double [] distance = FLYSUtils.getKmRange(this); | |
141 logger.debug("getDischargeCurveData: get range"); | |
142 | |
143 if (distance == null) { | |
144 return error(new WQKms[0], "no.range.found"); | |
145 } | |
146 | |
147 List<Gauge> gauges = river.determineGauges(distance[0], distance[1]); | |
148 logger.debug("getDischargeCurveData: got " + gauges.size() + " gauges"); | |
149 | |
150 if (gauges.isEmpty()) { | |
151 return error(new WQKms[0], "no.gauge.selected"); | |
152 } | |
153 | |
154 String [] names = new String[gauges.size()]; | |
155 | |
156 for (int i = 0; i < names.length; ++i) { | |
157 names[i] = gauges.get(i).getName(); | |
158 logger.debug("getDischargeCurveData: name " + names[i]); | |
159 } | |
160 */ | |
161 | |
162 DischargeTables dt = new DischargeTables(river.getName(), getDataAsString("ids")); | |
163 | |
164 Map<String, double [][]> map = dt.getValues(100); | |
165 | |
166 ArrayList<WQKms> res = new ArrayList<WQKms>(); | |
167 | |
168 Gauge gauge = river.determineGaugeByName(this.getDataAsString("ids")); | |
169 | |
170 String name = getGaugeName(); | |
171 double [][] values = map.get(name); | |
172 if (values == null) { | |
173 logger.error("No values for this gauge / discharge 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 | |
123 /** | 188 /** |
124 * Determines Facets initial disposition regarding activity (think of | 189 * Determines Facets initial disposition regarding activity (think of |
125 * selection in Client ThemeList GUI). This will be checked one time | 190 * selection in Client ThemeList GUI). This will be checked one time |
126 * when the facet enters a collections describe document. | 191 * when the facet enters a collections describe document. |
127 * | 192 * |
128 * @param facetName name of the facet. | 193 * @param facetName name of the facet. |
129 * @param index index of the facet. | 194 * @param index index of the facet. |
130 * @return 0 if not active | 195 * @return 1 - all Facets enter activated. |
131 */ | 196 */ |
132 @Override | 197 @Override |
133 public int getInitialFacetActivity( | 198 public int getInitialFacetActivity( |
134 String outputName, | 199 String outputName, |
135 String facetName, | 200 String facetName, |
136 int index) | 201 int index) |
137 { | 202 { |
138 return 1; | 203 return 1; |
139 } | 204 } |
140 | |
141 | |
142 /** | |
143 * Returns the data that is used to create discharge curves. | |
144 * | |
145 */ | |
146 public CalculationResult getDischargeCurveData() { | |
147 | |
148 River river = FLYSUtils.getRiver(this); | |
149 if (river == null) { | |
150 return error(new WQKms[0], "no.river.selected"); | |
151 } | |
152 | |
153 double [] distance = FLYSUtils.getKmRange(this); | |
154 logger.debug("getDischargeCurveData: get range"); | |
155 | |
156 if (distance == null) { | |
157 return error(new WQKms[0], "no.range.found"); | |
158 } | |
159 | |
160 List<Gauge> gauges = river.determineGauges(distance[0], distance[1]); | |
161 logger.debug("getDischargeCurveData: get gauges"); | |
162 | |
163 if (gauges.isEmpty()) { | |
164 return error(new WQKms[0], "no.gauge.selected"); | |
165 } | |
166 | |
167 String [] names = new String[gauges.size()]; | |
168 | |
169 for (int i = 0; i < names.length; ++i) { | |
170 names[i] = gauges.get(i).getName(); | |
171 logger.debug("getDischargeCurveData: name " + names[i]); | |
172 } | |
173 | |
174 DischargeTables dt = new DischargeTables(river.getName(), names); | |
175 | |
176 Map<String, double [][]> map = dt.getValues(100d); | |
177 | |
178 ArrayList<WQKms> res = new ArrayList<WQKms>(); | |
179 | |
180 for (Gauge gauge: gauges) { | |
181 String name = gauge.getName(); | |
182 double [][] values = map.get(name); | |
183 if (values == null) { | |
184 continue; | |
185 } | |
186 double [] kms = new double[values[0].length]; | |
187 Arrays.fill(kms, gauge.getStation().doubleValue()); | |
188 res.add(new WQKms(kms, values[0], values[1], name)); | |
189 logger.debug("getDischargeCurveData: add one res gauge"); | |
190 } | |
191 | |
192 return new CalculationResult( | |
193 res.toArray(new WQKms[res.size()]), | |
194 new Calculation()); | |
195 } | |
196 | |
197 } | 205 } |
198 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 206 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |