[Dive4elements-commits] [PATCH] SedimentLoad*: Set range to fraction/fractions values

Wald Commits scm-commit at wald.intevation.org
Thu Jun 20 08:57:23 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1371711983 -7200
# Node ID 48e92ff57f236130084748cc05074df9ff510c1e
# Parent  be283f9bc0791ba8f269b4ee866a61fc133b3d8c
SedimentLoad*: Set range to fraction/fractions values.

diff -r be283f9bc079 -r 48e92ff57f23 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoad.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoad.java	Wed Jun 19 16:53:27 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoad.java	Thu Jun 20 09:06:23 2013 +0200
@@ -13,6 +13,8 @@
 import java.util.Set;
 
 import org.dive4elements.river.artifacts.model.NamedObjectImpl;
+import org.dive4elements.river.artifacts.model.Range;
+
 
 /** Gives access to Fractions (at kms). */
 public class SedimentLoad
@@ -89,68 +91,79 @@
         return kms.get(km);
     }
 
-    public void setCoarse(double km, double coarse) {
+    public void setCoarse(double km, double coarse, Range range) {
         if (kms.containsKey(km)) {
             kms.get(km).setCoarse(coarse);
         }
         else {
             SedimentLoadFraction f = new SedimentLoadFraction();
             f.setCoarse(coarse);
+            f.setCoarseRange(range);
             kms.put(km, f);
         }
     }
 
-    public void setFineMiddle(double km, double fine_middle) {
+    public void setFineMiddle(double km, double fine_middle, Range range) {
         if (kms.containsKey(km)) {
             kms.get(km).setFine_middle(fine_middle);
+            kms.get(km).setFineMiddleRange(range);
         }
         else {
             SedimentLoadFraction f = new SedimentLoadFraction();
             f.setFine_middle(fine_middle);
+            f.setFineMiddleRange(range);
             kms.put(km, f);
         }
     }
 
-    public void setSand(double km, double sand) {
+    public void setSand(double km, double sand, Range range) {
         if (kms.containsKey(km)) {
             kms.get(km).setSand(sand);
+            kms.get(km).setSandRange(range);
         }
         else {
             SedimentLoadFraction f = new SedimentLoadFraction();
             f.setSand(sand);
+            f.setSandRange(range);
             kms.put(km, f);
         }
     }
 
-    public void setSuspSand(double km, double susp_sand) {
+    public void setSuspSand(double km, double susp_sand, Range range) {
         if (kms.containsKey(km)) {
             kms.get(km).setSusp_sand(susp_sand);
+            kms.get(km).setSuspSandRange(range);
         }
         else {
             SedimentLoadFraction f = new SedimentLoadFraction();
             f.setSusp_sand(susp_sand);
+            f.setSuspSandRange(range);
             kms.put(km, f);
         }
     }
 
-    public void setSuspSandBed(double km, double susp_sand_bed) {
+    public void setSuspSandBed(double km, double susp_sand_bed, Range range) {
         if (kms.containsKey(km)) {
             kms.get(km).setSusp_sand_bed(susp_sand_bed);
+            kms.get(km).setSuspSandBedRange(range);
         }
         else {
             SedimentLoadFraction f = new SedimentLoadFraction();
             f.setSusp_sand_bed(susp_sand_bed);
+            f.setSuspSandBedRange(range);
             kms.put(km, f);
         }
     }
 
-    public void setSuspSediment(double km, double susp_sediment) {
+    public void setSuspSediment(double km, double susp_sediment, Range range) {
         if (kms.containsKey(km)) {
             kms.get(km).setSusp_sediment(susp_sediment);
+            kms.get(km).setSuspSedimentRange(range);
         }
         else {
             SedimentLoadFraction f = new SedimentLoadFraction();
             f.setSusp_sediment(susp_sediment);
+            f.setSuspSedimentRange(range);
             kms.put(km, f);
         }
     }
@@ -166,13 +179,15 @@
         }
     }
 
-    public void setTotal(double km, double total) {
+    public void setTotal(double km, double total, Range range) {
         if (kms.containsKey(km)) {
             kms.get(km).setTotal(total);
+            kms.get(km).setTotalRange(range);
         }
         else {
             SedimentLoadFraction f = new SedimentLoadFraction();
             f.setTotal(total);
+            f.setTotalRange(range);
             kms.put(km, f);
         }
     }
diff -r be283f9bc079 -r 48e92ff57f23 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Wed Jun 19 16:53:27 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Thu Jun 20 09:06:23 2013 +0200
@@ -155,42 +155,42 @@
                 SedimentLoadFraction f = load.getFraction(km);
                 if (f.getCoarse() > 0d) {
                     double c = resLoad.getFraction(km).getCoarse();
-                    resLoad.setCoarse(km, c + f.getCoarse());
+                    resLoad.setCoarse(km, c + f.getCoarse(), f.getCoarseRange());
                     cSum++;
                 }
                 if (f.getFine_middle() > 0d) {
                     double fm = resLoad.getFraction(km).getFine_middle();
-                    resLoad.setFineMiddle(km, fm + f.getFine_middle());
+                    resLoad.setFineMiddle(km, fm + f.getFine_middle(), f.getFineMiddleRange());
                     fmSum++;
                 }
                 if (f.getSand() > 0d) {
                     double s = resLoad.getFraction(km).getSand();
-                    resLoad.setSand(km, s + f.getSand());
+                    resLoad.setSand(km, s + f.getSand(), f.getSandRange());
                     sSum++;
                 }
                 if (f.getSusp_sand() > 0d) {
                     double s = resLoad.getFraction(km).getSusp_sand();
-                    resLoad.setSuspSand(km, s + f.getSusp_sand());
+                    resLoad.setSuspSand(km, s + f.getSusp_sand(), f.getSuspSandRange());
                     ssSum++;
                 }
                 if (f.getSusp_sand_bed() > 0d) {
                     double s = resLoad.getFraction(km).getSusp_sand_bed();
-                    resLoad.setSuspSandBed(km, s + f.getSusp_sand_bed());
+                    resLoad.setSuspSandBed(km, s + f.getSusp_sand_bed(), f.getSuspSandBedRange());
                     ssbSum++;
                 }
                 if (f.getSusp_sediment() > 0d) {
                     double s = resLoad.getFraction(km).getSusp_sediment();
-                    resLoad.setSuspSediment(km, s + f.getSusp_sediment());
+                    resLoad.setSuspSediment(km, s + f.getSusp_sediment(), f.getSuspSedimentRange());
                     sseSum++;
                 }
             }
             SedimentLoadFraction fr = resLoad.getFraction(km);
-            resLoad.setCoarse(km, fr.getCoarse()/cSum);
-            resLoad.setFineMiddle(km, fr.getFine_middle()/fmSum);
-            resLoad.setSand(km, fr.getSand()/sSum);
-            resLoad.setSuspSand(km, fr.getSusp_sand()/ssSum);
-            resLoad.setSuspSandBed(km, fr.getSusp_sand_bed()/ssbSum);
-            resLoad.setSuspSediment(km, fr.getSusp_sediment()/sseSum);
+            resLoad.setCoarse(km, fr.getCoarse()/cSum, fr.getCoarseRange());
+            resLoad.setFineMiddle(km, fr.getFine_middle()/fmSum, fr.getFineMiddleRange());
+            resLoad.setSand(km, fr.getSand()/sSum, fr.getSandRange());
+            resLoad.setSuspSand(km, fr.getSusp_sand()/ssSum, fr.getSuspSandRange());
+            resLoad.setSuspSandBed(km, fr.getSusp_sand_bed()/ssbSum, fr.getSuspSandBedRange());
+            resLoad.setSuspSediment(km, fr.getSusp_sediment()/sseSum, fr.getSuspSedimentRange());
         }
         resLoad.setDescription("");
         resLoad.setEpoch(true);
@@ -264,6 +264,7 @@
         return result;
     }
 
+    /** Add up the loads of a year. */
     private SedimentLoad calculateTotalLoad(SedimentLoad load, int year) {
         logger.debug("calculateTotalLoad");
         boolean problemThisYear = false;
@@ -319,7 +320,7 @@
                 fraction.getSand() +
                 fraction.getSusp_sand() +
                 fraction.getSusp_sediment();
-            load.setTotal(km, total);
+            load.setTotal(km, total, fraction.getTotalRange());
         }
         return load;
     }
@@ -337,13 +338,13 @@
             double bedSand = fraction.getSusp_sand_bed();
             double sediment = fraction.getSusp_sediment();
             double total = fraction.getTotal();
-            load.setCoarse(km, (coarse * dens));
-            load.setFineMiddle(km, (fineMiddle * dens));
-            load.setSand(km, (sand * dens));
-            load.setSuspSand(km, (suspSand * dens));
-            load.setSuspSandBed(km, (bedSand * dens));
-            load.setSuspSediment(km, (sediment * dens));
-            load.setTotal(km, (total * dens));
+            load.setCoarse(km, (coarse * dens), fraction.getCoarseRange());
+            load.setFineMiddle(km, (fineMiddle * dens), fraction.getFineMiddleRange());
+            load.setSand(km, (sand * dens), fraction.getSandRange());
+            load.setSuspSand(km, (suspSand * dens), fraction.getSuspSandRange());
+            load.setSuspSandBed(km, (bedSand * dens), fraction.getSuspSandBedRange());
+            load.setSuspSediment(km, (sediment * dens), fraction.getSuspSedimentRange());
+            load.setTotal(km, (total * dens), fraction.getTotalRange());
         }
         return load;
     }
