Mercurial > dive4elements > river
changeset 1740:8d08f6641372
Improved the title creation of WSP Q and W facets - named main values are taken into account while title creation.
flys-artifacts/trunk@3031 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 19 Oct 2011 14:00:36 +0000 |
parents | 980d880c583c |
children | 1bc926b5b435 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java |
diffstat | 3 files changed, 121 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Oct 19 13:51:16 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Oct 19 14:00:36 2011 +0000 @@ -1,3 +1,15 @@ +2011-10-19 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java: + moved the code to create WSP W and Q facet names to FLYSUtils. + + * src/main/java/de/intevation/flys/utils/FLYSUtils.java: New functions for + creating WSP W and Q facet names and for querying a named main value + based on a given gauge and value. The names of W and Q facets will now + depend on the selected Q and Q mode: if the mode is "q at gauge" and a + named value is found for the given value, the facet's name contains the + named value instead of the value itself. + 2011-10-19 Felix Wolfsteller <felix.wolfsteller@intevation.de> Fix datacage configuration to let client load ZUS and flood
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java Wed Oct 19 13:51:16 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java Wed Oct 19 14:00:36 2011 +0000 @@ -1,6 +1,5 @@ package de.intevation.flys.artifacts.states; -import java.text.NumberFormat; import java.util.List; import org.apache.log4j.Logger; @@ -19,7 +18,7 @@ import de.intevation.flys.artifacts.model.ReportFacet; import de.intevation.flys.artifacts.model.WaterlevelFacet; import de.intevation.flys.artifacts.model.WQKms; -import de.intevation.flys.utils.Formatter; +import de.intevation.flys.utils.FLYSUtils; public class WaterlevelState @@ -57,10 +56,9 @@ for (int i = 0; i < wqkms.length; i++) { String name = wqkms[i].getName(); - boolean isQ = winfo.isQ(); - String nameW = createWTitle(cc, name, isQ); - String nameQ = createQTitle(cc, name, isQ); + String nameW = FLYSUtils.createWspWTitle(winfo, cc, name); + String nameQ = FLYSUtils.createWspQTitle(winfo, cc, name); logger.debug("Create facet: " + nameW); logger.debug("Create facet: " + nameQ); @@ -98,60 +96,6 @@ } - public static String createWTitle(CallContext cc, String name, boolean isQ) { - String[] parts = name.split("="); - - NumberFormat nf = Formatter.getWaterlevelW(cc); - - double v; - - try { - v = Double.valueOf(parts[1]); - } - catch (NumberFormatException nfe) { - logger.warn("Cannot parse Double of: '" + parts[1] + "'"); - return name; - } - - String prefix = null; - - if (isQ) { - prefix = "Q="; - } - - return prefix == null - ? "W(" + nf.format(v) + ")" - : "W(" + prefix + nf.format(v) + ")"; - } - - - public static String createQTitle(CallContext cc, String name, boolean isQ) { - String[] parts = name.split("="); - - NumberFormat nf = Formatter.getWaterlevelQ(cc); - - double v; - - try { - v = Double.valueOf(parts[1]); - } - catch (NumberFormatException nfe) { - logger.warn("Cannot parse Double of: '" + parts[1] + "'"); - return name; - } - - String prefix = null; - - if (!isQ) { - prefix = "W="; - } - - return prefix == null - ? "Q(" + nf.format(v) + ")" - : "Q(" + prefix + nf.format(v) + ")"; - } - - /** * @param context Ignored. */
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java Wed Oct 19 13:51:16 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java Wed Oct 19 14:00:36 2011 +0000 @@ -1,8 +1,10 @@ package de.intevation.flys.utils; import org.apache.log4j.Logger; - + +import java.text.NumberFormat; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.xml.xpath.XPathConstants; @@ -18,7 +20,10 @@ import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.model.RiverFactory; +import de.intevation.flys.model.Gauge; +import de.intevation.flys.model.MainValue; import de.intevation.flys.model.River; public class FLYSUtils { @@ -223,5 +228,105 @@ null, variables); } + + + public static String createWspWTitle( + WINFOArtifact winfo, + CallContext cc, + String name + ) { + String[] parts = name.split("="); + + NumberFormat nf = Formatter.getWaterlevelW(cc); + + String namedMainValue = null; + + boolean isQ = winfo.isQ(); + boolean isFree = winfo.isFreeQ(); + + double v; + + try { + v = Double.valueOf(parts[1]); + + namedMainValue = getNamedMainValue(winfo.getGauge(), v); + } + catch (NumberFormatException nfe) { + logger.warn("Cannot parse Double of: '" + parts[1] + "'"); + return name; + } + + String prefix = null; + + if (isQ && !isFree && namedMainValue != null) { + return "W (" + namedMainValue + ")"; + } + + if (isQ) { + prefix = "Q="; + } + + return prefix == null + ? "W(" + nf.format(v) + ")" + : "W(" + prefix + nf.format(v) + ")"; + } + + + public static String createWspQTitle( + WINFOArtifact winfo, + CallContext cc, + String name + ) { + String[] parts = name.split("="); + + NumberFormat nf = Formatter.getWaterlevelQ(cc); + + String namedMainValue = null; + + boolean isQ = winfo.isQ(); + boolean isFree = winfo.isFreeQ(); + + double v; + + try { + v = Double.valueOf(parts[1]); + + namedMainValue = getNamedMainValue(winfo.getGauge(), v); + } + catch (NumberFormatException nfe) { + logger.warn("Cannot parse Double of: '" + parts[1] + "'"); + return name; + } + + String prefix = null; + + if (isQ && !isFree && namedMainValue != null) { + return namedMainValue; + } + + if (!isQ) { + prefix = "W="; + } + + return prefix == null + ? "Q(" + nf.format(v) + ")" + : "Q(" + prefix + nf.format(v) + ")"; + } + + + public static String getNamedMainValue(Gauge gauge, double value) { + List<MainValue> mainValues = gauge.getMainValues(); + logger.debug("Search named main value for: " + value); + + for (MainValue mv: mainValues) { + if (mv.getValue().doubleValue() == value) { + logger.debug("Found named main value: " + mv.getMainValue().getName()); + return mv.getMainValue().getName(); + } + } + + logger.debug("Did not find a named main value for: " + value); + return null; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :