[PATCH 1 of 2] New columns for bed_height, tkh and depth_evolution, a few syntactic corrections for Oracle

Wald Commits scm-commit at wald.intevation.org
Fri Apr 27 17:42:56 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1524843312 -7200
# Node ID 1f63e9d3b0ec38c712039c7d81aeac7d320501b5
# Parent  efd2de78d1581bbcc6443f99dad1b1abb014c3fa
New columns for bed_height, tkh and depth_evolution, a few syntactic corrections for Oracle

diff -r efd2de78d158 -r 1f63e9d3b0ec backend/doc/schema/oracle-drop-sinfo-uinfo.sql
--- a/backend/doc/schema/oracle-drop-sinfo-uinfo.sql	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/doc/schema/oracle-drop-sinfo-uinfo.sql	Fri Apr 27 17:35:12 2018 +0200
@@ -44,8 +44,8 @@
 DROP SEQUENCE DAILY_DISCHARGE_VALUES_ID_SEQ;
 DROP SEQUENCE SALIX_ID_SEQ;
 DROP SEQUENCE SALIX_VALUES_ID_SEQ;
-DROP SEQUENCE SALIX_RANK_ID_SEQ;
-DROP SEQUENCE VEGETATION_TYPE_ID_SEQ;
+--DROP SEQUENCE SALIX_RANK_ID_SEQ;
+--DROP SEQUENCE VEGETATION_TYPE_ID_SEQ;
 DROP SEQUENCE VEGETATION_ID_SEQ;
 DROP SEQUENCE VEGETATION_ZONE_ID_SEQ;
 DROP SEQUENCE FLOW_DEPTH_ID_SEQ;
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/doc/schema/oracle-sinfo-uinfo.sql
--- a/backend/doc/schema/oracle-sinfo-uinfo.sql	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/doc/schema/oracle-sinfo-uinfo.sql	Fri Apr 27 17:35:12 2018 +0200
@@ -3,26 +3,50 @@
 
 --Add new column wsts.sinfo_selection
 
-ALTER TABLE wsts ADD COLUMN sinfo_selection CHAR(1) CHECK((sinfo_selection IS NULL) OR (sinfo_selection IN ('W','Q')));
+ALTER TABLE wsts ADD (
+  sinfo_selection CHAR(1) CHECK((sinfo_selection IS NULL) OR (sinfo_selection IN ('W','Q')))
+);
 COMMENT ON COLUMN wsts.sinfo_selection IS 'Whether and how the WST series is selected within S-INFO calculation types ("W"=without-Q-group, "Q"=with-Q-group, NULL=not-selectable)' ;
 
 
 --Add new columns bed_height.sounding_width_info and bed_height.comment
 
-ALTER TABLE bed_height ADD COLUMN sounding_width_info VARCHAR2(256);
+ALTER TABLE bed_height ADD (
+  sounding_width_info VARCHAR2(256),
+  "comment" VARCHAR2(256)
+);
 COMMENT ON COLUMN bed_height.sounding_width_info IS 'File header line info "ausgewertete Peilbreite"' ;
-
-ALTER TABLE bed_height ADD COLUMN "comment" VARCHAR2(256);
 COMMENT ON COLUMN bed_height."comment" IS 'File header line info "weitere Bemerkungen"' ;
 
 
 --Add new columns bed_height_values.min_height (Talweg) and bed_height_values.max_height (Kammlage) (same type as existing height column)
 
-ALTER TABLE bed_height_values ADD COLUMN min_height DOUBLE PRECISION;
+ALTER TABLE bed_height_values ADD (
+  min_height FLOAT(126),
+  max_height FLOAT(126),
+  height01 FLOAT(32),
+  height02 FLOAT(32),
+  height03 FLOAT(32),
+  height04 FLOAT(32),
+  height05 FLOAT(32),
+  height06 FLOAT(32),
+  height07 FLOAT(32),
+  height08 FLOAT(32),
+  height09 FLOAT(32),
+  height10 FLOAT(32)
+);
 COMMENT ON COLUMN bed_height_values.min_height IS 'Minimum bed height (Talweg) in m' ;
-
-ALTER TABLE bed_height_values ADD COLUMN max_height DOUBLE PRECISION;
 COMMENT ON COLUMN bed_height_values.max_height IS 'Maximum bed height (Kammlage) in m' ;