diff -r be283f9bc079 -r 48e92ff57f23 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Wed Jun 19 16:53:27 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Thu Jun 20 09:06:23 2013 +0200
@@ -13,6 +13,8 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
@@ -22,7 +24,12 @@
 import org.hibernate.Session;
 import org.hibernate.type.StandardBasicTypes;
 
+import org.dive4elements.river.model.MeasurementStation;
+
 import org.dive4elements.river.artifacts.cache.CacheFactory;
+
+import org.dive4elements.river.artifacts.model.Range;
+import org.dive4elements.river.artifacts.model.RiverFactory;
 import org.dive4elements.river.artifacts.model.StaticSedimentLoadCacheKey;
 import org.dive4elements.river.backend.SessionHolder;
 
@@ -264,6 +271,22 @@
         Session session = SessionHolder.HOLDER.get();
         SQLQuery sqlQuery = null;
 
+        List<MeasurementStation> allStations = RiverFactory.getRiver(river).getMeasurementStations();
+        TreeMap<Double,MeasurementStation> floatStations = new TreeMap<Double, MeasurementStation>();
+        TreeMap<Double,MeasurementStation> suspStations = new TreeMap<Double, MeasurementStation>();
+        for (MeasurementStation measurementStation: allStations) {
+            if (measurementStation.getMeasurementType() == null ||
+                measurementStation.getRange() == null) {
+                continue;
+            }
+            if (measurementStation.getMeasurementType().equals("Schwebstoff")) {
+                suspStations.put(measurementStation.getRange().getA().doubleValue(), measurementStation);
+            }
+            else if (measurementStation.getMeasurementType().equals("Geschiebe")) {
+                floatStations.put(measurementStation.getRange().getA().doubleValue(), measurementStation);
+            }
+        }
+
         Calendar start = Calendar.getInstance();
         start.set(syear - 1, 11, 31);
         Calendar end = Calendar.getInstance();
