changeset 3426:e7a67407dea1

Limited the input of time periods in SQ relation calculation to 1. flys-artifacts/trunk@5082 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 20 Jul 2012 09:34:47 +0000
parents 7babd4e92c8b
children 5f47e68a1130
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/minfo.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/SQRelationAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/PeriodSelect.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties
diffstat 9 files changed, 104 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jul 20 07:50:08 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Jul 20 09:34:47 2012 +0000
@@ -1,3 +1,24 @@
+2012-07-20  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/artifacts/minfo.xml: Changed the parameters for SQ relation
+	  period selection; only a single period is allowed now.
+
+	* src/main/java/de/intevation/flys/artifacts/states/PeriodSelect.java: New
+	  class that allows the selection of a time period.
+
+	* src/main/java/de/intevation/flys/artifacts/access/SQRelationAccess.java:
+	  Reduced support of time periods to a single period.
+
+	* src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java:
+	  Adapted the usage of SQRelationAccess which method signature has
+	  changed; it returns a single DateRange instance only.
+
+	* src/main/resources/messages.properties,
+	  src/main/resources/messages_de_DE.properties,
+	  src/main/resources/messages_en.properties,
+	  src/main/resources/messages_de.properties: Modified the keys of the
+	  state for SQ relation time period input.
+
 2012-07-20  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/sq/SQOverviewGenerator.java:
--- a/flys-artifacts/doc/conf/artifacts/minfo.xml	Fri Jul 20 07:50:08 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/minfo.xml	Fri Jul 20 09:34:47 2012 +0000
@@ -56,7 +56,7 @@
 
         <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
             <from state="state.minfo.sq.location"/>
-            <to state="state.minfo.sq.periods"/>
+            <to state="state.minfo.sq.period"/>
         </transition>
 
         <state id="state.minfo.dischargestate" description="state.minfo.dischargestate" state="de.intevation.flys.artifacts.states.DischargeState" helpText="help.minfo.dischargestate">
@@ -68,8 +68,9 @@
             <data name="soundings" type="options"/>
         </state>
 
-        <state id="state.minfo.sq.periods" description="state.minfo.sq.periods" state="de.intevation.flys.artifacts.states.PeriodsSelect">
-            <data name="periods" type="String"/>
+        <state id="state.minfo.sq.period" description="state.minfo.sq.period" state="de.intevation.flys.artifacts.states.PeriodSelect">
+            <data name="start" type="Long"/>
+            <data name="end"   type="Long"/>
         </state>
 
         <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
@@ -83,7 +84,7 @@
         </transition>
 
         <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
-            <from state="state.minfo.sq.periods"/>
+            <from state="state.minfo.sq.period"/>
             <to state="state.minfo.sq.outliers"/>
         </transition>
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/SQRelationAccess.java	Fri Jul 20 07:50:08 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/SQRelationAccess.java	Fri Jul 20 09:34:47 2012 +0000
@@ -1,23 +1,24 @@
 package de.intevation.flys.artifacts.access;
 
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+
 import de.intevation.flys.artifacts.FLYSArtifact;
-
 import de.intevation.flys.artifacts.model.DateRange;
 
-import org.apache.log4j.Logger;
-
 public class SQRelationAccess
 extends      Access
 {
     private static Logger log = Logger.getLogger(SQRelationAccess.class);
 
-    protected String       river;
+    protected String    river;
 
-    protected Double       location;
+    protected Double    location;
 
-    protected DateRange [] periods;
+    protected DateRange period;
 
-    protected Double       outliers;
+    protected Double    outliers;
 
     public SQRelationAccess() {
     }
@@ -49,11 +50,17 @@
         return location;
     }
 
-    public DateRange [] getPeriods() {
-        if (periods == null) {
-            periods = getDateRange("periods");
+    public DateRange getPeriod() {
+        if (period == null) {
+            Long start = getLong("start");
+            Long end   = getLong("end");
+
+            if (start != null && end != null) {
+                period = new DateRange(new Date(start), new Date(end));
+            }
         }
-        return periods;
+
+        return period;
     }
 
     public Double getOutliers() {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java	Fri Jul 20 07:50:08 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java	Fri Jul 20 09:34:47 2012 +0000
@@ -12,7 +12,6 @@
 
 import de.intevation.flys.backend.SedDBSessionHolder;
 
-import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.log4j.Logger;
@@ -24,20 +23,20 @@
 
     public static final String SQ_FUNCTION_NAME = "sq-pow";
 
-    protected String       river;
-    protected double       location;
-    protected DateRange [] periods;
-    protected double       outliers;
+    protected String    river;
+    protected double    location;
+    protected DateRange period;
+    protected double    outliers;
 
     public SQRelationCalculation() {
     }
 
     public SQRelationCalculation(SQRelationAccess access) {
 
-        String       river    = access.getRiver();
-        Double       location = access.getLocation();
-        DateRange [] periods  = access.getPeriods();
-        Double       outliers = access.getOutliers();
+        String    river    = access.getRiver();
+        Double    location = access.getLocation();
+        DateRange period  = access.getPeriod();
+        Double    outliers = access.getOutliers();
 
         //river = "Rhein";
 
@@ -51,7 +50,7 @@
             addProblem("sq.missing.location");
         }
 
-        if (periods == null || periods.length == 0) {
+        if (period == null) {
             // TODO: i18n
             addProblem("sq.missing.periods");
         }
@@ -64,7 +63,7 @@
         if (!hasProblems()) {
             this.river    = river;
             this.location = location;
-            this.periods  = periods;
+            this.period   = period;
             this.outliers = outliers;
         }
     }
@@ -103,56 +102,45 @@
 
         String [] parameterNames = function.getParameterNames();
 
-        List<SQResult> results = new ArrayList<SQResult>(periods.length);
-
         Fitting fitting = new Fitting(function, outliers);
 
-        for (DateRange period: periods) {
             Measurements measurements =
                 MeasurementFactory.getMeasurements(river, location, period);
 
-            /*
-            if (debug) {
-                log.debug(measurements.toString());
-            }
-            */
-
-            SQFractionResult [] fractionResults =
-                new SQFractionResult[SQResult.NUMBER_FRACTIONS];
+        SQFractionResult [] fractionResults =
+            new SQFractionResult[SQResult.NUMBER_FRACTIONS];
 
-            for (int i = 0; i < fractionResults.length; ++i) {
-                List<SQ> sqs = measurements.getSQs(i);
+        for (int i = 0; i < fractionResults.length; ++i) {
+            List<SQ> sqs = measurements.getSQs(i);
 
-                SQFractionResult fractionResult;
+            SQFractionResult fractionResult;
 
-                if (!fitting.fit(sqs)) {
-                    // TODO: i18n
-                    addProblem("sq.fitting.failed." + i);
-                    fractionResult = new SQFractionResult();
+            if (!fitting.fit(sqs)) {
+                // TODO: i18n
+                addProblem("sq.fitting.failed." + i);
+                fractionResult = new SQFractionResult();
+            }
+            else {
+                Parameters parameters = createParameters(parameterNames);
+                int row = parameters.newRow();
+                double [] coeffs = fitting.getParameters();
+                for (int j = 0; j < parameterNames.length; ++j) {
+                    parameters.set(row, parameterNames[j], coeffs[j]);
                 }
-                else {
-                    Parameters parameters = createParameters(parameterNames);
-                    int row = parameters.newRow();
-                    double [] coeffs = fitting.getParameters();
-                    for (int j = 0; j < parameterNames.length; ++j) {
-                        parameters.set(row, parameterNames[j], coeffs[j]);
-                    }
-                    parameters.set(row, "chi_sqr", fitting.getChiSqr());
-                    parameters.set(row, "std_dev", fitting.getStandardDeviation());
+                parameters.set(row, "chi_sqr", fitting.getChiSqr());
+                parameters.set(row, "std_dev", fitting.getStandardDeviation());
 
-                    fractionResult = new SQFractionResult(
-                        parameters,
-                        fitting.getRemaining(),
-                        fitting.getOutliers());
-                }
-                fitting.reset();
-                fractionResults[i] = fractionResult;
+                fractionResult = new SQFractionResult(
+                    parameters,
+                    fitting.getRemaining(),
+                    fitting.getOutliers());
             }
-            results.add(new SQResult(location, fractionResults));
+            fitting.reset();
+            fractionResults[i] = fractionResult;
         }
 
         return new CalculationResult(
-            results.toArray(new SQResult[results.size()]),
+            new SQResult[] { new SQResult(location, fractionResults) },
             this);
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/PeriodSelect.java	Fri Jul 20 09:34:47 2012 +0000
@@ -0,0 +1,21 @@
+package de.intevation.flys.artifacts.states;
+
+public class PeriodSelect extends DefaultState {
+
+    public static final String UI_PROVIDER = "period_select";
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * The default constructor that initializes an empty State object.
+     */
+    public PeriodSelect() {
+    }
+
+    @Override
+    protected String getUIProvider() {
+        return UI_PROVIDER;
+    }
+
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/resources/messages.properties	Fri Jul 20 07:50:08 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages.properties	Fri Jul 20 09:34:47 2012 +0000
@@ -35,7 +35,7 @@
 state.minfo.distance_only = Range selection
 state.minfo.dischargestate = Selection of discharge state and channel
 state.minfo.sq.location=Location
-state.minfo.sq.periods=Periods
+state.minfo.sq.period=Periods
 state.minfo.sq.outliers=Outliers
 
 historical.mode.w = Waterlevel Analyse
--- a/flys-artifacts/src/main/resources/messages_de.properties	Fri Jul 20 07:50:08 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de.properties	Fri Jul 20 09:34:47 2012 +0000
@@ -35,7 +35,7 @@
 state.minfo.distance_only = Wahl der Berechnungsstrecke
 state.minfo.dischargestate = Abflusszustand und Gerinne
 state.minfo.sq.location=Ort
-state.minfo.sq.periods=Zeitraum
+state.minfo.sq.period=Zeitraum
 state.minfo.sq.outliers=Ausrei\u00dfer
 
 historical.mode.w = Wasserstandsanalyse
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Fri Jul 20 07:50:08 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Fri Jul 20 09:34:47 2012 +0000
@@ -35,7 +35,7 @@
 state.minfo.distance_only = Wahl der Berechnungsstrecke
 state.minfo.dischargestate = Abflusszustand und Gerinne
 state.minfo.sq.location=Ort
-state.minfo.sq.periods=Zeitraum
+state.minfo.sq.period=Zeitraum
 state.minfo.sq.outliers=Ausrei\u00dfer
 
 historical.mode.w = Wasserstandsanalyse
--- a/flys-artifacts/src/main/resources/messages_en.properties	Fri Jul 20 07:50:08 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Fri Jul 20 09:34:47 2012 +0000
@@ -35,7 +35,7 @@
 state.minfo.distance_only = Range selection
 state.minfo.dischargestate = Selection of discharge state and channel
 state.minfo.sq.location=Location
-state.minfo.sq.periods=Periods
+state.minfo.sq.period=Periods
 state.minfo.sq.outliers=Outliers
 
 historical.mode.w = Waterlevel Analyse

http://dive4elements.wald.intevation.org