+COMMENT ON COLUMN bed_height_values.height01 IS 'Bed height of section 1 in m' ;
+COMMENT ON COLUMN bed_height_values.height02 IS 'Bed height of section 2 in m' ;
+COMMENT ON COLUMN bed_height_values.height03 IS 'Bed height of section 3 in m' ;
+COMMENT ON COLUMN bed_height_values.height04 IS 'Bed height of section 4 in m' ;
+COMMENT ON COLUMN bed_height_values.height05 IS 'Bed height of section 5 in m' ;
+COMMENT ON COLUMN bed_height_values.height06 IS 'Bed height of section 6 in m' ;
+COMMENT ON COLUMN bed_height_values.height07 IS 'Bed height of section 7 in m' ;
+COMMENT ON COLUMN bed_height_values.height08 IS 'Bed height of section 8 in m' ;
+COMMENT ON COLUMN bed_height_values.height09 IS 'Bed height of section 9 in m' ;
+COMMENT ON COLUMN bed_height_values.height10 IS 'Bed height of section 10 in m' ;
 
 
 --Bed mobility
@@ -81,9 +105,9 @@
 
 CREATE TABLE infrastructure_values (
     id  NUMBER(9,0) PRIMARY KEY,
-    infrastructure_id  NUMBER(9,0) CONSTRAINT cInfrastructureValuesInfrastructure REFERENCES infrastructure(id) ON DELETE CASCADE,
+    infrastructure_id  NUMBER(9,0) CONSTRAINT cInfrastructureValuesInfrastru REFERENCES infrastructure(id) ON DELETE CASCADE,
     station  NUMBER(7,3) NOT NULL,
-    attribute_id  NUMBER(38,0) CONSTRAINT cInfrastructureValuesAttributes REFERENCES attributes(id),
+    attribute_id  NUMBER(38,0) CONSTRAINT cInfrastructureValuesAttrib REFERENCES attributes(id),
     height  NUMBER(6,2)
 );
 COMMENT ON TABLE infrastructure_values IS 'Infrastructure at a river station' ;
@@ -185,14 +209,16 @@
     day  DATE,
     kmrange_info  VARCHAR2(32),
     filename  VARCHAR2(256) NOT NULL,
+    groupname  VARCHAR2(32) NOT NULL CHECK(groupname IN ('messung','berechnung')),
     sounding_info  VARCHAR2(64),
     evaluation_by  VARCHAR2(256),
     "comment"  VARCHAR2(256)
 );
-COMMENT ON TABLE tkh IS 'Longitudinal section of computed Transportkörperhöhe of a river' ;
+COMMENT ON TABLE tkh IS 'Longitudinal section of computed Transportkoerperhoehe of a river' ;
 COMMENT ON COLUMN tkh.day IS 'File header line info "Datum"' ;
 COMMENT ON COLUMN tkh.kmrange_info IS 'File header line info "Strecke"' ;
 COMMENT ON COLUMN tkh.filename IS 'Name without type extension of the imported file' ;
+COMMENT ON COLUMN tkh.groupname IS 'Group the file belongs to' ;
 COMMENT ON COLUMN tkh.sounding_info IS 'File header line info "Peilung"' ;
 COMMENT ON COLUMN tkh.evaluation_by IS 'File header line info "Auswerter"' ;
 COMMENT ON COLUMN tkh."comment" IS 'File header line info "weitere Bemerkungen"' ;
@@ -205,7 +231,7 @@
     tkh_id  NUMBER(9,0) NOT NULL CONSTRAINT cTkhColumnTkh REFERENCES tkh(id) ON DELETE CASCADE,
     name  VARCHAR2(64) NOT NULL
 );
-COMMENT ON TABLE tkh_column IS 'Longitudinal section of computed Transportkörperhöhe for a waterlevel series' ;
+COMMENT ON TABLE tkh_column IS 'Longitudinal section of computed Transportkoerperhoehe for a waterlevel series' ;
 COMMENT ON COLUMN tkh_column.name IS 'Name of the tkh computation column' ;
 
 CREATE SEQUENCE TKH_COLUMN_ID_SEQ ;
@@ -217,9 +243,9 @@
     station  NUMBER(7,3) NOT NULL,
     tkheight  NUMBER(7,3)
 );