@@ -289,12 +312,12 @@
                     (Date) row[1],
                     null,
                     false);
-            getValues("coarse", sqlQuery, load);
-            getValues("fine_middle", sqlQuery, load);
-            getValues("sand", sqlQuery, load);
-            getValues("suspended_sediment", sqlQuery, load);
-            getValues("susp_sand_bed", sqlQuery, load);
-            getValues("susp_sand", sqlQuery, load);
+            getValues("coarse", sqlQuery, load, floatStations);
+            getValues("fine_middle", sqlQuery, load, floatStations);
+            getValues("sand", sqlQuery, load, floatStations);
+            getValues("suspended_sediment", sqlQuery, load, suspStations);
+            getValues("susp_sand_bed", sqlQuery, load, suspStations);
+            getValues("susp_sand", sqlQuery, load, suspStations);
 
             return load;
         }
@@ -334,12 +357,12 @@
                 kms.add((Double)row[3]);
                 load.setLoadTotal((Double)row[3], (Double)row[2]);
             }
-            getValues("coarse", sqlQuery, load);
-            getValues("fine_middle", sqlQuery, load);
-            getValues("sand", sqlQuery, load);
-            getValues("suspended_sediment", sqlQuery, load);
-            getValues("susp_sand_bed", sqlQuery, load);
-            getValues("susp_sand", sqlQuery, load);
+            getValues("coarse", sqlQuery, load, floatStations);
+            getValues("fine_middle", sqlQuery, load, floatStations);
+            getValues("sand", sqlQuery, load, floatStations);
+            getValues("suspended_sediment", sqlQuery, load, suspStations);
+            getValues("susp_sand_bed", sqlQuery, load, suspStations);
+            getValues("susp_sand", sqlQuery, load, floatStations);
             return load;
         }
         return new SedimentLoad();
