changeset 3020:ce796f1db30e

FixA: Store AnalysisPeriods into FixResult now. flys-artifacts/trunk@4587 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 05 Jun 2012 13:51:42 +0000
parents 484f3dad4bfd
children 84a7314244b5
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/AnalysisPeriodsKM.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java
diffstat 5 files changed, 57 insertions(+), 170 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 05 13:34:50 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 05 13:51:42 2012 +0000
@@ -1,3 +1,18 @@
+2012-06-05	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/AnalysisPeriodsKM.java:
+	  Removed. Not needed any longer.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java:
+	  Store the AnalysisPeriod per km into FixResult.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java:
+	  Uses KMIndex<AnalysisPeriod []> instead of DeltaWTsKM now.
+
+	* src/main/java/de/intevation/flys/exports/DeltaWtExporter.java:
+	  Commented out old code.
+	  TODO: Rewrite exporter to use AnalysisPeriods.
+
 2012-06-05  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java: Override
@@ -11,7 +26,7 @@
 2012-06-05	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/utils/Formatter.java:
-          (getMeterFormat): New.
+	  (getMeterFormat): New.
 	  Doc.
 
 	* src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/AnalysisPeriodsKM.java	Tue Jun 05 13:34:50 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-package de.intevation.flys.artifacts.model.fixings;
-
-import java.util.Comparator;
-
-import java.io.Serializable;
-
-public class AnalysisPeriodsKM
-implements   Serializable
-{
-    public static final double EPSILON = 1e-5;
-
-    public static final Comparator<AnalysisPeriodsKM> KM_COMPARATOR =
-        new Comparator<AnalysisPeriodsKM>() {
-            @Override
-            public int compare(AnalysisPeriodsKM a, AnalysisPeriodsKM b) {
-                double d = a.km - b.km;
-                if (d < EPSILON) return -1;
-                return d > EPSILON ? +1 : 0;
-            }
-        };
-
-    protected double            km;
-    protected AnalysisPeriod [] analysisPeriods;
-
-    public AnalysisPeriodsKM() {
-    }
-
-    public AnalysisPeriodsKM(double km) {
-        this.km = km;
-    }
-
-    public AnalysisPeriodsKM(double km, AnalysisPeriod [] analysisPeriods) {
-        this(km);
-        this.analysisPeriods = analysisPeriods;
-    }
-
-    public double getKm() {
-        return km;
-    }
-
-    public void setKm(double km) {
-        this.km = km;
-    }
-
-    public AnalysisPeriod [] getAnalysisPeriods() {
-        return analysisPeriods;
-    }
-
-    public void setAnalysisPeriods(AnalysisPeriod [] analysisPeriods) {
-        this.analysisPeriods = analysisPeriods;
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Tue Jun 05 13:34:50 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Tue Jun 05 13:51:42 2012 +0000
@@ -255,15 +255,13 @@
             results.removeNaNs();
         }
 
-        // Calculate Delta W/t
-        DeltaWTsKM deltaWTsKM = calculateDeltaWTs(
-            func,
-            overview,
-            results);
+        KMIndex<AnalysisPeriod []> analysisPeriods =
+            calculateAnalysisPeriods(func, results, overview);
 
         outliers.sort();
+        analysisPeriods.sort();
 
-        FixResult fr = new FixResult(results, deltaWTsKM, outliers);
+        FixResult fr = new FixResult(results, analysisPeriods, outliers);
 
         return new CalculationResult(fr, this);
     }
@@ -299,101 +297,11 @@
         return columns;
     }
 