-COMMENT ON TABLE tkh_values IS 'Transportkörperhöhe of a river station and referenced file column' ;
+COMMENT ON TABLE tkh_values IS 'Transportkoerperhoehe of a river station and referenced file column' ;
 COMMENT ON COLUMN tkh_values.station IS 'River km' ;
-COMMENT ON COLUMN tkh_values.tkheight IS 'Transportkörperhöhe of a river station computed for a waterlevel in  m' ;
+COMMENT ON COLUMN tkh_values.tkheight IS 'Transportkoerperhoehe of a river station computed for a waterlevel in  m' ;
 
 CREATE SEQUENCE TKH_VALUES_ID_SEQ ;
 
@@ -262,7 +288,7 @@
 
 CREATE TABLE flow_depth_values (
     id  NUMBER(9,0) PRIMARY KEY,
-    flow_depth_column_id  NUMBER(9,0) NOT NULL CONSTRAINT cFlowDepthValuesFlowDepthColumn REFERENCES flow_depth_column(id) ON DELETE CASCADE,
+    flow_depth_column_id  NUMBER(9,0) NOT NULL CONSTRAINT cFlowDepthValuesFlowDepthCol REFERENCES flow_depth_column(id) ON DELETE CASCADE,
     station  NUMBER(7,3) NOT NULL,
     depth  NUMBER(7,3)
 );
@@ -287,6 +313,7 @@
     curr_glw  VARCHAR2(64) NOT NULL,
     old_glw  VARCHAR2(64) NOT NULL,
     filename  VARCHAR2(256) NOT NULL,
+    groupname  VARCHAR2(32) NOT NULL CHECK(groupname IN ('aktuell','etappe')),
     "comment"  VARCHAR2(256)
 );
 COMMENT ON TABLE depth_evolution IS 'Longitudinal section of the evolution of the flow depth of a river' ;
@@ -298,6 +325,7 @@
 COMMENT ON COLUMN depth_evolution.curr_glw IS 'File header line info "Aktuelle Wasserspiegellage"' ;
 COMMENT ON COLUMN depth_evolution.old_glw IS 'File header line info "Historische Wasserspiegellage"' ;
 COMMENT ON COLUMN depth_evolution.filename IS 'Name without type extension of the imported file' ;
+COMMENT ON COLUMN depth_evolution.groupname IS 'Group the file belongs to' ;
 COMMENT ON COLUMN depth_evolution."comment" IS 'File header line info "weitere Bemerkungen"' ;
 
 CREATE SEQUENCE DEPTH_EVOLUTION_ID_SEQ ;
