[PATCH] SINFO-TKH: definition der standard sohlhöhen jetzt mit Gültigkeitsstrecke. Definitionsdateien aufgeteilt in eine pro Gewässer

Wald Commits scm-commit at wald.intevation.org
Tue Jul 3 13:09:53 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1530616186 -7200
# Node ID aca5a7a57a3ae24763cc54c3a8a08eadfaedd501
# Parent  de55d9a94796cf116e2340c3ee6c823148c2d4db
SINFO-TKH: definition der standard sohlhöhen jetzt mit Gültigkeitsstrecke. Definitionsdateien aufgeteilt in eine pro Gewässer.

diff -r de55d9a94796 -r aca5a7a57a3a artifacts/doc/conf/sinfo_tkh_bedheights.properties
--- a/artifacts/doc/conf/sinfo_tkh_bedheights.properties	Tue Jul 03 13:00:56 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-# Konfigurationsdatei f\u00fcr die in der Berechnungsart SINFO-Transportk\u00f6rperh\u00f6hen zu verwendenden Sohlh\u00f6hen.
-# Die Datei ist im Charset 'ISO-8859-1' zu encodieren.
-# Jede Zeile entspricht: <gew\u00e4ssername> = <sohlh\u00f6he1>, <Sohlh\u00f6he2>, ...
-# Alle Daten beziehen sich auf die FLYS Datenbank (d4e Datenbank)
-# der <gew\u00e4ssername> entspricht dem Feld 'name' der Tabelle 'rivers'
-# die Sohlh\u00f6hen dem Feld 'description' aus der Tabelle 'bed_heights'
-# Leerzeichen im Ge\u00e4ssernamen m\u00fcssen mit u0020 kodiert werden.
-Beispielfluss=DGM-2004_Epoche-2-SOBEK  
-Beispiel\u0020fluss=DGM-2004_Epoche-2-SOBEK
\ No newline at end of file
diff -r de55d9a94796 -r aca5a7a57a3a artifacts/doc/conf/sinfo_tkh_sohlhoehen_Beispielfluss.properties
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/doc/conf/sinfo_tkh_sohlhoehen_Beispielfluss.properties	Tue Jul 03 13:09:46 2018 +0200
@@ -0,0 +1,15 @@
+# Konfigurationsdatei f\u00fcr die in der Berechnungsart SINFO-Transportk\u00f6rperh\u00f6hen zu verwendenden Sohlh\u00f6hen.
+# Je Gew\u00e4sser ist eine Datei mit Namen "sinfo_tkh_sohlhoehen_<Gew\u00e4ssername>.properties" anzulegen. Gro\u00df-/Kleinschriebung beim Gew\u00e4ssernamen ist zu beachten!
+# Die Datei ist im Charset 'ISO-8859-1' zu kodieren.
+
+# Die Datei definiert die Standardm\u00e4\u00dfig zu verwendenden Sohlh\u00f6hen und deren G\u00fcltigkeitsbereiche.
+# Pro Sohlh\u00f6he ist eine Zeile folgender Form anzulegen:
+# <Sohlh\u00f6he> = <von km>;<bis km>
+
+# 'Sohlh\u00f6he' entspriche dem Feld 'description' in der Tabelle 'bed_height' der D4E Datenbank.  
+# 'von km' entpsricht dem Start des G\u00fcltigkeitsbereichs in km
+# 'bis km' entpsricht dem Ende des G\u00fcltigkeitsbereichs in km
+
+# Der G\u00fcltigkeitsbereich schr\u00e4nkt den zu verwendenden Daten bereich der Sohlh\u00f6he f\u00fcr die TKH Berechnung ein, die Daten in der Datenbank k\u00f6nnen einen gr\u00f6\u00dferen G\u00fcltigkeitsbereich besitzen.
+# Leerzeichen im Namen der Sohlh\u00f6he m\u00fcssen mit u0020 kodiert werden.
+DGM-2004_Epoche-2-SOBEK = 0.0;182.4
diff -r de55d9a94796 -r aca5a7a57a3a artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/DefaultBedHeights.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/DefaultBedHeights.java	Tue Jul 03 13:00:56 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/DefaultBedHeights.java	Tue Jul 03 13:09:46 2018 +0200
@@ -10,17 +10,13 @@
 package org.dive4elements.river.artifacts.sinfo.tkhstate;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import java.util.Properties;
 
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberRange;
-import org.dive4elements.artifacts.common.utils.Config;
 import org.dive4elements.river.artifacts.model.Calculation;
+import org.dive4elements.river.artifacts.sinfo.tkhstate.DefaultBedHeightsConfig.DefaultBedHeight;
 import org.dive4elements.river.model.BedHeight;
 import org.dive4elements.river.model.Range;
 import org.dive4elements.river.model.River;
