changeset 9454:4cccbd32b680

Bundu.wst.UD -> Q-Values are set on Client side now
author gernotbelger
date Thu, 23 Aug 2018 16:32:28 +0200
parents 9e471031cc1e
children 5f81d3f7b82b
files artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java backend/src/main/java/org/dive4elements/river/model/MainValueType.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractWQAdaptedInputPanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstWQPanel.java
diffstat 5 files changed, 90 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java	Thu Aug 23 11:02:47 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java	Thu Aug 23 16:32:28 2018 +0200
@@ -125,7 +125,7 @@
         final int yearCnt = DateUtils.getYearFromDate(endTime) - DateUtils.getYearFromDate(startTime) + 1;
         double glq20 = Double.NaN;
         for (int i = 0, k = 0; (i <= 364) && (k <= qs.size() - 1); i++, k += yearCnt) {
-            final NamedMainValue nmv = fetchNamedQMainValue(i, session, mainValues.get(0).getMainValue().getType());
+            final NamedMainValue nmv = fetchNamedQMainValue(i, session);
             if (nmv != null) {
                 final double q = getDurationQ(qs, k);
                 mainValues.add(createMainValue(gauge, nmv, q, timeperiod));
@@ -175,11 +175,16 @@
     /**
      * Fetches a named main Q(duration) value from the database, if existing
      */
-    private NamedMainValue fetchNamedQMainValue(final int days, final Session session, final MainValueType qType) {
-        final NamedMainValue nmv = NamedMainValue.fetchByNameAndType(Integer.toString(days), MainValueTypeKey.DURATION.getName(), session);
-        // final NamedMainValue nmv = new NamedMainValue(Integer.toString(days), qType);
-        if (nmv != null)
-            nmv.setOfficialLines(new ArrayList<OfficialLine>());
+    private NamedMainValue fetchNamedQMainValue(final int days, final Session session) {
+
+        NamedMainValue nmv = NamedMainValue.fetchByNameAndType(Integer.toString(days), MainValueTypeKey.DURATION.getName(), session);
+        if (nmv == null) {
+            final MainValueType mvt = new MainValueType(MainValueTypeKey.INVISIBLE_D.name());
+            nmv = new NamedMainValue(Integer.toString(days), mvt);
+        }
+
+        nmv.setOfficialLines(new ArrayList<OfficialLine>());
+
         return nmv;
     }
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java	Thu Aug 23 11:02:47 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java	Thu Aug 23 16:32:28 2018 +0200
@@ -50,6 +50,11 @@
 
     }
 
+    @Override
+    protected boolean pdfExportEnabled() {
+        return false;
+    }
+
     public BedHeightInfo getSounding() {
         return this.sounding;
     }
--- a/backend/src/main/java/org/dive4elements/river/model/MainValueType.java	Thu Aug 23 11:02:47 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/MainValueType.java	Thu Aug 23 16:32:28 2018 +0200
@@ -25,9 +25,7 @@
 
 @Entity
 @Table(name = "main_value_types")
-public class MainValueType
-implements   Serializable
-{
+public class MainValueType implements Serializable {
 
     /***** TYPES *****/
 
@@ -36,7 +34,7 @@
      *
      */
     public enum MainValueTypeKey {
-        NONE(""), W("W"), Q("Q"), DURATION("D"), UNKNOWN("-");
+        NONE(""), W("W"), Q("Q"), DURATION("D"), UNKNOWN("-"), INVISIBLE_D("D_INV");
 
         private final String name;
         private int id;
@@ -127,7 +125,7 @@
     /***** FIELDS *****/
 
     private Integer id;
-    private String  name;
+    private String name;
     // static private List<Integer> typeids;
     // static private List<String> typenames;
 
@@ -140,17 +138,11 @@
         this.name = name;
     }
 
-
     /***** METHODS *****/
 
     @Id
-    @SequenceGenerator(
-            name           = "SEQUENCE_MAIN_VALUE_TYPES_ID_SEQ",
-            sequenceName   = "MAIN_VALUE_TYPES_ID_SEQ",
-            allocationSize = 1)
-    @GeneratedValue(
-            strategy  = GenerationType.SEQUENCE,
-            generator = "SEQUENCE_MAIN_VALUE_TYPES_ID_SEQ")
+    @SequenceGenerator(name = "SEQUENCE_MAIN_VALUE_TYPES_ID_SEQ", sequenceName = "MAIN_VALUE_TYPES_ID_SEQ", allocationSize = 1)
+    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_MAIN_VALUE_TYPES_ID_SEQ")
     @Column(name = "id")
     public Integer getId() {
         return this.id;
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractWQAdaptedInputPanel.java	Thu Aug 23 11:02:47 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractWQAdaptedInputPanel.java	Thu Aug 23 16:32:28 2018 +0200
@@ -69,6 +69,8 @@
     /** Stores the input panels related to their keys. */
     protected Map<String, DoubleArrayPanel> wqranges;
 
+    protected Map<String, Double> UDMap = new HashMap<String, Double>();
+
     /** [startkm,endkm] per gauge in selected range. */
     protected List<Double[]> gaugeRanges;
 
@@ -113,20 +115,18 @@
         this.tabs.setWidth100();
         this.tabs.setHeight100();
         final String msg = this.getWQInfoMsg();
-        final Label test = PanelHelper.getValidationLabel();
-        test.setText(msg);
-        test.getElement().getStyle().setColor("black");
-        test.getElement().getStyle().setPadding(1, Unit.MM);
 
         // For each gauge, add two tabs with helper tables.
         createTabs();
         layout.addMember(this.tabs);
-        if (msg != null)
-            layout.addMember(test);
 
+        if (msg != null) {
+            final Label additionalMsg = new Label(msg); // PanelHelper.getValidationLabel();
+            additionalMsg.setHeight("15px");
+            additionalMsg.getElement().getStyle().setPadding(1, Unit.MM);
+            layout.addMember(additionalMsg);
+        }
         this.helperContainer.addMember(layout);
-        // DOM.setStyleAttribute(test.getElement(), "color", "red");
-
     }
 
     /** Create labels, canvasses, layouts. */
@@ -410,28 +410,57 @@
         return results;
     }
 
+    private final String createKeyForWQValues(final String gaugeName, final String UD) {
+        final Double[] fromTo = this.gaugeNamesRange.get(gaugeName);
+        assert (fromTo.length == 2);
+        return new StringBuilder().append(fromTo[0]).append(GAUGE_PART_SEPARATOR).append(fromTo[1]).append(GAUGE_PART_SEPARATOR).append(gaugeName)
+                .append(GAUGE_PART_SEPARATOR).append(UD).toString();
+    }
+
     protected final Data getWQValues(final String dataKey) {
         String wqvalue = null;
-
         for (final Map.Entry<String, DoubleArrayPanel> entry : this.wqranges.entrySet()) {
-            final String key = entry.getKey();
-            final DoubleArrayPanel dap = entry.getValue();
-            final String label = dap.getItemTitle();
+            final String key = getKeyFromDap(entry);
+            final double[] values = entry.getValue().getInputValues();
+            wqvalue = appendValueStr(createValueString(key, values), wqvalue);
+        }
+        return getValueItem(dataKey, wqvalue);
+    }
 
-            final double[] values = dap.getInputValues();
-            if (wqvalue == null) {
-                wqvalue = createValueString(key + ";" + label, values);
-            } else {
-                wqvalue += GAUGE_SEPARATOR + createValueString(key + ";" + label, values);
-            }
+    protected final Data getWQValuesForUD(final String dataKey, final String udValue) {
+        String wqvalue = null;
+        for (final Map.Entry<String, DoubleArrayPanel> entry : this.wqranges.entrySet()) {
+            final String keyBasic = getKeyFromDap(entry);
+            final Double value = this.UDMap.get(keyBasic + GAUGE_PART_SEPARATOR + udValue);
+            if (value != null)
+                wqvalue = appendValueStr(createValueString(keyBasic, new double[] { value }), wqvalue);
         }
+        return getValueItem(dataKey, wqvalue);
+    }
 
+    private Data getValueItem(final String dataKey, final String wqvalue) {
         final DataItem valueItem = new DefaultDataItem(dataKey, dataKey, wqvalue);
         final Data values = new DefaultData(dataKey, null, null, new DataItem[] { valueItem });
 
         return values;
     }
 
+    private String appendValueStr(final String appendStr, String oldStr) {
+        if (oldStr == null) {
+            oldStr = appendStr;
+        } else {
+            oldStr += GAUGE_SEPARATOR + appendStr;
+        }
+        return oldStr;
+    }
+
+    private String getKeyFromDap(final Map.Entry<String, DoubleArrayPanel> entry) {
+        final String keyRange = entry.getKey();
+        final DoubleArrayPanel dap = entry.getValue();
+        final String label = dap.getItemTitle();
+        return new StringBuilder().append(keyRange).append(GAUGE_PART_SEPARATOR).append(label).toString();
+    }
+
     protected String createValueString(final String key, final double[] values) {
         final StringBuilder sb = new StringBuilder();
 
@@ -441,9 +470,7 @@
             if (!first) {
                 sb.append(",");
             }
-
             sb.append(Double.toString(value));
-
             first = false;
         }
 
@@ -466,9 +493,6 @@
     /** Get the WQD data from service and stuck them up that tables. */
     protected abstract void fetchWQData();
 
-    // protected abstract void callMainValuesService(String locale, String river, double start, double end,
-    // AsyncCallback<WQInfoObject[]> cb);
-
     /** Add Info to helper table for gauge at index gaugeIdx. */
     public void addWQInfo(final WQInfoObject[] wqi, final int gaugeIdx, final GaugeInfoObject gauge) {
         if (wqi == null) {
@@ -481,13 +505,19 @@
         } else {
             for (final WQInfoObject wi : wqi) {
                 final WQInfoRecord rec = new WQInfoRecord(wi);
-
-                if (wi.getType().equals("W")) {
-                    if (gaugeIdx < this.wTables.size())
-                        this.wTables.get(gaugeIdx).addData(rec);
-                } else { // Q,D,- alle gehören hier rein!
-                    if (gaugeIdx < this.qdTables.size())
-                        this.qdTables.get(gaugeIdx).addData(rec);
+                final String type = wi.getType();
+                if (!type.contains("INVISIBLE")) {
+                    if (type.equals("W")) {
+                        if (gaugeIdx < this.wTables.size())
+                            this.wTables.get(gaugeIdx).addData(rec);
+                    } else { // Q,D,- alle gehören hier rein!
+                        if (gaugeIdx < this.qdTables.size())
+                            this.qdTables.get(gaugeIdx).addData(rec);
+                    }
+                }
+                if ((type.equals("D") || type.equals("INVISIBLE_D")) && gauge != null) {
+                    final String key = this.createKeyForWQValues(gauge.getName(), wi.getName());
+                    this.UDMap.put(key, wi.getValue());
                 }
             }
         }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstWQPanel.java	Thu Aug 23 11:02:47 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstWQPanel.java	Thu Aug 23 16:32:28 2018 +0200
@@ -192,20 +192,24 @@
 
     @Override
     public Data[] getData() {
-        final Data[] data = new Data[2];
+        final List<Data> dataList = new ArrayList<Data>();
         final String modeStr = getMode();
         final DataItem item = new DefaultDataItem("bundu.wst.mode", "bundu.wst.mode", modeStr);
         final Data modeData = new DefaultData("bundu.wst.mode", null, null, new DataItem[] { item });
-        data[0] = modeData;
+        dataList.add(modeData);
         if (modeStr.equals(mode.Q.toString())) {
-            data[1] = getWQValues("wq_values");
+
+            dataList.add(getWQValues("wq_values"));
         } else if (modeStr.equals(mode.UD.toString())) {
+
             final String udValue = this.udInputItem.getValueAsString(); // in validate findet der int-check statt; er verhindert ein weitergehen, falls der Wert
                                                                         // nicht int-kompatibel ist
             final DataItem itemV = new DefaultDataItem("bundu.wst.ud_value", "bundu.wst.ud_value", udValue);
-            data[1] = new DefaultData("bundu.wst.ud_value", null, null, new DataItem[] { itemV });
+            dataList.add(new DefaultData("bundu.wst.ud_value", null, null, new DataItem[] { itemV }));
+            dataList.add(getWQValuesForUD("wq_values", udValue));
         }
-        return data;
+
+        return dataList.toArray(new Data[dataList.size()]);
     }
 
     @Override

http://dive4elements.wald.intevation.org