-    public DeltaWTsKM calculateDeltaWTs(
-        Function        function,
-        FixingsOverview overview,
-        Parameters      results
-    ) {
-        boolean debug = log.isDebugEnabled();
-
-        DeltaWTsKM deltaWTsKM = new DeltaWTsKM(results.size());
-
-        Column [][] analysisColumns = getAnalysisColumns(overview);
-
-        int [] parameterIndices = 
-            results.columnIndices(function.getParameterNames());
-
-        double [] parameterValues =
-            new double[parameterIndices.length];
-
-        double [] ow = new double[1];
-
-        int kmIdx = results.columnIndex("km");
-
-        for (int i = 0, N = results.size(); i < N; ++i) {
-            double km = results.get(i, kmIdx);
-            results.get(i, parameterIndices, parameterValues);
-
-            DeltaWTsKM.KM dwtkm = new DeltaWTsKM.KM(km);
-            deltaWTsKM.add(dwtkm);
-
-            // This is the paraterized function for a given km.
-            de.intevation.flys.artifacts.math.Function instance =
-                function.instantiate(parameterValues);
-
-            // Evaluate all columns for all analysis periods.
-            for (int j = 0; j < analysisColumns.length; ++j) {
-                Column [] periodColumns = analysisColumns[j];
-
-                int failedQ = 0;
-                int failedW = 0;
-                int failedC = 0;
-
-                for (int k = 0; k < periodColumns.length; ++k) {
-                    Column pc = periodColumns[k];
-
-                    // Q from real data.
-                    double q = pc.data.getQ(km);
-                    if (Double.isNaN(q)) {
-                        ++failedQ;
-                        continue;
-                    }
-
-                    // Calculate W from function.
-                    double nw = instance.value(q);
-                    if (Double.isNaN(nw)) {
-                        ++failedC;
-                        continue;
-                    }
-
-                    // W from real data.
-                    pc.data.getW(km, ow);
-
-                    if (Double.isNaN(ow[0])) {
-                        ++failedW;
-                        continue;
-                    }
-
-                    double deltaW = (ow[0] - nw)*100.0; // in cm
-
-                    DeltaWT deltaWT = new DeltaWT(
-                        deltaW,
-                        pc.meta.getStartTime(),
-                        pc.meta.getDescription());
-
-                    dwtkm.add(deltaWT);
-                }
-                if (debug) {
-                    log.debug("failed W: " + failedW);
-                    log.debug("failed Q: " + failedQ);
-                    log.debug("failed C: " + failedC);
-                    log.debug("input size: " + periodColumns.length);
-                    log.debug("outpt size: " + dwtkm.size());
-                }
-            }
-        }
-
-        return deltaWTsKM;
-    }
-
-    protected List<AnalysisPeriodsKM> calculateAnalysisPeriods(
+    protected KMIndex<AnalysisPeriod []> calculateAnalysisPeriods(
         Function        function,
         Parameters      parameters,
         FixingsOverview overview
     ) {
-        ArrayList<AnalysisPeriodsKM> results
-            = new ArrayList<AnalysisPeriodsKM>(parameters.size());
-
         Range range = new Range(from, to);
 
         int kmIndex = parameters.columnIndex("km");
@@ -409,7 +317,10 @@
 
         DateAverager dateAverager = new DateAverager();
 
-        for (int row = 0, P = parameters.size(); row < P; ++row) {
+        KMIndex<AnalysisPeriod []> results =
+            new KMIndex<AnalysisPeriod []>(parameters.size());
+
+        for (int row = 0, R = parameters.size(); row < R; ++row) {
             double km = parameters.get(row, kmIndex);
             parameters.get(row, parameterIndices, parameterValues);
 
@@ -419,11 +330,17 @@
 
             KmFilter kmFilter = new KmFilter(km);
 
+            ArrayList<AnalysisPeriod> periodResults =
+                new ArrayList<AnalysisPeriod>(analysisPeriods.length);
+
             for (DateRange analysisPeriod: analysisPeriods) {
                 DateRangeFilter drf = new DateRangeFilter(
                     analysisPeriod.getFrom(),
                     analysisPeriod.getTo());
 
+                QWD [] qSectorAverages = new QWD[4];
+                ArrayList<QWD> allQWDs = new ArrayList<QWD>();
+
                 // for all Q sectors.
                 for (int qSector = qSectorStart; qSector < qSectorEnd; ++qSector) {
 
@@ -480,6 +397,7 @@
                     // Calulate average per Q sector.
                     int N = qwds.size();
                     if (N > 0) {
+                        allQWDs.addAll(qwds);
                         double avgW = sumW / N;
                         double avgQ = sumQ / N;
 
@@ -493,14 +411,20 @@
                             QWD avgQWD = new QWD(
                                 avgQ, avgW, avgDescription, avgDate, avgDw);
 
-                            // TODO: Store average value.
-                        }
-                        else {
-                            // TODO: Store
+                            qSectorAverages[qSector] = avgQWD;
                         }
                     }
                 } // for all Q sectors
+
+                QWD [] aqwds = allQWDs.toArray(new QWD[allQWDs.size()]);
+
+                AnalysisPeriod periodResult = new AnalysisPeriod(
+                    analysisPeriod, aqwds, qSectorAverages);
+                periodResults.add(periodResult);
             }
+
+            results.add(km, periodResults.toArray(
+                new AnalysisPeriod[periodResults.size()]));
         }
 
         return results;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java	Tue Jun 05 13:34:50 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java	Tue Jun 05 13:51:42 2012 +0000
@@ -9,21 +9,21 @@
 public class FixResult
 implements   Serializable
 {
-    protected Parameters parameters;
-    protected DeltaWTsKM deltaWTsKM;
-    protected KMIndex<QW []> outliers;
+    protected Parameters                 parameters;
+    protected KMIndex<AnalysisPeriod []> analysisPeriods;
+    protected KMIndex<QW []>             outliers;
 
     public FixResult() {
     }
 
     public FixResult(
-        Parameters     parameters,
-        DeltaWTsKM     deltaWTsKM,
-        KMIndex<QW []> outliers
+        Parameters                 parameters,
+        KMIndex<AnalysisPeriod []> analysisPeriods,
+        KMIndex<QW []>             outliers
     ) {
-        this.parameters = parameters;
-        this.deltaWTsKM = deltaWTsKM;
-        this.outliers   = outliers;
+        this.parameters      = parameters;
+        this.analysisPeriods = analysisPeriods;
+        this.outliers        = outliers;
     }
 
     public Parameters getParameters() {
@@ -34,12 +34,12 @@
         this.parameters = parameters;
     }
 
-    public DeltaWTsKM getDeltaWTsKM() {
-        return deltaWTsKM;
+    public KMIndex<AnalysisPeriod []> getAnalysisPeriods() {
+        return analysisPeriods;
     }
 
-    public void setDeltaWTsKM(DeltaWTsKM deltaWTsKM) {
-        this.deltaWTsKM = deltaWTsKM;
+    public void setAnalysisPeriods(KMIndex<AnalysisPeriod []> analysisPeriods) {
+        this.analysisPeriods = analysisPeriods;
     }
 
     public KMIndex<QW []> getOutliers() {
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java	Tue Jun 05 13:34:50 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java	Tue Jun 05 13:51:42 2012 +0000
@@ -94,7 +94,8 @@
             log.warn("Invalid data stored in result.");
         }
         FixResult result = (FixResult)data;
-        deltaWTsKMs.add(result.getDeltaWTsKM());
+        // TODO: replace old code
+        //deltaWTsKMs.add(result.getDeltaWTsKM());
     }
 
     @Override

http://dive4elements.wald.intevation.org