changeset 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 02254d763bc0
children acd89b7970dd
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/meta-data.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeDischargeState.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties
diffstat 7 files changed, 118 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Jun 07 13:13:13 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Jun 07 20:47:17 2012 +0000
@@ -1,3 +1,17 @@
+2012-06-07	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* doc/conf/meta-data.xml: Simplified choice of gauges for discharge c.
+
+	* src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/states/GaugeDischargeState.java:
+	  Create better name for facets, minor refactoring, polishing.
+
+	* src/main/resources/messages.properties,
+	  src/main/resources/messages_de_DE.properties,
+	  src/main/resources/messages_en.properties,
+	  src/main/resources/messages_de.properties:
+	  Added i18n strings.
+
 2012-06-07	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java,
--- a/flys-artifacts/doc/conf/meta-data.xml	Thu Jun 07 13:13:13 2012 +0000
+++ b/flys-artifacts/doc/conf/meta-data.xml	Thu Jun 07 20:47:17 2012 +0000
@@ -616,6 +616,15 @@
                       <gauge>
                         <dc:attribute name="name" value="${gauge_name}"/>
                         <dc:attribute name="db-id" value="${gauge_id}"/>
+                        <dc:attribute name="factory" value="gaugedischarge"/>
+                        <dc:attribute name="from" value="${g_start}"/>
+                        <dc:attribute name="to" value="${g_stop}"/>
+                        <dc:attribute name="ids" value="${gauge_name}"/>
+                      </gauge>
+                      <!--
+                      <gauge>
+                        <dc:attribute name="name" value="${gauge_name}"/>
+                        <dc:attribute name="db-id" value="${gauge_id}"/>
                         <dc:context>
                           <dc:statement>
                             SELECT description   AS gauge_desc, 
@@ -637,6 +646,7 @@
                           </dc:elements>
                         </dc:context>
                       </gauge>
+                      -->
                     </dc:elements>
                   </dc:context>
                 </discharge_table_gauge>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java	Thu Jun 07 13:13:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeArtifact.java	Thu Jun 07 20:47:17 2012 +0000
@@ -69,9 +69,10 @@
         Document        data)
     {
         logger.debug("GaugeDischargeArtifact.setup");
+        String ids = StaticFLYSArtifact.getDatacageIDValue(data);
+        addStringData("ids", ids);
+        logger.debug("id for gaugedischarge: " + ids);
         super.setup(identifier, factory, context, callMeta, data);
-        String ids = StaticFLYSArtifact.getDatacageIDValue(data);
-        logger.debug("id for gaugedischarge: " + ids);
     }
 
 
@@ -81,12 +82,6 @@
     }
 
 
-    /** Access state data storing the jsonstring with points. 
-    public String getPointsData(String facetName) {
-        return getDataAsString(facetName + ".data");
-    }*/
-
-
     /**
      * Setup state and facet, copy from master artifact.
      */
@@ -98,10 +93,7 @@
         importData(artifact, "river");
 
         // Get the location(s)
-        //importData(artifact, "ld_mode");
-        //importData(artifact, "ld_from");
-        //importData(artifact, "ld_to");
-        //importData(artifact, "ld_locations");
+        //importData(artifact, "ld_mode", ld_from, ld_to, ld_locations
         addStringData("ld_from", "0");
         addStringData("ld_to", "1000");
         addStringData("ld_mode", "distance");
@@ -120,28 +112,22 @@
     }
 
 