@@ -31,7 +27,7 @@
  * @author Gernot Belger
  */
 final class DefaultBedHeights {
-    private static final String CONFIG_FILE = "sinfo_tkh_bedheights.properties";
+
     private final River river;
 
     public DefaultBedHeights(final River river) {
@@ -39,9 +35,9 @@
     }
 
     public List<BedHeight> getBedHeights(final Calculation problems) {
-        final Collection<String> bedHeightNames = loadBedHeightDefaultsForRiver(this.river, problems);
+        final Collection<DefaultBedHeight> defaults = DefaultBedHeightsConfig.getDefaults(this.river, problems);
 
-        final List<BedHeight> defaultBedHeights = loadBedHeightsByName(this.river, bedHeightNames, problems);
+        final List<BedHeight> defaultBedHeights = loadBedHeightsByName(this.river, defaults, problems);
         if (defaultBedHeights.isEmpty()) {
             problems.addProblem("sinfo.bedheightsfinder.nobedheightsforriver", this.river.getName());
             return Collections.emptyList();
@@ -56,9 +52,9 @@
             final Range range = bedHeight.getRange();
             final NumberRange bedRange = new NumberRange(range.getA(), range.getB());
 
-            if (overlapsRange(bedRange, defaultBedHeights, i + 1)) {
+            if (overlapsRange(bedRange, defaultBedHeights, i + 1))
                 problems.addProblem("sinfo.bedheightsfinder.overlappingrange", bedHeight.getDescription());
-            } else
+            else
                 result.add(bedHeight);
         }
 
@@ -78,41 +74,25 @@
         return result;
     }
 
-    private static Collection<String> loadBedHeightDefaultsForRiver(final River river, final Calculation problems) {
 
-        try {
-            final Properties properties = Config.loadProperties(CONFIG_FILE);
-            final String value = properties.getProperty(river.getName());
-            final String[] split = StringUtils.split(StringUtils.trim(value), ',');
-            if (ArrayUtils.isEmpty(split)) {
-                problems.addProblem("sinfo.bedheightsfinder.configfile.missingriver", CONFIG_FILE, river.getName());
-                return Collections.emptyList();
-            }
+    private static List<BedHeight> loadBedHeightsByName(final River river, final Collection<DefaultBedHeight> defaults, final Calculation problems) {
 
-            return Arrays.asList(split);
-        }
-        catch (final Exception e) {
-            e.printStackTrace();
-            problems.addProblem("sinfo.bedheightsfinder.configfile.loaderror", CONFIG_FILE, e.getMessage());
-            return Collections.emptyList();
-        }
-    }
+        final List<BedHeight> bedHeights = new ArrayList<>(defaults.size());
 
-    private static List<BedHeight> loadBedHeightsByName(final River river, final Collection<String> bedHeightNames, final Calculation problems) {
+        for (final DefaultBedHeight heightDefault : defaults) {
 
-        final List<BedHeight> bedHeights = new ArrayList<>(bedHeightNames.size());
+            final String description = heightDefault.description;
+            try {
 
-        for (final String name : bedHeightNames) {
-            try {
-                final BedHeight bedHeight = BedHeight.getBedHeightByDescription(river, name);
+                final BedHeight bedHeight = BedHeight.getBedHeightByDescription(river, description, heightDefault.startKm, heightDefault.endKm);
                 if (bedHeight == null)
-                    problems.addProblem("sinfo.bedheightsfinder.missingdescription", river.getName(), name);
+                    problems.addProblem("sinfo.bedheightsfinder.missingdescription", river.getName(), description);
                 else
                     bedHeights.add(bedHeight);
             }
             catch (final Exception e) {
                 e.printStackTrace();
-                problems.addProblem("sinfo.bedheightsfinder.missingdescription", river.getName(), name);
+                problems.addProblem("sinfo.bedheightsfinder.missingdescription", river.getName(), description);
             }
         }
 
diff -r de55d9a94796 -r aca5a7a57a3a artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/DefaultBedHeightsConfig.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/DefaultBedHeightsConfig.java	Tue Jul 03 13:09:46 2018 +0200
@@ -0,0 +1,104 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.artifacts.sinfo.tkhstate;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+import org.dive4elements.artifacts.common.utils.Config;
+import org.dive4elements.river.artifacts.model.Calculation;
+import org.dive4elements.river.model.River;
+
+/**
+ * Represents the contents of the 'bedheights.properties' files.
+ *
+ * @author Gernot Belger
+ */
+final class DefaultBedHeightsConfig {
+
+    private static final String CONFIG_FILE = "sinfo_tkh_sohlhoehen_%s.properties";
+
+
+    public static class DefaultBedHeight {
+
+        public final String description;
+        public final double startKm;
+        public final double endKm;
+
+        public DefaultBedHeight(final String description, final double startKm, final double endKm) {
+            this.description = description;
+            this.startKm = startKm;
+            this.endKm = endKm;
+        }
+    }
+
+    private static DefaultBedHeightsConfig INSTANCE = new DefaultBedHeightsConfig();
+
+    public static synchronized Collection<DefaultBedHeight> getDefaults(final River river, final Calculation problems) {
+        return INSTANCE.getBedHeightDefaultsForRiver(river, problems);
+    }
+
+    private final Map<String, Collection<DefaultBedHeight>> cache = new HashMap<>();
+
+    private DefaultBedHeightsConfig() {
+    }
+
+
+    private synchronized Collection<DefaultBedHeight> getBedHeightDefaultsForRiver(final River river, final Calculation problems) {
+
+        final String rivername = river.getName();
+        if (!this.cache.containsKey(rivername)) {
+            final Collection<DefaultBedHeight> newDefaults = loadBedHeightDefaultsForRiver(river, problems);
+            this.cache.put(rivername, null);
+            return newDefaults;
+        }
+
+        return this.cache.get(rivername);
+    }
+
+    private static Collection<DefaultBedHeight> loadBedHeightDefaultsForRiver(final River river, final Calculation problems) {
+
+        try {
+            final String rivername = river.getName();
+            final String filename = String.format(CONFIG_FILE, rivername);
+
+            final Properties properties = Config.loadProperties(filename);
+
+            final Set<String> keys = properties.stringPropertyNames();
+
+            final Collection<DefaultBedHeight> defaults = new ArrayList<>(keys.size());
+
+            for (final String key : keys) {
+
+                final String value = properties.getProperty(key);
+
+                final String[] split = StringUtils.split(StringUtils.trim(value), ';');
+
+                final double startKm = Double.parseDouble(split[0]);
+                final double endKm = Double.parseDouble(split[1]);
+
+                defaults.add(new DefaultBedHeight(key, startKm, endKm));
+            }
+
+            return defaults;
+        }
+        catch (final Exception e) {
+            e.printStackTrace();
+            problems.addProblem("sinfo.bedheightsfinder.configfile.loaderror", CONFIG_FILE, e.getMessage());
+            return Collections.emptyList();
+        }
+    }
+}
\ No newline at end of file
diff -r de55d9a94796 -r aca5a7a57a3a artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties	Tue Jul 03 13:00:56 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties	Tue Jul 03 13:09:46 2018 +0200
@@ -802,7 +802,6 @@
 sinfo.bedheightsfinder.badrange = Invalid range for bed heights {0}.
 sinfo.bedheightsfinder.overlappingrange = Range of bed height {0} overlaps with other ranges.
 sinfo.bedheightsfinder.missingdescription = River {0} has no bed heights with description {1}
-sinfo.bedheightsfinder.configfile.missingriver = River not defined in config file ''{0}'': {1}
 sinfo.bedheightsfinder.configfile.loaderror = Failed to load config file ''{0}'': {1}
 sinfo.bedheightsfinder.notfound = Failed to access sounding with id ''{0}''
 sinfo.bedheightsfinder.empty = The bed heights do not contain any values for the selected calculation range
diff -r de55d9a94796 -r aca5a7a57a3a artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties	Tue Jul 03 13:00:56 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties	Tue Jul 03 13:09:46 2018 +0200
@@ -802,7 +802,6 @@
 sinfo.bedheightsfinder.badrange = Ung\u00fcltige -range- f\u00fcr Sohlh\u00f6hen {0}.
 sinfo.bedheightsfinder.overlappingrange = -Range- der Sohlh\u00f6hen {0} \u00fcberlappt andere Sohlh\u00f6hen.
 sinfo.bedheightsfinder.missingdescription = Gew\u00e4sser {0} hat keine Sohlh\u00f6he mit Bezeichnung {1}
-sinfo.bedheightsfinder.configfile.missingriver = Gew\u00e4sser  {1} ist in Konfigurationsdatei {0} nicht definiert.
 sinfo.bedheightsfinder.configfile.loaderror = Fehler beim Laden der Konfigurationsdatei ''{0}'': {1}
 sinfo.bedheightsfinder.notfound = Keine Sohlh\u00f6he mit id ''{0}'' vorhanden
 sinfo.bedheightsfinder.empty = Die Sohlh\u00f6hen enthalten keine Werte f\u00fcr die gew\u00e4hlte Berechnungsstrecke 
diff -r de55d9a94796 -r aca5a7a57a3a backend/src/main/java/org/dive4elements/river/model/BedHeight.java
--- a/backend/src/main/java/org/dive4elements/river/model/BedHeight.java	Tue Jul 03 13:00:56 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/BedHeight.java	Tue Jul 03 13:09:46 2018 +0200
@@ -243,7 +243,8 @@
         return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null;
     }
 
-    public static BedHeight getBedHeightByDescription(final River river, final String description) {
+    // TODO Do km range filtering in SQL statement
+    public static BedHeight getBedHeightByDescription(final River river, final String description, final double startKm, final double endKm) {
 
         final Session session = SessionHolder.HOLDER.get();
 
@@ -255,5 +256,4 @@
 
         return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null;
     }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
\ No newline at end of file
+}
\ No newline at end of file


More information about the Dive4Elements-commits mailing list