@@ -305,7 +333,7 @@
 
 CREATE TABLE depth_evolution_values (
     id  NUMBER(9,0) PRIMARY KEY,
-    depth_evolution_id  NUMBER(9,0) NOT NULL CONSTRAINT cDepthEvolutionValuesDepthEvolution REFERENCES depth_evolution(id) ON DELETE CASCADE,
+    depth_evolution_id  NUMBER(9,0) NOT NULL CONSTRAINT cDepthEvolutionValuesDepthEvol REFERENCES depth_evolution(id) ON DELETE CASCADE,
     station  NUMBER(7,3) NOT NULL,
     total_change  NUMBER(8,4),
     change_per_year  NUMBER(8,4)
@@ -334,7 +362,7 @@
 
 CREATE TABLE daily_discharge_values (
     id  NUMBER(9,0) PRIMARY KEY,
-    daily_discharge_id  NUMBER(9,0) NOT NULL CONSTRAINT cDailyDischargeValueDailyDischarge REFERENCES daily_discharge(id) ON DELETE CASCADE,
+    daily_discharge_id  NUMBER(9,0) NOT NULL CONSTRAINT cDailyDischargeValueDailyDisch REFERENCES daily_discharge(id) ON DELETE CASCADE,
     day  DATE NOT NULL,
     discharge  NUMBER(8,3) NOT NULL
 );
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/doc/schema/postgresql-sinfo-uinfo.sql
--- a/backend/doc/schema/postgresql-sinfo-uinfo.sql	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/doc/schema/postgresql-sinfo-uinfo.sql	Fri Apr 27 17:35:12 2018 +0200
@@ -9,20 +9,40 @@
 
 --Add new columns bed_height.sounding_width_info and bed_height.comment
 
-ALTER TABLE bed_height ADD COLUMN sounding_width_info VARCHAR(256);
+ALTER TABLE bed_height
+  ADD sounding_width_info VARCHAR(256),
+  ADD "comment" VARCHAR(256);
 COMMENT ON COLUMN bed_height.sounding_width_info IS 'File header line info "ausgewertete Peilbreite"' ;
-
-ALTER TABLE bed_height ADD COLUMN "comment" VARCHAR(256);
 COMMENT ON COLUMN bed_height."comment" IS 'File header line info "weitere Bemerkungen"' ;
 
 
 --Add new columns bed_height_values.min_height (Talweg) and bed_height_values.max_height (Kammlage) (same type as existing height column)
 
-ALTER TABLE bed_height_values ADD COLUMN min_height NUMERIC;
+ALTER TABLE bed_height_values
+  ADD min_height NUMERIC,
+  ADD max_height NUMERIC,
+  ADD height01 NUMERIC,
+  ADD height02 NUMERIC,
+  ADD height03 NUMERIC,
+  ADD height04 NUMERIC,
+  ADD height05 NUMERIC,
+  ADD height06 NUMERIC,
+  ADD height07 NUMERIC,
+  ADD height08 NUMERIC,
+  ADD height09 NUMERIC,
+  ADD height10 NUMERIC;
 COMMENT ON COLUMN bed_height_values.min_height IS 'Minimum bed height (Talweg) in m' ;
-
-ALTER TABLE bed_height_values ADD COLUMN max_height NUMERIC;
 COMMENT ON COLUMN bed_height_values.max_height IS 'Maximum bed height (Kammlage) in m' ;
+COMMENT ON COLUMN bed_height_values.height01 IS 'Bed height of section 1 in m' ;
+COMMENT ON COLUMN bed_height_values.height02 IS 'Bed height of section 2 in m' ;
+COMMENT ON COLUMN bed_height_values.height03 IS 'Bed height of section 3 in m' ;
+COMMENT ON COLUMN bed_height_values.height04 IS 'Bed height of section 4 in m' ;
+COMMENT ON COLUMN bed_height_values.height05 IS 'Bed height of section 5 in m' ;
+COMMENT ON COLUMN bed_height_values.height06 IS 'Bed height of section 6 in m' ;
+COMMENT ON COLUMN bed_height_values.height07 IS 'Bed height of section 7 in m' ;
+COMMENT ON COLUMN bed_height_values.height08 IS 'Bed height of section 8 in m' ;
+COMMENT ON COLUMN bed_height_values.height09 IS 'Bed height of section 9 in m' ;
+COMMENT ON COLUMN bed_height_values.height10 IS 'Bed height of section 10 in m' ;
 
 
 --Bed mobility
@@ -185,6 +205,7 @@
     day  DATE,
     kmrange_info  VARCHAR(32),
     filename  VARCHAR(256) NOT NULL,
+    groupname  VARCHAR(32) NOT NULL CHECK(groupname IN ('messung','berechnung')),
     sounding_info  VARCHAR(64),
     evaluation_by  VARCHAR(256),
     "comment"  VARCHAR(256)
@@ -193,6 +214,7 @@
 COMMENT ON COLUMN tkh.day IS 'File header line info "Datum"' ;
 COMMENT ON COLUMN tkh.kmrange_info IS 'File header line info "Strecke"' ;
 COMMENT ON COLUMN tkh.filename IS 'Name without type extension of the imported file' ;
+COMMENT ON COLUMN tkh.groupname IS 'Group the file belongs to' ;
 COMMENT ON COLUMN tkh.sounding_info IS 'File header line info "Peilung"' ;
 COMMENT ON COLUMN tkh.evaluation_by IS 'File header line info "Auswerter"' ;
 COMMENT ON COLUMN tkh."comment" IS 'File header line info "weitere Bemerkungen"' ;
@@ -287,6 +309,7 @@
     curr_glw  VARCHAR(64) NOT NULL,
     old_glw  VARCHAR(64) NOT NULL,
     filename  VARCHAR(256) NOT NULL,
+    groupname  VARCHAR(32) NOT NULL CHECK(groupname IN ('aktuell','etappe')),
     "comment"  VARCHAR(256)
 );
 COMMENT ON TABLE depth_evolution IS 'Longitudinal section of the evolution of the flow depth of a river' ;
