changeset 6754:f3730c727473 double-precision

merged changes from default into double-precision branch
author Tom Gottfried <tom@intevation.de>
date Tue, 06 Aug 2013 11:04:12 +0200
parents b5b54e8da1cf (current diff) e032e9e6d09e (diff)
children 54addebfcda4
files
diffstat 12 files changed, 120 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/meta-data.xml	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/doc/conf/meta-data.xml	Tue Aug 06 11:04:12 2013 +0200
@@ -87,6 +87,9 @@
                   <dc:when test="$out = 'fix_longitudinal_section_curve'">
                     <dc:call-macro name="annotations"/>
                   </dc:when>
+                  <dc:when test="$out = 'bedheight_middle'">
+                    <dc:call-macro name="annotations"/>
+                  </dc:when>
                   <dc:when test="$out = 'bed_difference_epoch'">
                     <dc:call-macro name="annotations"/>
                     <dc:call-macro name="basedata_6_delta_w"/>
--- a/artifacts/doc/conf/themes/default.xml	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/doc/conf/themes/default.xml	Tue Aug 06 11:04:12 2013 +0200
@@ -834,11 +834,26 @@
     <!-- MIDDLE BED HEIGHT -->
     <theme name="MiddleBedHeightSingle">
         <inherits>
-            <inherit from="LongitudinalSection" />
+            <inherit from="Lines" />
+            <inherit from="Points" />
+            <inherit from="MinMaxPoints" />
+            <inherit from="Label" />
         </inherits>
         <fields>
+            <field name="showlines" type="boolean" display="Linie anzeigen"
+                default="true" />
+            <field name="linesize" type="int" display="Liniendicke"
+                default="1" />
+            <field name="linetype" type="Dash" display="Linienart"
+                default="10" />
             <field name="linecolor" type="Color" display="Linienfarbe"
-                default="204, 204, 204" />
+                />
+            <field name="showlinelabel" type="boolean"
+                display="Beschriftung anzeigen" default="false" />
+            <field name="showpoints" type="boolean" display="Punkte anzeigen"
+                default="false" />
+            <field name="showpointlabel" type="boolean"
+                display="Punktbeschriftung anzeigen" default="false" hints="hidden" />
         </fields>
     </theme>
 
@@ -1124,7 +1139,7 @@
                 display="Beschriftung anzeigen" default="false" hints="hidden" />
         </fields>
     </theme>
-     <theme name="SedimentLoadFineTotalLoad">
+     <theme name="SedimentLoadTotalLoad">
         <inherits>
             <inherit from="LongitudinalSection" />
         </inherits>
--- a/artifacts/doc/conf/themes/second.xml	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/doc/conf/themes/second.xml	Tue Aug 06 11:04:12 2013 +0200
@@ -834,11 +834,26 @@
     <!-- MIDDLE BED HEIGHT -->
     <theme name="MiddleBedHeightSingle">
         <inherits>
-            <inherit from="LongitudinalSection" />
+            <inherit from="Lines" />
+            <inherit from="Points" />
+            <inherit from="MinMaxPoints" />
+            <inherit from="Label" />
         </inherits>
         <fields>
+            <field name="showlines" type="boolean" display="Linie anzeigen"
+                default="true" />
+            <field name="linesize" type="int" display="Liniendicke"
+                default="2" />
+            <field name="linetype" type="Dash" display="Linienart"
+                default="10" />
             <field name="linecolor" type="Color" display="Linienfarbe"
-                default="204, 204, 204" />
+                />
+            <field name="showlinelabel" type="boolean"
+                display="Beschriftung anzeigen" default="false" />
+            <field name="showpoints" type="boolean" display="Punkte anzeigen"
+                default="false" />
+            <field name="showpointlabel" type="boolean"
+                display="Punktbeschriftung anzeigen" default="false" hints="hidden" />
         </fields>
     </theme>
 
