changeset 3729:e727e3ebdf85

Factored out a pure QW model to be more reusable. flys-artifacts/trunk@5402 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 08 Sep 2012 14:19:40 +0000
parents d03e65378b9f
children 487a8cb4a222
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QW.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisResult.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/FixOutlierFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/QW.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/QWD.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/QWI.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/QWSeriesCollection.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java
diffstat 14 files changed, 213 insertions(+), 160 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/ChangeLog	Sat Sep 08 14:19:40 2012 +0000
@@ -1,7 +1,34 @@
+2012-09-08	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/QW.java:
+	  New. a pure model for discharge and waterlevel. No extras.
+
+	  Makes reuse in upcoming "Auslagerung extremer Wasserspiegellagen"
+	  a lot easier.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/QW.java:
+	  Removed.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/QWI.java:
+	  Re-inserted here. Extends the new QW and adds all the extra bells
+	  and whistles needed in the fixings analysis.
+
+	* src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java,
+	  src/main/java/de/intevation/flys/artifacts/services/QWSeriesCollection.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisResult.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingResult.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/QWD.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java,
+	  src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java:
+	  Adjusted QW to QWI.
+
 2012-09-08	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/MainValuesFactory.java;
-	   Removed because code is found in backend already.
+	  Removed because code is found in backend already.
 
 	* src/main/java/de/intevation/flys/artifacts/services/MainValuesService.java:
 	  Simplified. Please _DO_NOT_ use NullPointerExceptions for regular flow control!
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QW.java	Sat Sep 08 14:19:40 2012 +0000
@@ -0,0 +1,35 @@
+package de.intevation.flys.artifacts.model;
+
+import java.io.Serializable;
+
+public class QW
+implements   Serializable
+{
+    protected double q;
+    protected double w;
+
+    public QW() {
+    }
+
+    public QW(double q, double w) {
+        this.q = q;
+        this.w = w;
+    }
+
+    public double getQ() {
+        return q;
+    }
+
+    public void setQ(double q) {
+        this.q = q;
+    }
+
+    public double getW() {
+        return w;
+    }
+
+    public void setW(double w) {
+        this.w = w;
+    }
+}
+// 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/Fitting.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java	Sat Sep 08 14:19:40 2012 +0000
@@ -37,18 +37,18 @@
         }
     };
 
-    protected boolean       checkOutliers;
-    protected Function      function;
-    protected QWDFactory    qwdFactory;
-    protected double        chiSqr;
-    protected double []     parameters;
-    protected ArrayList<QW> removed;
-    protected QWD []        referenced;
-    protected double        standardDeviation;
+    protected boolean        checkOutliers;
+    protected Function       function;
+    protected QWDFactory     qwdFactory;
+    protected double         chiSqr;
+    protected double []      parameters;
+    protected ArrayList<QWI> removed;
+    protected QWD []         referenced;
+    protected double         standardDeviation;
 
 
     public Fitting() {
-        removed = new ArrayList<QW>();
+        removed = new ArrayList<QWI>();
     }
 
     public Fitting(Function function) {
@@ -102,12 +102,12 @@
         return !removed.isEmpty();
     }
 