@@ -298,6 +321,7 @@
 COMMENT ON COLUMN depth_evolution.curr_glw IS 'File header line info "Aktuelle Wasserspiegellage"' ;
 COMMENT ON COLUMN depth_evolution.old_glw IS 'File header line info "Historische Wasserspiegellage"' ;
 COMMENT ON COLUMN depth_evolution.filename IS 'Name without type extension of the imported file' ;
+COMMENT ON COLUMN depth_evolution.groupname IS 'Group the file belongs to' ;
 COMMENT ON COLUMN depth_evolution."comment" IS 'File header line info "weitere Bemerkungen"' ;
 
 CREATE SEQUENCE DEPTH_EVOLUTION_ID_SEQ ;
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/DepthEvolutionSeriesImport.java
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/DepthEvolutionSeriesImport.java	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/DepthEvolutionSeriesImport.java	Fri Apr 27 17:35:12 2018 +0200
@@ -16,6 +16,7 @@
 import org.dive4elements.river.importer.common.AbstractSeriesImport;
 import org.dive4elements.river.model.River;
 import org.dive4elements.river.model.sinfo.DepthEvolution;
+import org.dive4elements.river.model.sinfo.DepthEvolution.Group;
 import org.dive4elements.river.model.sinfo.DepthEvolutionValue;
 import org.hibernate.SQLQuery;
 import org.hibernate.Session;
@@ -32,6 +33,8 @@
 
     private static Logger log = Logger.getLogger(DepthEvolutionSeriesImport.class);
 
+    private Group group;
+
     private Integer start_year;
 
     private Integer reference_year;
@@ -54,6 +57,10 @@
 
     /***** METHODS *****/
 
+    public void setGroup(final Group group) {
+        this.group = group;
+    }
+
     public void setStart_year(final Integer start_year) {
         this.start_year = start_year;
     }
@@ -100,6 +107,6 @@
     @Override
     public DepthEvolution createSeriesItem(final River river) {
         return new DepthEvolution(river, this.filename, this.kmrange_info, this.comment, this.start_year, this.reference_year, this.curr_sounding,
-                this.old_sounding, this.curr_glw, this.old_glw);
+                this.old_sounding, this.curr_glw, this.old_glw, this.group);
     }
 }
\ No newline at end of file
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/TkhSeriesImport.java
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/TkhSeriesImport.java	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/TkhSeriesImport.java	Fri Apr 27 17:35:12 2018 +0200
@@ -18,6 +18,7 @@
 import org.dive4elements.river.importer.common.StoreMode;
 import org.dive4elements.river.model.River;
 import org.dive4elements.river.model.sinfo.Tkh;
+import org.dive4elements.river.model.sinfo.Tkh.Group;
 import org.hibernate.Query;
 import org.hibernate.Session;
 
@@ -38,6 +39,8 @@
      */
     private final String filename;
 
+    private Group group;
+
     private String kmrange_info;
 
     private String comment;
@@ -66,6 +69,14 @@
         return this.filename;
     }
 
+    public Group getGroup() {
+        return this.group;
+    }
+
+    public void setGroup(final Group group) {
+        this.group = group;
+    }
+
     public String getKmrange_info() {
         return this.kmrange_info;
     }
@@ -141,6 +152,6 @@
     }
 
     private Tkh createSeriesItem(final River river) {
-        return new Tkh(river, this.filename, this.kmrange_info, this.comment, this.day, this.sounding_info, this.evaluation_by);
+        return new Tkh(river, this.filename, this.kmrange_info, this.comment, this.day, this.sounding_info, this.evaluation_by, this.group);
     }
 }
\ No newline at end of file
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/DepthEvolutionParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/DepthEvolutionParser.java	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/DepthEvolutionParser.java	Fri Apr 27 17:35:12 2018 +0200
@@ -50,6 +50,36 @@
 
     private static final Pattern META_OLD_WSP = Pattern.compile("^#\\sHistorische Wasserspiegellage:\\s*([^;]*).*", Pattern.CASE_INSENSITIVE);
 
