Mercurial > dive4elements > river
changeset 2164:d548e2e13524
Added code for the simple case of "Bezugslinienverfahren" ("W auf freier Strecke").
flys-artifacts/trunk@3752 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 23 Jan 2012 16:55:42 +0000 (2012-01-23) |
parents | 105097966111 |
children | 637dd38d0e2f |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java |
diffstat | 4 files changed, 79 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Jan 23 14:18:53 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Jan 23 16:55:42 2012 +0000 @@ -1,3 +1,13 @@ +2012-01-23 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: + Added code for the simple case of "Bezugslinienverfahren" ("W auf freier Strecke"). + TODO: Handle case if the model returns more than one Q for a given W. + + * src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java, + src/main/java/de/intevation/flys/artifacts/states/WQSelect.java: + Micro optimizations. + 2012-01-23 Felix Wolfsteller <felix.wolfsteller@intevation.de> Fix flys/issue452 (Annotations at second y-axis).
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Mon Jan 23 14:18:53 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Mon Jan 23 16:55:42 2012 +0000 @@ -383,7 +383,7 @@ double refKm; - if (isFreeQ()) { + if (isFreeQ() || isFreeW()) { refKm = range[0]; logger.debug("'free' calculation (km " + refKm + ")"); } @@ -734,6 +734,32 @@ return null; } + if (isFreeW()) { + WstValueTable wst = WstValueTableFactory.getTable(r); + if (wst == null) { + logger.warn("no wst value table found"); + return null; + } + double km = range[0]; + + double [] outQs = new double[ws.length]; + + for (int i = 0; i < ws.length; ++i) { + double [] qs = wst.findQsForW(km, ws[i]); + if (qs.length < 1) { + logger.warn("no q found for w = " + ws[i]); + outQs[i] = Double.NaN; + } + if (qs.length > 1) { + // TODO: Generate more than w/q line! + logger.warn("more than one q found for w = " + ws[i]); + } + outQs[i] = qs[0]; + } + + return outQs; + } + if (debug) { logger.debug("range: " + Arrays.toString(range)); } @@ -939,6 +965,11 @@ return mode != null && mode.getValue().equals("Q"); } + public boolean isFreeW() { + StateData mode = getData("wq_mode"); + return mode != null && mode.getValue().equals("FREEW"); + } + /** * Returns true, if the parameter is set to compute data on a free range. @@ -954,11 +985,7 @@ logger.debug("isFreeQ: " + value); - if (value == null) { - return false; - } - - return Boolean.valueOf(value); + return value != null && Boolean.valueOf(value); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java Mon Jan 23 14:18:53 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java Mon Jan 23 16:55:42 2012 +0000 @@ -94,10 +94,9 @@ CallMeta meta = context.getMeta(); Element[] calcs = new Element[CALCULATIONS.length]; - int i = 0; - - for (String calc: CALCULATIONS) { - calcs[i++] = createItem( + for (int i = 0; i < CALCULATIONS.length; ++i) { + String calc = CALCULATIONS[i]; + calcs[i] = createItem( cr, new String[] { Resources.getMsg(meta, calc, calc), calc
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Mon Jan 23 14:18:53 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Mon Jan 23 16:55:42 2012 +0000 @@ -102,7 +102,7 @@ Element itemElement = creator.create("item"); creator.addAttr(itemElement, "value", value, true); - String label = ""; + String label; if (mode == null || mode.equals("W") || Boolean.valueOf(free)) { label = getLabel(winfo, cc, value); @@ -125,25 +125,33 @@ String raw ) { String[] values = raw.split(" "); - String label = null; + + if (values.length < 1) { + return null; + } + + StringBuilder label = new StringBuilder(); NumberFormat nf = NumberFormat.getInstance( Resources.getLocale(cc.getMeta())); for (String value: values) { try { - double v = Double.valueOf(value.trim()); + double v = Double.parseDouble(value.trim()); String formatted = nf.format(v); - label = label != null ? label + ";" + formatted : formatted; + if (label.length() > 0) { + label.append(';'); + } + label.append(formatted); } catch (NumberFormatException nfe) { // do nothing here } } - return label; + return label.toString(); } @@ -153,34 +161,44 @@ String raw ) { String[] values = raw.split(" "); - String label = null; + + if (values.length < 1) { + return null; + } NumberFormat nf = NumberFormat.getInstance( Resources.getLocale(cc.getMeta())); + Gauge gauge = winfo.getGauge(); + + boolean debug = logger.isDebugEnabled(); + + StringBuilder label = new StringBuilder(); + for (String value: values) { try { - double v = Double.valueOf(value.trim()); + double v = Double.parseDouble(value.trim()); String tmp = nf.format(v); - String mv = FLYSUtils.getNamedMainValue(winfo.getGauge(),v); + String mv = FLYSUtils.getNamedMainValue(gauge, v); if (mv != null && mv.length() > 0) { - String add = mv + ": " + tmp; - logger.debug("Add main value: '" + mv + "'"); - label = label != null ? label + ";" + add : add; + tmp = mv + ": " + tmp; + if (debug) { + logger.debug("Add main value: '" + mv + "'"); + } } - else { - logger.debug("Add non main value: '" + tmp + "'"); - label = label != null ? label + ";" + tmp : tmp; + if (label.length() > 0) { + label.append(';'); } + label.append(tmp); } catch (NumberFormatException nfe) { // do nothing here } } - return label; + return label.toString(); }