-    public List<QW> getOutliers() {
+    public List<QWI> getOutliers() {
         return removed;
     }
 
-    public QW [] outliersToArray() {
-        return removed.toArray(new QW[removed.size()]);
+    public QWI [] outliersToArray() {
+        return removed.toArray(new QWI[removed.size()]);
     }
 
     public QWD [] referencedToArray() {
@@ -117,7 +117,7 @@
     public double getMaxQ() {
         double maxQ = -Double.MAX_VALUE;
         if (referenced != null) {
-            for (QW qw: referenced) {
+            for (QWI qw: referenced) {
                 if (qw.getQ() > maxQ) {
                     maxQ = qw.getQ();
                 }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisResult.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisResult.java	Sat Sep 08 14:19:40 2012 +0000
@@ -18,7 +18,7 @@
     public FixAnalysisResult(
         Parameters                 parameters,
         KMIndex<QWD []>            referenced,
-        KMIndex<QW []>             outliers,
+        KMIndex<QWI []>            outliers,
         KMIndex<AnalysisPeriod []> analysisPeriods
     ) {
         super(parameters, referenced, outliers);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Sat Sep 08 14:19:40 2012 +0000
@@ -47,7 +47,7 @@
 
         protected Parameters      parameters;
         protected KMIndex<QWD []> referenced;
-        protected KMIndex<QW []>  outliers;
+        protected KMIndex<QWI []> outliers;
 
         public FitResult() {
         }
@@ -55,7 +55,7 @@
         public FitResult(
             Parameters      parameters,
             KMIndex<QWD []> referenced,
-            KMIndex<QW []>  outliers
+            KMIndex<QWI []> outliers
         ) {
             this.parameters = parameters;
             this.referenced = referenced;
@@ -70,7 +70,7 @@
             return referenced;
         }
 
-        public KMIndex<QW []> getOutliers() {
+        public KMIndex<QWI []> getOutliers() {
             return outliers;
         }
     } // class FitResult
@@ -323,7 +323,7 @@
             log.debug("number of kms: " + kms.length);
         }
 
-        KMIndex<QW []>  outliers   = new KMIndex<QW []>();
+        KMIndex<QWI []> outliers   = new KMIndex<QWI []>();
         KMIndex<QWD []> referenced = new KMIndex<QWD []>(kms.length);
 
         int kmIndex             = results.columnIndex("km");
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Sat Sep 08 14:19:40 2012 +0000
@@ -65,15 +65,17 @@
             double currentKm =
                 ((Double)context.getContextValue("currentKm")).doubleValue();
 
-            KMIndex<QW []>       kmQWs    = result.getOutliers();
-            KMIndex.Entry<QW []> qwsEntry = kmQWs.binarySearch(currentKm);
+            KMIndex<QWI []>       kmQWs    = result.getOutliers();
+            KMIndex.Entry<QWI []> qwsEntry = kmQWs.binarySearch(currentKm);
 
-            QW[] qws = null;
-            if(qwsEntry != null) {
+            QWI [] qws = null;
+            if (qwsEntry != null) {
                 qws = qwsEntry.getValue();
 
-                logger.debug("Found " + (qws != null ? qws.length : 0)
-                    + " KMIndex.Entry for km " + currentKm);
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Found " + (qws != null ? qws.length : 0)
+                        + " KMIndex.Entry for km " + currentKm);
+                }
             }
             else {
                 logger.debug("Found no KMIndex.Entry for km " + currentKm);
@@ -81,10 +83,9 @@
 
             return qws;
         }
-        else {
-            logger.warn("Not an instance of FLYSArtifact.");
-            return null;
-        }
+
+        logger.warn("Not an instance of FLYSArtifact.");
+        return null;
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingResult.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingResult.java	Sat Sep 08 14:19:40 2012 +0000
@@ -17,7 +17,7 @@
     public FixRealizingResult(
         Parameters      parameters,
         KMIndex<QWD []> referenced,
-        KMIndex<QW []>  outliers,
+        KMIndex<QWI []> outliers,
         WQKms []        wqkms
     ) {
         super(parameters, referenced, outliers);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java	Sat Sep 08 14:19:40 2012 +0000
@@ -11,7 +11,7 @@
 {
     protected Parameters      parameters;
     protected KMIndex<QWD []> referenced;
-    protected KMIndex<QW []>  outliers;
+    protected KMIndex<QWI []> outliers;
 
     public FixResult() {
     }
@@ -19,7 +19,7 @@
     public FixResult(
         Parameters      parameters,
         KMIndex<QWD []> referenced,
-        KMIndex<QW []>  outliers
+        KMIndex<QWI []> outliers
     ) {
         this.parameters = parameters;
         this.referenced = referenced;
@@ -34,11 +34,11 @@
         this.referenced = referenced;
     }
 
-    public KMIndex<QW []> getOutliers() {
+    public KMIndex<QWI []> getOutliers() {
         return outliers;
     }
 
-    public void setOutliers(KMIndex<QW []> outliers) {
+    public void setOutliers(KMIndex<QWI []> outliers) {
         this.outliers = outliers;
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/QW.java	Sat Sep 08 13:36:06 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-package de.intevation.flys.artifacts.model.fixings;
-
-import java.util.Date;
-
-import java.io.Serializable;
-
-public class QW
-implements   Serializable
-{
-    protected double  q;
-    protected double  w;
-    protected String  description;
-    protected Date    date;
-    protected boolean interpolated;
-    protected int     index;
-
-    public QW() {
-    }
-
-    public QW(double q, double w) {
-        this.q = q;
-        this.w = w;
-    }
-
-    public QW(
-        double  q,
-        double  w,
-        String  description,
-        Date    date,
-        boolean interpolated,
-        int     index
-    ) {
-        this(q, w);
-        this.description  = description;
-        this.date         = date;
-        this.interpolated = interpolated;
-        this.index        = index;
-    }
-
-    public double getQ() {
-        return q;
-    }
-
-    public void setQ(double q) {
-        this.q = q;
-    }
-
-    public double getW() {
-        return w;
-    }
-
-    public void setW(double w) {
-        this.w = w;
-    }
-
-    public Date getDate() {
-        return date;
-    }
-
-    public void setDate(Date date) {
-        this.date = date;
-    }
-
-    public String getDescription() {
-        return description;
-    }
-
-    public void setDescription(String description) {
-        this.description = description;
-    }
-
-    public boolean getInterpolated() {
-        return interpolated;
-    }
-
-    public void setInterpolated(boolean interpolated) {
-        this.interpolated = interpolated;
-    }
-
-    public int getIndex() {
-        return index;
-    }
-
-    public void setIndex(int index) {
-        this.index = index;
-    }
-}
-// 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/QWD.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/QWD.java	Sat Sep 08 14:19:40 2012 +0000
@@ -3,7 +3,7 @@
 import java.util.Date;
 
 public class QWD
-extends      QW
+extends      QWI
 {
     protected double deltaW;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/QWI.java	Sat Sep 08 14:19:40 2012 +0000
@@ -0,0 +1,69 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import de.intevation.flys.artifacts.model.QW;
+
+import java.util.Date;
+
+public class QWI
+extends      QW
+{
+    protected String  description;
+    protected Date    date;
+    protected boolean interpolated;
+    protected int     index;
+
+    public QWI() {
+    }
+
+    public QWI(double q, double w) {
+        super(q, w);
+    }
+
+    public QWI(
+        double  q,
+        double  w,
+        String  description,
+        Date    date,
+        boolean interpolated,
+        int     index
+    ) {
+        super(q, w);
+        this.description  = description;
+        this.date         = date;
+        this.interpolated = interpolated;
+        this.index        = index;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public boolean getInterpolated() {
+        return interpolated;
+    }
+
+    public void setInterpolated(boolean interpolated) {
+        this.interpolated = interpolated;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java	Sat Sep 08 14:19:40 2012 +0000
@@ -18,7 +18,7 @@
 import de.intevation.flys.artifacts.model.GaugeFinderFactory;
 import de.intevation.flys.artifacts.model.GaugeRange;
 
-import de.intevation.flys.artifacts.model.fixings.QW;
+import de.intevation.flys.artifacts.model.fixings.QWI;
 
 import de.intevation.flys.artifacts.resources.Resources;
 
@@ -276,7 +276,7 @@
             boolean interpolated = !col.getB().getW(km, w);
             double q = col.getB().getQ(km);
             if (!Double.isNaN(w[0]) && !Double.isNaN(q)) {
-                QW qw = new QW(
+                QWI qw = new QWI(
                     q, w[0],
                     col.getA().getDescription(),
                     col.getA().getStartTime(),
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/QWSeriesCollection.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/QWSeriesCollection.java	Sat Sep 08 14:19:40 2012 +0000
@@ -1,6 +1,6 @@
 package de.intevation.flys.artifacts.services;
 
-import de.intevation.flys.artifacts.model.fixings.QW;
+import de.intevation.flys.artifacts.model.fixings.QWI;
 
 import de.intevation.flys.java2d.ShapeUtils;
 
@@ -38,7 +38,7 @@
 implements   XYItemLabelGenerator
 {
     public interface LabelGenerator {
-        String createLabel(QW qw);
+        String createLabel(QWI qw);
     } // interface LabelGenerator
 
     public static class DateFormatLabelGenerator
@@ -59,7 +59,7 @@
         }
 
         @Override
-        public String createLabel(QW qw) {
+        public String createLabel(QWI qw) {
             Date date = qw.getDate();
             return date != null ? format.format(date) : "";
         }
@@ -71,7 +71,7 @@
     protected Date minDate;
     protected Date maxDate;
 
-    protected List<List<QW>> labels;
+    protected List<List<QWI>> labels;
 
     protected Rectangle2D area;
 
@@ -81,7 +81,7 @@
         new HashMap<ShapeRenderer.Entry, Integer>();
 
     public QWSeriesCollection() {
-        labels = new ArrayList<List<QW>>();
+        labels = new ArrayList<List<QWI>>();
         labelGenerator = SIMPLE_GENERATOR;
     }
 
@@ -90,7 +90,7 @@
         this.labelGenerator = labelGenerator;
     }
 
-    protected static ShapeRenderer.Entry classify(QW qw) {
+    protected static ShapeRenderer.Entry classify(QWI qw) {
         boolean interpolated = qw.getInterpolated();
 
         Shape shape = interpolated
@@ -103,7 +103,7 @@
         return new ShapeRenderer.Entry(shape, color, filled);
     }
 
-    public void add(QW qw) {
+    public void add(QWI qw) {
 
         ShapeRenderer.Entry key = classify(qw);
 
@@ -116,7 +116,7 @@
             knownShapes.put(key, seriesNo);
             series = new XYSeries(seriesNo, false);
             addSeries(series);
-            labels.add(new ArrayList<QW>());
+            labels.add(new ArrayList<QWI>());
         }
         else {
             series = getSeries(seriesNo);
@@ -130,7 +130,7 @@
         extendArea(qw);
     }
 
-    protected void extendDateRange(QW qw) {
+    protected void extendDateRange(QWI qw) {
         Date date = qw.getDate();
         if (date != null) {
             if (minDate == null) {
@@ -147,7 +147,7 @@
         }
     }
 
-    protected void extendArea(QW qw) {
+    protected void extendArea(QWI qw) {
         if (area == null) {
             area = new Rectangle2D.Double(
                 qw.getQ(), qw.getW(), 0d, 0d);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Sat Sep 08 13:36:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Sat Sep 08 14:19:40 2012 +0000
@@ -14,7 +14,7 @@
 import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.model.fixings.FixFunction;
 import de.intevation.flys.artifacts.model.fixings.FixWQCurveFacet;
-import de.intevation.flys.artifacts.model.fixings.QW;
+import de.intevation.flys.artifacts.model.fixings.QWI;
 import de.intevation.flys.artifacts.model.fixings.QWD;
 import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.exports.ChartGenerator;
@@ -200,7 +200,7 @@
     protected void doReferenceEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
        logger.debug("doReferenceEventsOut");
 
-       QW qwd = (QW)aaf.getData(context);
+       QWI qwd = (QWI)aaf.getData(context);
        if(qwd != null) {
             XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
             List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>();
@@ -261,7 +261,7 @@
     protected void doOutlierOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
         logger.debug("doOutlierOut");
 
-        QW[] qws = (QW[])aaf.getData(context);
+        QWI[] qws = (QWI[])aaf.getData(context);
         addQWSeries(qws, aaf, doc, visible);
     }
 
@@ -431,30 +431,39 @@
     }
 
 
-    protected void addQWSeries(QW[] qws, ArtifactAndFacet aaf, Document theme, boolean visible) {
-         if(qws != null) {
-            XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
-            List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>();
-
-            DateFormat dateFormat = DateFormat.getDateInstance(
-                DateFormat.SHORT);
-
-            for(QW qw : qws) {
-                series.add(qw.getQ(), qw.getW());
+    protected void addQWSeries(
+        QWI []           qws,
+        ArtifactAndFacet aaf,
+        Document         theme,
+        boolean          visible
+    ) {
+        if (qws == null) {
+            return;
+        }
 
-                XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
-                    dateFormat.format(qw.getDate()),
-                    qw.getQ(),
-                    qw.getW());
-                textAnnos.add(anno);
-            }
+        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
+        List<XYTextAnnotation> textAnnos =
+            new ArrayList<XYTextAnnotation>(qws.length);
 
-            addAxisSeries(series, 0, visible);
-            if(visible && ThemeUtil.parseShowPointLabel(theme)) {
-                FLYSAnnotation flysAnno = new FLYSAnnotation(null, null, null, theme);
-                flysAnno.setTextAnnotations(textAnnos);
-                addAnnotations(flysAnno);
-            }
+        DateFormat dateFormat = DateFormat.getDateInstance(
+            DateFormat.SHORT);
+
+        for (QWI qw: qws) {
+            series.add(qw.getQ(), qw.getW());
+
+            XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
+                dateFormat.format(qw.getDate()),
+                qw.getQ(),
+                qw.getW());
+            textAnnos.add(anno);
+        }
+
+        addAxisSeries(series, 0, visible);
+        if (visible && ThemeUtil.parseShowPointLabel(theme)) {
+            FLYSAnnotation flysAnno =
+                new FLYSAnnotation(null, null, null, theme);
+            flysAnno.setTextAnnotations(textAnnos);
+            addAnnotations(flysAnno);
         }
     }
 

http://dive4elements.wald.intevation.org