-    /**
-     * Determines Facets initial disposition regarding activity (think of
-     * selection in Client ThemeList GUI). This will be checked one time
-     * when the facet enters a collections describe document.
-     *
-     * @param facetName name of the facet.
-     * @param index     index of the facet.
-     * @return 0 if not active
-     */
-    @Override
-    public int getInitialFacetActivity(
-        String outputName,
-        String facetName,
-        int index)
-    {
-        return 1;
+    /** Get the Gauges name which came with datacage data-document. */
+    public String getGaugeName() {
+        return this.getDataAsString("ids");
+    }
+
+
+    /** Get the Gauges which came with datacage data-document. */
+    public Gauge getGauge() {
+        River river = FLYSUtils.getRiver(this);
+        return river.determineGaugeByName(getGaugeName());
     }
 
 
     /**
      * Returns the data that is used to create discharge curves.
-     *
+     * @return CalculationResult with WQKms.
      */
     public CalculationResult getDischargeCurveData() {
 
@@ -149,7 +135,8 @@
         if (river == null) {
             return error(new WQKms[0], "no.river.selected");
         }
-
+        /*
+        // This one would allow to automatically pick the right Gauge.
         double [] distance = FLYSUtils.getKmRange(this);
         logger.debug("getDischargeCurveData: get range");
 
@@ -158,7 +145,7 @@
         }
 
         List<Gauge> gauges = river.determineGauges(distance[0], distance[1]);
-        logger.debug("getDischargeCurveData: get gauges");
+        logger.debug("getDischargeCurveData: got " + gauges.size() + " gauges");
 
         if (gauges.isEmpty()) {
             return error(new WQKms[0], "no.gauge.selected");
@@ -170,29 +157,50 @@
             names[i] = gauges.get(i).getName();
             logger.debug("getDischargeCurveData: name " + names[i]);
         }
+        */
 
-        DischargeTables dt = new DischargeTables(river.getName(), names);
+        DischargeTables dt = new DischargeTables(river.getName(), getDataAsString("ids"));
 
-        Map<String, double [][]> map = dt.getValues(100d);
+        Map<String, double [][]> map = dt.getValues(100);
 
         ArrayList<WQKms> res = new ArrayList<WQKms>();
 
-        for (Gauge gauge: gauges) {
-            String name = gauge.getName();
-            double [][] values = map.get(name);
-            if (values == null) {
-                continue;
-            }
-            double [] kms = new double[values[0].length];
-            Arrays.fill(kms, gauge.getStation().doubleValue());
-            res.add(new WQKms(kms, values[0], values[1], name));
-            logger.debug("getDischargeCurveData: add one res gauge");
+        Gauge gauge = river.determineGaugeByName(this.getDataAsString("ids"));
+
+        String name = getGaugeName();
+        double [][] values = map.get(name);
+        if (values == null) {
+            logger.error("No values for this gauge / discharge found.");
         }
+        for (int i = 0 ; i < values[0].length; i++) {
+            values[0][i] += gauge.getDatum().doubleValue();
+        }
+        double [] kms = new double[values[0].length];
+        Arrays.fill(kms, gauge.getStation().doubleValue());
+        res.add(new WQKms(kms, values[0], values[1], name));
 
         return new CalculationResult(
             res.toArray(new WQKms[res.size()]),
             new Calculation());
     }
 
+
+    /**
+     * Determines Facets initial disposition regarding activity (think of
+     * selection in Client ThemeList GUI). This will be checked one time
+     * when the facet enters a collections describe document.
+     *
+     * @param facetName name of the facet.
+     * @param index     index of the facet.
+     * @return 1 - all Facets enter activated.
+     */
+    @Override
+    public int getInitialFacetActivity(
+        String outputName,
+        String facetName,
+        int index)
+    {
+        return 1;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeDischargeState.java	Thu Jun 07 13:13:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeDischargeState.java	Thu Jun 07 20:47:17 2012 +0000
@@ -23,6 +23,8 @@
 import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.utils.FLYSUtils;
 
+import de.intevation.flys.model.Gauge;
+
 
 /**
  * The only state for an GaugeDischargeState (River and km known).
@@ -35,7 +37,33 @@
     public static final String I18N_DESCRIPTION = "facet.discharge.curve";
 
     /** The logger that is used in this state. */
-    private static final Logger logger = Logger.getLogger(GaugeDischargeState.class);
+    private static final Logger logger =
+        Logger.getLogger(GaugeDischargeState.class);
+
+
+    /**
+     * Create i18ned name for gaugedischargeFacet.
+     * @param artifact The artifact which has information about the gauge.
+     * @param meta used for i18n.
+     * @return localized name for gaugedischargefacet.
+     */
+    protected String createFacetName(GaugeDischargeArtifact artifact,
+        CallMeta meta) {
+
+        Gauge gauge = artifact.getGauge();
+        Object[] args = new Object[] {
+            gauge.getName(),
+            gauge.getStation()
+        };
+
+        String name = Resources.getMsg(
+            meta,
+            "chart.computed.discharge.curve.gauge",
+            "",
+            args);
+
+        return name;
+    }
 
 
     /**
@@ -59,20 +87,22 @@
     ) {
         logger.debug("GaugeDischargeState.computeInit()");
 
-        // TODO caching, / CalculationResultusage
+        // TODO caching, / CalculationResultUsage
 
         GaugeDischargeFacet facet = new GaugeDischargeFacet(
             0,
             DISCHARGE_CURVE,
-            DISCHARGE_CURVE);
-            //Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION));
+            createFacetName((GaugeDischargeArtifact) artifact, meta));
+
         facets.add(facet);
 
         return null;
     }
-    //WINFOArtifact#getDischargeCurveData
 
 
+    /**
+     * 'Calculate' Discharge at Gauge.
+     */
     @Override
     public Object computeAdvance(
         FLYSArtifact artifact,
@@ -81,8 +111,6 @@
         List<Facet>  facets,
         Object       old
     ) {
-        // TODO why are the facets null here?
-        //if (facets == null) facets = new List<Facet>();
         if (artifact instanceof GaugeDischargeArtifact) {
             logger.debug("GaugeDischargeState.computeAdvance()");
             GaugeDischargeArtifact dischargeArtifact = (GaugeDischargeArtifact) artifact;
@@ -100,33 +128,12 @@
 
             if (wqkms != null && facets != null) {
                 logger.debug("GaugeDischargeState.computeAdvance(): create facets");
-                // Create an i18ed name for a (w or q) duration curve facet.
-                Object[] args = new Object[] {
-                    FLYSUtils.getRiver(dischargeArtifact).getName(),
-                    FLYSUtils.getLocations(dischargeArtifact)[0]
-                };
 
-                String nameW = Resources.getMsg(
-                    context.getMeta(),
-                    "chart.duration.curve.curve.w",
-                    "",
-                    args);
-
-                String nameQ = Resources.getMsg(
-                    context.getMeta(),
-                    "chart.duration.curve.curve.q",
-                    "",
-                    args);
-
-                /*Facet w = new DurationCurveFacet(DURATION_W, nameW);
-                Facet q = new DurationCurveFacet(DURATION_Q, nameQ);
-
-                facets.add(w);*/
                 GaugeDischargeFacet facet = new GaugeDischargeFacet(
                     0,
-                    "A"+DISCHARGE_CURVE,
-                    "A"+DISCHARGE_CURVE);
-                    //Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION));
+                    DISCHARGE_CURVE,
+                    createFacetName(dischargeArtifact, context.getMeta()));
+
                 facets.add(facet);
 
                 //facets.add(new DataFacet(CSV, "CSV data"));
@@ -138,9 +145,9 @@
             }
             else {
                 if (wqkms == null)
-                logger.debug("GaugeDischargeState.computeAdvance(): wqkms 0");
+                    logger.debug("GaugeDischargeState.computeAdvance(): wqkms 0");
                 else
-                logger.debug("GaugeDischargeState.computeAdvance(): facets 0");
+                    logger.debug("GaugeDischargeState.computeAdvance(): facets 0");
             }
 
             return res;
@@ -152,6 +159,5 @@
         }
         return null;
     }
-
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/resources/messages.properties	Thu Jun 07 13:13:13 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages.properties	Thu Jun 07 20:47:17 2012 +0000
@@ -108,6 +108,7 @@
 chart.computed.discharge.curve.subtitle = {0}-km: {1,number,#.###}
 chart.computed.discharge.curve.yaxis.label = W [NN + m]
 chart.computed.discharge.curve.curve.label = Discharge Curve {0} km {1}
+chart.computed.discharge.curve.gauge = Discharge curve at gauge {0} (km {1})
 chart.duration.curve.title = Duration Curve
 chart.duration.curve.subtitle = {0}-km: {1,number,#.###}
 chart.duration.curve.xaxis.label = Duration of Non-Exceedence [Days]
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Thu Jun 07 13:13:13 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Thu Jun 07 20:47:17 2012 +0000
@@ -105,6 +105,7 @@
 chart.computed.discharge.curve.subtitle = {0}-km: {1,number,#.###}
 chart.computed.discharge.curve.yaxis.label = W [NN + m]
 chart.computed.discharge.curve.curve.label = Abflusskurve {0} km {1}
+chart.computed.discharge.curve.gauge = Abflusskurve an Pegel {0} (km {1})
 chart.duration.curve.title = Dauerlinie
 chart.duration.curve.subtitle = {0}-km: {1,number,#.###}
 chart.duration.curve.xaxis.label = Unterschreitungsdauer [Tage]
--- a/flys-artifacts/src/main/resources/messages_en.properties	Thu Jun 07 13:13:13 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Thu Jun 07 20:47:17 2012 +0000
@@ -98,6 +98,7 @@
 chart.longitudinal.section.yaxis.label = W [{0}]
 chart.longitudinal.section.yaxis.second.label = Q [m\u00b3/s]
 chart.longitudinal.annotations.label = {0}.km
+chart.computed.discharge.curve.gauge = Discharge curve at gauge {0} (km {1})
 chart.discharge.curve.title = Discharge Curve
 chart.discharge.curve.xaxis.label = Q [m\u00b3/s]
 chart.discharge.curve.yaxis.label = W [cm]

http://dive4elements.wald.intevation.org