@@ -1124,7 +1139,7 @@
                 display="Beschriftung anzeigen" default="false" hints="hidden" />
         </fields>
     </theme>
-     <theme name="SedimentLoadFineTotalLoad">
+     <theme name="SedimentLoadTotalLoad">
         <inherits>
             <inherit from="LongitudinalSection" />
         </inherits>
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Tue Aug 06 11:04:12 2013 +0200
@@ -36,6 +36,7 @@
     protected double kmUp;
     protected double kmLow;
     protected int[] period;
+    /** Years of chosen epochs. */
     protected int[][] epoch;
     protected String unit;
 
@@ -234,6 +235,7 @@
         return result;
     }
 
+    /** Calculate/Fetch values at off. epochs. */
     private SedimentLoadResult calculateOffEpoch(int i) {
         SedimentLoad load = SedimentLoadFactory.getLoadWithData(
             this.river,
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Tue Aug 06 11:04:12 2013 +0200
@@ -29,6 +29,7 @@
 import org.hibernate.Session;
 import org.hibernate.type.StandardBasicTypes;
 
+
 /** Pull Sediment Loads out of db. */
 public class SedimentLoadFactory
 {
@@ -201,6 +202,10 @@
         return values;
     }
 
+    /**
+     * Get a sedimentLoad filled with data from db (or cache).
+     * @param type "epoch","off_epoch" or "single"
+     */
     public static SedimentLoad getLoadWithData(
         String river,
         String type,
@@ -338,7 +343,7 @@
     /**
      * Get sediment loads from db.
      * @param river the river
-     * @param type the sediment load type (year or epoch)
+     * @param type the sediment load type (year, epoch or off_epoch)
      * @return according sediment loads.
      */
     public static SedimentLoad getSedimentLoadWithDataUncached(
@@ -406,10 +411,13 @@
             return load;
         }
         else if (type.equals("off_epoch")) {
+            // Set calendars to fetch the epochs by their start and end
+            // dates.
             Calendar toStart = Calendar.getInstance();
             toStart.set(eyear - 1, 11, 31);
             Calendar toEnd = Calendar.getInstance();
-            toEnd.set(eyear+1, 11, 31);
+            toEnd.set(eyear+1, 00, 01);
+            // Set query parameters.
             sqlQuery = session.createSQLQuery(SQL_SELECT_EPOCHS_DATA)
                 .addScalar("description", StandardBasicTypes.STRING)
                 .addScalar("startYear", StandardBasicTypes.DATE)
@@ -422,33 +430,38 @@
             sqlQuery.setDouble("endKm", endKm);
             sqlQuery.setDate("sbegin", start.getTime());
             sqlQuery.setDate("send", end.getTime());
-            sqlQuery.setDate("ebegin",toStart.getTime());
+            sqlQuery.setDate("ebegin", toStart.getTime());
             sqlQuery.setDate("eend", toEnd.getTime());
             sqlQuery.setString("grain", "total");
 
             List<Object[]> results = null;
             results = sqlQuery.list();
 
-            SedimentLoad load = new SedimentLoad();
-            Object[] row = results.get(0);
-            load = new SedimentLoad(
-                    (String) row[0],
-                    (Date) row[1],
-                    (Date) row[4],
-                    true,
-                    (String)row[5]);
-            TDoubleArrayList kms = new TDoubleArrayList();
-            for (int i = 0; i < results.size(); i++) {
-                row = results.get(i);
-                kms.add((Double)row[3]);
-                load.setLoadTotal((Double)row[3], (Double)row[2]);
+            SedimentLoad load = null;
+            if (results.isEmpty()) {
+                log.warn("No total results for off-epoch");
             }
-            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, floatStations);
-            getValues("susp_sand", sqlQuery, load, floatStations);
+            else {
+                Object[] row = results.get(0);
+                load = new SedimentLoad(
+                        (String) row[0],
+                        (Date) row[1],
+                        (Date) row[4],
+                        true,
+                        (String)row[5]);
+                TDoubleArrayList kms = new TDoubleArrayList();
+                for (int i = 0; i < results.size(); i++) {
+                    row = results.get(i);
+                    kms.add((Double)row[3]);
+                    load.setLoadTotal((Double)row[3], (Double)row[2]);
+                }
+            }
+            load = getValues("coarse", sqlQuery, load, floatStations);
+            load = getValues("fine_middle", sqlQuery, load, floatStations);
+            load = getValues("sand", sqlQuery, load, floatStations);
+            load = getValues("suspended_sediment", sqlQuery, load, suspStations);
+            load = getValues("susp_sand_bed", sqlQuery, load, floatStations);
+            load = getValues("susp_sand", sqlQuery, load, floatStations);
             return load;
         }
         return new SedimentLoad();
@@ -457,12 +470,15 @@
 
     /**
      * Run query with grain parameter set to fraction, feed result into
-     * load.
+     * load. Create load if null.
+     *
      * @param fraction value to set 'grain' parameter in query to.
      * @param query query in which to set 'grain' parameter and run.
-     * @param load[out] SedimentLoad which to populate with values.
+     * @param load[out] SedimentLoad which to populate with values. if null
+     *                  and values are found, return a new load.
+     * @return param load or new load if null.
      */
-    protected static void getValues (
+    protected static SedimentLoad getValues (
         String fraction,
         SQLQuery query,
         SedimentLoad load,
@@ -470,6 +486,18 @@
     ) {
         query.setString("grain", fraction);
         List<Object[]> results = query.list();
+
+        // We have the first results for this query, create new load.
+        if (!results.isEmpty() && load == null) {
+           Object[] row = results.get(0);
+           load = new SedimentLoad(
+                   (String) row[0],
+                   (Date) row[1],
+                   (Date) row[4],
+                   true,
+                   (String)row[5]);
+        }
+
         for (int i = 0; i < results.size(); i++) {
             Object[] row = results.get(i);
             double km = (Double)row[3];
@@ -516,6 +544,8 @@
                 load.setSuspSandBed(km, v, range);
             }
         }
+
+        return load;
     }
 
     public static SedimentLoad getLoadUnknown(
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java	Tue Aug 06 11:04:12 2013 +0200
@@ -28,7 +28,6 @@
 import java.util.List;
 
 import org.jfree.chart.axis.NumberAxis;
-import org.jfree.chart.plot.XYPlot;
 import org.jfree.data.xy.XYSeries;
 
 import org.apache.log4j.Logger;
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java	Tue Aug 06 11:04:12 2013 +0200
@@ -72,9 +72,12 @@
      * Returns the PNP (Datum) of gauge, if at gauge, 0 otherwise.
      */
     public static double getCurrentGaugeDatum(double km, D4EArtifact artifact, double tolerance) {
-        // Code borrowed from FixATWriter.
-        Gauge gauge = RiverUtils.getGauge(artifact);
+        // Look if there is a gauge at chosen km:
+        // Get gauge which is defined for km
+        Gauge gauge =
+            RiverUtils.getRiver(artifact).determineGauge(km-0.1d, km+0.1d);
         double subtractPNP = 0d;
+        // Compare to km.
         if (Math.abs(km - gauge.getStation().doubleValue()) < tolerance) {
             subtractPNP = gauge.getDatum().doubleValue();
         }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesCurveGenerator.java	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesCurveGenerator.java	Tue Aug 06 11:04:12 2013 +0200
@@ -16,11 +16,6 @@
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.WKms;
 
-import org.dive4elements.river.exports.StyledSeriesBuilder;
-import org.dive4elements.river.jfree.StyledXYSeries;
-import org.dive4elements.river.artifacts.model.minfo.MorphologicWidth;
-
-
 import org.dive4elements.river.exports.process.BedDiffYearProcessor;
 import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor;
 import org.dive4elements.river.exports.process.BedheightProcessor;
@@ -28,7 +23,6 @@
 
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.plot.XYPlot;
-import org.jfree.data.xy.XYSeries;
 import org.w3c.dom.Document;
 
 
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDiffHeightYearGenerator.java	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDiffHeightYearGenerator.java	Tue Aug 06 11:04:12 2013 +0200
@@ -9,14 +9,12 @@
 package org.dive4elements.river.exports.minfo;
 
 import org.apache.log4j.Logger;
-import org.jfree.data.xy.XYSeries;
 import org.w3c.dom.Document;
 
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.minfo.BedDifferencesResult;
-import org.dive4elements.river.exports.StyledSeriesBuilder;
 import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor;
 import org.dive4elements.river.exports.process.KMIndexProcessor;
 import org.dive4elements.river.exports.process.Processor;
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceYearGenerator.java	Mon Aug 05 18:39:12 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceYearGenerator.java	Tue Aug 06 11:04:12 2013 +0200
@@ -21,7 +21,6 @@
 import org.dive4elements.river.artifacts.model.minfo.BedDifferencesResult;
 import org.dive4elements.river.artifacts.model.minfo.MorphologicWidth;
 import org.dive4elements.river.exports.StyledSeriesBuilder;
-import org.dive4elements.river.exports.fixings.FixChartGenerator;
 import org.dive4elements.river.exports.process.BedDiffYearProcessor;
 import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor;
 import org.dive4elements.river.exports.process.KMIndexProcessor;
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java	Mon Aug 05 18:39:12 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java	Tue Aug 06 11:04:12 2013 +0200
@@ -199,9 +199,12 @@
     }
 
 
-    /** Handle one line of data, add one value for all columns. */
+    /** Handle one line of data, add one value for all columns.
+     * @param line the line to parse
+     */
     private void handleDataLine(String line) {
-        String[] cols = line.split(SEPERATOR_CHAR);
+        // Split by separator, do not exclude trailing empty string.
+        String[] cols = line.split(SEPERATOR_CHAR, -1);
 
         if (cols == null || cols.length < 2) {
             log.warn("skip invalid waterlevel-diff line: '" + line + "'");
@@ -209,6 +212,8 @@
         }
 
         try {
+            // The first value in a line like 12,9;4,3;4,5 is the station, later
+            // real values.
             Double station = nf.parse(cols[0]).doubleValue();
 
             for (int i = 0; i < columns.length; i++) {
@@ -221,13 +226,15 @@
 
                 String value = cols[idx];
 
-                try {
-                    columns[i].addColumnValue(
-                        new BigDecimal(station),
-                        new BigDecimal(nf.parse(value).doubleValue()));
-                }
-                catch (ParseException pe) {
-                    log.warn("Could not parse value: '" + value + "'");
+                if (value != null && !value.equals("")) {
+                    try {
+                        columns[i].addColumnValue(
+                            new BigDecimal(station),
+                            new BigDecimal(nf.parse(value).doubleValue()));
+                    }
+                    catch (ParseException pe) {
+                        log.warn("Could not parse value: '" + value + "'");
+                    }
                 }
             }
         }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadOffEpochPanel.java	Mon Aug 05 18:39:12 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadOffEpochPanel.java	Tue Aug 06 11:04:12 2013 +0200
@@ -126,6 +126,7 @@
         return sedLoadTable;
     }
 
+    /** Get data via listgrid selection. */
     @Override
     public Data[] getData() {
         List<Data> data = new ArrayList<Data>();
@@ -151,6 +152,7 @@
         return data.toArray(new Data[data.size()]);
     }
 
+    /** Fetch load info from service and populate table. */
     protected void fetchSedimentLoadData() {
         Config config = Config.getInstance();
         String locale = config.getLocale ();
@@ -183,6 +185,7 @@
     }
 
 
+    /** Add record to input helper listgrid. */
     protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) {
         for(SedimentLoadInfoObject sl: sedLoad) {
             SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl);

http://dive4elements.wald.intevation.org