+    private enum GroupDirectory {
+        NONE(DepthEvolution.Group.NONE, ""), //
+        AKTUELL(DepthEvolution.Group.AKTUELL, "Bezug_aktueller_GLW"), //
+        ETAPPE(DepthEvolution.Group.ETAPPE, "GLW-Etappen");
+
+        private final DepthEvolution.Group group;
+        private final String dirname;
+
+        GroupDirectory(final DepthEvolution.Group group, final String dirname) {
+            this.group = group;
+            this.dirname = dirname;
+        }
+
+        public DepthEvolution.Group getGroup() {
+            return this.group;
+        }
+
+        public String getDirName() {
+            return this.dirname;
+        }
+
+        public static GroupDirectory forDirName(final String dirname) {
+            for (final GroupDirectory gd : GroupDirectory.values()) {
+                if (dirname.equalsIgnoreCase(gd.getDirName()))
+                    return gd;
+            }
+            return NONE;
+        }
+    }
+
 
     /***** CONSTRUCTORS *****/
 
@@ -178,7 +208,9 @@
 
     @Override
     protected DepthEvolutionSeriesImport createSeriesImport(final String filename) {
-        return new DepthEvolutionSeriesImport(filename);
+        final DepthEvolutionSeriesImport series = new DepthEvolutionSeriesImport(filename);
+        series.setGroup(GroupDirectory.forDirName(this.importPath.getParentFile().getName()).getGroup());
+        return series;
     }
 
     @Override
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/TkhParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/TkhParser.java	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/TkhParser.java	Fri Apr 27 17:35:12 2018 +0200
@@ -31,6 +31,7 @@
 import org.dive4elements.river.importer.sinfo.importitem.TkhColumnSeriesImport;
 import org.dive4elements.river.importer.sinfo.importitem.TkhKmLineImport;
 import org.dive4elements.river.importer.sinfo.importitem.TkhSeriesImport;
+import org.dive4elements.river.model.sinfo.Tkh;
 import org.dive4elements.river.model.sinfo.TkhColumn;
 import org.dive4elements.river.model.sinfo.TkhValue;
 
@@ -56,6 +57,36 @@
 
     private static final Pattern COLUMN_TITLE = Pattern.compile("Transportk((.)|(oe))rperh((.)|(oe))he\\s*\\((.+?)\\)\\s*\\[cm\\].*", Pattern.CASE_INSENSITIVE);
 
+    private enum GroupDirectory {
+        NONE(Tkh.Group.NONE, ""), //
+        CALCULATION(Tkh.Group.CALCULATION, "Berechnungsergebnisse"), //
+        MEASUREMENT(Tkh.Group.MEASUREMENT, "Naturmessungen");
+
+        private final Tkh.Group group;
+        private final String dirname;
+
+        GroupDirectory(final Tkh.Group group, final String dirname) {
+            this.group = group;
+            this.dirname = dirname;
+        }
+
+        public Tkh.Group getGroup() {
+            return this.group;
+        }
+
+        public String getDirName() {
+            return this.dirname;
+        }
+
+        public static GroupDirectory forDirName(final String dirname) {
+            for (final GroupDirectory gd : GroupDirectory.values()) {
+                if (dirname.equalsIgnoreCase(gd.getDirName()))
+                    return gd;
+            }
+            return NONE;
+        }
+    }
+
     private static final DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
 
     private final TkhSeriesImport tkhGroup;
@@ -68,6 +99,7 @@
     public TkhParser(final File importPath, final File rootRelativePath, final ImportRiver river) {
         super(importPath, rootRelativePath, river);
         this.tkhGroup = new TkhSeriesImport(importPath.getName().replaceAll("\\.csv", ""));
+        this.tkhGroup.setGroup(GroupDirectory.forDirName(this.importPath.getParentFile().getName()).getGroup());
         this.seriesHeader = new TkhColumnSeriesImport(this.tkhGroup.getFilename(), this.tkhGroup, null, null);
         this.colParsers = new ArrayList<>();
     }
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/src/main/java/org/dive4elements/river/model/sinfo/DepthEvolution.java
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/DepthEvolution.java	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/DepthEvolution.java	Fri Apr 27 17:35:12 2018 +0200
@@ -24,8 +24,12 @@
 import javax.persistence.OneToOne;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
+import javax.persistence.Transient;
 
+import org.dive4elements.river.backend.SessionHolder;
 import org.dive4elements.river.model.River;
