changeset 3760:312870fded7e

Added result objects for minfo bed quality calculation. flys-artifacts/trunk@5459 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 13 Sep 2012 13:51:00 +0000
parents e54f8dc222cf
children 066e2b4d69ca
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedQualityAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/BedQualityCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedBedQualityResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedLoadBedQualityResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedQualityCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedQualityResult.java
diffstat 7 files changed, 331 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Sep 13 13:47:02 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Sep 13 13:51:00 2012 +0000
@@ -1,3 +1,17 @@
+2012-09-13  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/access/BedQualityAccess.java:
+	  Added getter for calculation parameters.
+
+	* src/main/java/de/intevation/flys/artifacts/model/BedQualityCalculation.java:
+	  Removed. Moved to package de.intevation.flys.artifacts.model.minfo.
+
+	* src/main/java/de/intevation/flys/artifacts/model/minfo/BedQualityResult.java,
+	  src/main/java/de/intevation/flys/artifacts/model/minfo/BedLoadBedQualityResult.java,
+	  src/main/java/de/intevation/flys/artifacts/model/minfo/BedBedQualityResult.java,
+	  src/main/java/de/intevation/flys/artifacts/model/minfo/BedQualityCalculation.java:
+	  New. Calculation results and some more calculation stub.
+
 2012-09-13  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/conf/artifacts/minfo.xml,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedQualityAccess.java	Thu Sep 13 13:47:02 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedQualityAccess.java	Thu Sep 13 13:51:00 2012 +0000
@@ -1,11 +1,70 @@
 package de.intevation.flys.artifacts.access;
 
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+
 import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.model.DateRange;