@@ -356,34 +379,51 @@
     protected static void getValues (
         String fraction,
         SQLQuery query,
-        SedimentLoad load
+        SedimentLoad load,
+        TreeMap<Double, MeasurementStation> stations
     ) {
         query.setString("grain", fraction);
         List<Object[]> results = query.list();
         for (int i = 0; i < results.size(); i++) {
             Object[] row = results.get(i);
             double km = (Double)row[3];
+            MeasurementStation station = stations.get(km);
+            MeasurementStation nextStation = stations.ceilingEntry(km + 0.1d).getValue();
+            Range range = null;
+            if (station == null) {
+                log.warn("No measurement station for " + fraction + " km " + km);
+            }
+            else {
+                if (nextRange != null)
+                    range = new Range(station.getRange().getA().doubleValue(),
+                        nextStation.getRange().getA().doubleValue());
+                else {
+                    // TODO end-of-river instead of B.
+                    range = new Range(station.getRange().getA().doubleValue(),
+                        station.getRange().getB().doubleValue());
+                }
+            }
             double v = -1;
             if (row[2] != null) {
                 v = ((Double)row[2]).doubleValue();
             }
             if (fraction.equals("coarse")) {
-                load.setCoarse(km, v);
+                load.setCoarse(km, v, range);
             }
             else if (fraction.equals("sand")) {
-                load.setSand(km, v);
+                load.setSand(km, v, range);
             }
             else if (fraction.equals("fine_middle")) {
-                load.setFineMiddle(km, v);
+                load.setFineMiddle(km, v, range);
             }
             else if (fraction.equals("suspended_sediment")) {
-                load.setSuspSediment(km, v);
+                load.setSuspSediment(km, v, range);
             }
             else if (fraction.equals("susp_sand")) {
-                load.setSuspSand(km, v);
+                load.setSuspSand(km, v, range);
             }
             else if (fraction.equals("susp_sand_bed")) {
-                load.setSuspSandBed(km, v);
+                load.setSuspSandBed(km, v, range);
             }
         }
     }


More information about the Dive4elements-commits mailing list