+import org.hibernate.Query;
+import org.hibernate.Session;
 
 /**
  * Hibernate binding for the DB table depth_evolution
@@ -38,6 +42,41 @@
 @Table(name = "depth_evolution")
 public class DepthEvolution implements Serializable {
 
+    /***** TYPES *****/
+
+    /**
+     * Possible values of the groupname column
+     *
+     */
+    public enum Group {
+        NONE(""), AKTUELL("aktuell"), ETAPPE("etappe");
+
+        private final String dbvalue;
+
+        Group(final String dbvalue) {
+            this.dbvalue = dbvalue;
+        }
+
+        /**
+         * Value of the group's groupname column
+         */
+        public String getDbValue() {
+            return this.dbvalue;
+        }
+
+        /**
+         * Group for a groupname column value
+         */
+        public static Group forDbValue(final String dbvalue) {
+            for (final Group g : Group.values()) {
+                if (g.getDbValue().equals(dbvalue))
+                    return g;
+            }
+            return Group.NONE;
+        }
+    }
+
+
     /***** FIELDS *****/
 
     private static final long serialVersionUID = 2665718161356165179L;
@@ -50,6 +89,8 @@
 
     private String filename;
 
+    private transient Group group;
+
     private String comment;
 
     private Integer start_year;
@@ -73,7 +114,8 @@
     }
 
     public DepthEvolution(final River river, final String filename, final String kmrange_info, final String comment, final Integer start_year,
-            final Integer reference_year, final String curr_sounding, final String old_sounding, final String curr_glw, final String old_glw) {
+            final Integer reference_year, final String curr_sounding, final String old_sounding, final String curr_glw, final String old_glw,
+            final Group group) {
         this.river = river;
         this.filename = filename;
         this.kmrange_info = kmrange_info;
@@ -84,6 +126,7 @@
         this.old_sounding = old_sounding;
         this.curr_glw = curr_glw;
         this.old_glw = old_glw;
+        this.group = group;
         this.values = new ArrayList<>();
     }
 
@@ -120,6 +163,24 @@
         this.filename = filename;
     }
 
+    @Column(name = "groupname")
+    public String getGroupname() {
+        return this.group.getDbValue();
+    }
+
+    public void setGroupname(final String groupname) {
+        this.group = Group.forDbValue(groupname);
+    }
+
+    @Transient
+    public Group getGroup() {
+        return this.group;
+    }
+
+    public void setGroup(final Group group) {
+        this.group = group;
+    }
+
     @Column(name = "kmrange_info")
     public String getKmrange_info() {
         return this.kmrange_info;
@@ -205,4 +266,14 @@
     public void addValue(final DepthEvolutionValue value) {
         this.values.add(value);
     }
+
+    /**
+     * Get data series by id
+     */
+    public static DepthEvolution getSeries(final int id) {
+        final Session session = SessionHolder.HOLDER.get();
+        final Query query = session.createQuery("FROM DepthEvolution WHERE (id=:id)");
+        query.setParameter("id", id);
+        return (DepthEvolution) query.list().get(0);
+    }
 }
\ No newline at end of file
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/src/main/java/org/dive4elements/river/model/sinfo/DepthEvolutionValue.java
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/DepthEvolutionValue.java	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/DepthEvolutionValue.java	Fri Apr 27 17:35:12 2018 +0200
@@ -11,6 +11,7 @@
 package org.dive4elements.river.model.sinfo;
 
 import java.io.Serializable;
+import java.util.List;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -21,6 +22,11 @@
 import javax.persistence.OneToOne;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
+import javax.persistence.Transient;
+
+import org.dive4elements.river.backend.SessionHolder;
+import org.hibernate.Query;
+import org.hibernate.Session;
 
 
 /**
@@ -110,6 +116,14 @@
         this.total_change = total_change;
     }
 
+    @Transient
+    public Double getTotalChangeCm() {
+        if (getTotal_change() != null)
+            return getTotal_change() * 100;
+        else
+            return null;
+    }
+
     @Column(name = "change_per_year")
     public Double getChange_per_year() {
         return this.change_per_year;
@@ -118,4 +132,25 @@
     public void setChange_per_year(final Double change_per_year) {
         this.change_per_year = change_per_year;
     }
+
+    @Transient
+    public Double getPerYearChangeCm() {
+        if (getChange_per_year() != null)
+            return getChange_per_year() * 100;
+        else
+            return null;
+    }
+
+    /**
+     * Selects the depth evolution values of a data series in a km range from the database
+     */
+    public static List<DepthEvolutionValue> getValues(final DepthEvolution parent, final double kmLo, final double kmHi) {
+        final Session session = SessionHolder.HOLDER.get();
+        final Query query = session.createQuery("FROM DepthEvolutionValue WHERE (depthEvolution=:parent)"
+                + " AND (station >= :kmLo - 0.0001) AND (station <= :kmHi + 0.0001)");
+        query.setParameter("parent", parent);
+        query.setParameter("kmLo", new Double(kmLo));
+        query.setParameter("kmHi", new Double(kmHi));
+        return query.list();
+    }
 }
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/src/main/java/org/dive4elements/river/model/sinfo/Tkh.java
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/Tkh.java	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/Tkh.java	Fri Apr 27 17:35:12 2018 +0200
@@ -25,6 +25,7 @@
 import javax.persistence.OneToOne;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