+
 
 public class BedQualityAccess extends Access {
 
+    private Double from;
+    private Double to;
+    private String river;
+    private List<DateRange> ranges;
+
     public BedQualityAccess(FLYSArtifact artifact) {
         super(artifact);
     }
+
+    public double getFrom() {
+        if (from == null) {
+            from = getDouble("ld_from");
+        }
+        return from.doubleValue();
+    }
+
+    public double getTo() {
+        if (to == null) {
+            to = getDouble("ld_to");
+        }
+        return to.doubleValue();
+    }
+
+    public String getRiver() {
+        if (river == null) {
+            river = getString("river");
+        }
+        return river;
+    }
+
+    public List<DateRange> getDateRanges() {
+        if (ranges == null) {
+            ranges = extractRanges(getString("periods"));
+        }
+        return ranges;
+    }
+
+    private List<DateRange> extractRanges(String dateString) {
+        List<DateRange> list = new LinkedList<DateRange>();
+        String[] dates = dateString.split(";");
+        for (String s : dates) {
+            String[] pair = s.split(",");
+            try {
+                long l1      = Long.parseLong(pair[0]);
+                long l2      = Long.parseLong(pair[1]);
+                Date first   = new Date(l1);
+                Date second  = new Date(l2);
+                DateRange dr = new DateRange(first, second);
+                list.add(dr);
+            }
+            catch (NumberFormatException nfe) {
+                continue;
+            }
+        }
+        return list;
+    }
 }
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
\ No newline at end of file
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/BedQualityCalculation.java	Thu Sep 13 13:47:02 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-package de.intevation.flys.artifacts.model;
-
-import org.apache.log4j.Logger;
-
-import de.intevation.flys.artifacts.access.BedQualityAccess;
-
-public class BedQualityCalculation extends Calculation {
-
-    private static final Logger logger = Logger.getLogger(BedQualityCalculation.class);
-
-    public CalculationResult calculate(BedQualityAccess access) {
-        logger.info("BedQualityCalculation.calculate");
-
-        // TODO calculate
-        Object result = null;
-
-        return new CalculationResult(result, this);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedBedQualityResult.java	Thu Sep 13 13:51:00 2012 +0000
@@ -0,0 +1,69 @@
+package de.intevation.flys.artifacts.model.minfo;
+
+import de.intevation.flys.artifacts.model.DateRange;
+
+
+public class BedBedQualityResult
+extends BedQualityResult {
+
+    protected double depth1;
+    protected double depth2;
+    protected double porosityCap;
+    protected double porositySub;
+    protected double loadDensityCap;
+    protected double loadDensitySub;
+
+    public BedBedQualityResult(
+        DIAMETER_TYPE type,
+        double diameter,
+        double km,
+        DateRange range,
+        double depth1,
+        double depth2,
+        double porosityCap,
+        double porositySub,
+        double loadDensityCap,
+        double loadDensitySub
+    ) {
+        super(type, diameter, km, range);
+        this.depth1 = depth1;
+        this.depth2 = depth2;
+        this.porosityCap = porosityCap;
+        this.loadDensitySub = porositySub;
+        this.loadDensityCap = loadDensityCap;
+        this.loadDensitySub = loadDensitySub;
+    }
+
+    public double getPorosityCap() {
+        return porosityCap;
+    }
+
+    public void setPorosityCap(double porosityCap) {
+        this.porosityCap = porosityCap;
+    }
+
+    public double getPorositySub() {
+        return porositySub;
+    }
+
+    public void setPorositySub(double porositySub) {
+        this.porositySub = porositySub;
+    }
+
+    public double getLoadDensityCap() {
+        return loadDensityCap;
+    }
+
+    public void setLoadDensityCap(double loadDensityCap) {
+        this.loadDensityCap = loadDensityCap;
+    }
+
+    public double getLoadDensitySub() {
+        return loadDensitySub;
+    }
+
+    public void setLoadDensitySub(double loadDensitySub) {
+        this.loadDensitySub = loadDensitySub;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedLoadBedQualityResult.java	Thu Sep 13 13:51:00 2012 +0000
@@ -0,0 +1,7 @@
+package de.intevation.flys.artifacts.model.minfo;
+
+public class BedLoadBedQualityResult
+extends BedQualityResult 
+{
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedQualityCalculation.java	Thu Sep 13 13:51:00 2012 +0000
@@ -0,0 +1,103 @@
+package de.intevation.flys.artifacts.model.minfo;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.artifacts.access.BedQualityAccess;
+import de.intevation.flys.artifacts.model.Calculation;
+import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.DateRange;
+import de.intevation.flys.backend.SedDBSessionHolder;
+
+
+public class BedQualityCalculation extends Calculation {
+
+    private static final Logger logger = Logger
+        .getLogger(BedQualityCalculation.class);
+
+    protected String river;
+    protected double from;
+    protected double to;
+    protected List<DateRange> ranges;
+
+    public BedQualityCalculation() {
+    }
+
+    public CalculationResult calculate(BedQualityAccess access) {
+        logger.info("BedQualityCalculation.calculate");
+
+        String river = access.getRiver();
+        Double from = access.getFrom();
+        Double to = access.getTo();
+        List<DateRange> ranges = access.getDateRanges();
+
+        if (river == null) {
+            // TODO: i18n
+            addProblem("minfo.missing.river");
+        }
+
+        if (from == null) {
+            // TODO: i18n
+            addProblem("minfo.missing.from");
+        }
+
+        if (to == null) {
+            // TODO: i18n
+            addProblem("minfo.missing.to");
+        }
+
+        if (ranges == null) {
+            // TODO: i18n
+            addProblem("minfo.missing.periods");
+        }
+
+        if (!hasProblems()) {
+            this.river = river;
+            this.from = from;
+            this.to = to;
+            this.ranges = ranges;
+
+            SedDBSessionHolder.acquire();
+            try {
+                return internalCalculate();
+            }
+            finally {
+                SedDBSessionHolder.release();
+            }
+        }
+
+        return new CalculationResult();
+    }
+
+    protected CalculationResult internalCalculate() {
+
+        List<BedQualityResult> results = new LinkedList<BedQualityResult>();
+        // Calculate for all time periods.
+        for (DateRange dr : ranges) {
+            QualityMeasurements bedMeasurements = QualityMeasurementFactory
+                .getBedMeasurements(river, from, to, dr.getFrom(), dr.getTo());
+            QualityMeasurements loadMeasurements = QualityMeasurementFactory
+                .getBedMeasurements(river, from, to, dr.getFrom(), dr.getTo());
+
+            BedQualityResult bedResult = calculateBed(bedMeasurements);
+            BedQualityResult loadResult = calculateBedload(loadMeasurements);
+            results.add(bedResult);
+            results.add(loadResult);
+        }
+
+        return new CalculationResult(
+            results.toArray(new BedQualityResult[results.size()]), this);
+    }
+
+    protected BedQualityResult calculateBed(QualityMeasurements qm) {
+        // TODO
+        return new BedQualityResult();
+    }
+
+    protected BedQualityResult calculateBedload(QualityMeasurements qm) {
+        // TODO
+        return new BedQualityResult();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedQualityResult.java	Thu Sep 13 13:51:00 2012 +0000
@@ -0,0 +1,78 @@
+package de.intevation.flys.artifacts.model.minfo;
+
+import java.io.Serializable;
+
+import de.intevation.flys.artifacts.model.DateRange;
+
+public class BedQualityResult implements Serializable {
+
+    public static enum DIAMETER_TYPE {
+        D90,
+        D84,
+        D80,
+        D75,
+        D70,
+        D60,
+        D50,
+        D40,
+        D30,
+        D25,
+        D20,
+        D16,
+        D10,
+        DMIN,
+        DMAX
+    }
+
+    protected DIAMETER_TYPE type;
+    protected double diameter;
+    protected double km;
+    protected DateRange dateRange;
+
+    public BedQualityResult () {
+    }
+
+    public BedQualityResult (
+        DIAMETER_TYPE type,
+        double diameter,
+        double km,
+        DateRange range
+    ) {
+        this.type = type;
+        this.diameter = diameter;
+        this.km = km;
+        this.dateRange = range;
+    }
+
+    public DIAMETER_TYPE getType() {
+        return this.type;
+    }
+
+    public double getKm() {
+        return this.km;
+    }
+
+    public double getDiameter() {
+        return this.diameter;
+    }
+
+    public DateRange getDateRange() {
+        return this.dateRange;
+    }
+        public void setType(DIAMETER_TYPE type) {
+        this.type = type;
+    }
+
+    public void setDiameter(double diameter) {
+        this.diameter = diameter;
+    }
+
+    public void setKm(double km) {
+        this.km = km;
+    }
+
+    public void setDateRange(DateRange dateRange) {
+        this.dateRange = dateRange;
+    }
+
+}

http://dive4elements.wald.intevation.org