+import javax.persistence.Transient;
 
 import org.dive4elements.river.backend.SessionHolder;
 import org.dive4elements.river.model.River;
@@ -42,6 +43,38 @@
 @Table(name = "tkh")
 public class Tkh implements Serializable {
 
+    /**
+     * Possible values of the groupname column
+     *
+     */
+    public enum Group {
+        NONE(""), CALCULATION("berechnung"), MEASUREMENT("messung");
+
+        private final String dbvalue;
+
+        Group(final String dbvalue) {
+            this.dbvalue = dbvalue;
+        }
+
+        /**
+         * Value of the group's groupname column
+         */
+        public String getDbValue() {
+            return this.dbvalue;
+        }
+
+        /**
+         * Group for a groupname column value
+         */
+        public static Group forDbValue(final String dbvalue) {
+            for (final Group g : Group.values()) {
+                if (g.getDbValue().equals(dbvalue))
+                    return g;
+            }
+            return Group.NONE;
+        }
+    }
+
     /***** FIELDS *****/
 
     private static final long serialVersionUID = 5891445651697221261L;
@@ -52,6 +85,8 @@
 
     private String filename;
 
+    private transient Group group;
+
     private String kmrange_info;
 
     private String comment;
@@ -72,7 +107,7 @@
 
 
     public Tkh(final River river, final String filename, final String kmrange_info, final String comment, final Date day, final String sounding_info,
-            final String evaluation_by) {
+            final String evaluation_by, final Group group) {
         this.river = river;
         this.filename = filename;
         this.kmrange_info = kmrange_info;
@@ -80,6 +115,7 @@
         this.day = day;
         this.setSounding_info(sounding_info);
         this.setEvaluation_by(evaluation_by);
+        this.setGroup(group);
         this.columns = new ArrayList<>();
     }
 
@@ -116,6 +152,24 @@
         this.filename = filename;
     }
 
+    @Column(name = "groupname")
+    public String getGroupname() {
+        return this.group.getDbValue();
+    }
+
+    public void setGroupname(final String groupname) {
+        this.group = Group.forDbValue(groupname);
+    }
+
+    @Transient
+    public Group getGroup() {
+        return this.group;
+    }
+
+    public void setGroup(final Group group) {
+        this.group = group;
+    }
+
     @Column(name = "kmrange_info")
     public String getKmrange_info() {
         return this.kmrange_info;
diff -r efd2de78d158 -r 1f63e9d3b0ec backend/src/main/java/org/dive4elements/river/model/sinfo/TkhValue.java
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/TkhValue.java	Fri Apr 27 11:34:04 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/TkhValue.java	Fri Apr 27 17:35:12 2018 +0200
@@ -22,6 +22,7 @@
 import javax.persistence.OneToOne;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
+import javax.persistence.Transient;
 
 import org.dive4elements.river.backend.SessionHolder;
 import org.hibernate.Query;
@@ -114,6 +115,30 @@
         this.tkheight = tkheight;
     }
 
+    @Transient
+    public double getTkhCm() {
+        if (getTkheight() != null)
+            return getTkheight().doubleValue() * 100;
+        else
+            return Double.NaN;
+    }
+
+    @Transient
+    public double getTkhUpCm(final boolean bedMoving) {
+        if (bedMoving)
+            return getTkhCm() / 2;
+        else
+            return getTkhCm();
+    }
+
+    @Transient
+    public double getTkhDownCm(final boolean bedMoving) {
+        if (bedMoving)
+            return -getTkhCm() / 2;
+        else
+            return 0.0;
+    }
+
     /**
      * Selects the tkh values of a tkh series column in a km range from the database
      */


More information about the Dive4Elements-commits mailing list