changeset 9448:d32b11d585cd

CSV-Export bundu.wst fehlvolumen
author gernotbelger
date Wed, 22 Aug 2018 11:51:46 +0200
parents 3f4215ddd6b4
children ba3ad54edbae
files artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/BunduResultType.java artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstMissVolCalculationResult2.java artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractResultType.java
diffstat 4 files changed, 36 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/BunduResultType.java	Wed Aug 22 09:00:54 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/BunduResultType.java	Wed Aug 22 11:51:46 2018 +0200
@@ -104,7 +104,7 @@
 
         @Override
         public String exportValue(final CallContext context, final Object value) {
-            return exportStringValue(value);
+            return exportBooleanValue(context, value);
         }
 
         @Override
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java	Wed Aug 22 09:00:54 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java	Wed Aug 22 11:51:46 2018 +0200
@@ -57,13 +57,11 @@
 
     private final List<ResultRow> rows;
 
-
     public BezugswstCalculation(final CallContext context) {
         this.context = context;
         this.rows = new ArrayList<>();
     }
 
-
     /**
      * Calculates the result rows of a bundu bzws workflow
      */
@@ -214,8 +212,7 @@
                 missFieldCnt++;
                 fieldMissDepths.add(Double.valueOf(h - channelHeight));
                 fieldMissWidths.add(Double.valueOf(channelWidth / BedHeightValueType.FIELD_LAST_INDEX));
-            }
-            else {
+            } else {
                 fieldMissDepths.add(Double.valueOf(0.0));
                 fieldMissWidths.add(Double.valueOf(0.0));
             }
@@ -272,13 +269,14 @@
                     vTotal += volumes.get(j - 1);
                     vExcav += volumes.get(j - 1) + areas.get(j - 1) * EXCAVATION_DEPTH;
                     expenses += vExcav * EXPENSE_PER_CBM;
-                }
-                else {
+                } else {
                     volumes.add(Double.valueOf(0.0));
                     areas.add(Double.valueOf(0.0));
                 }
             }
             this.rows.get(i).putValue(BunduResultType.missVolumeFields, volumes);
+            // TODO: berechnete masse hier einfügen!
+            this.rows.get(i).putValue(BunduResultType.missMassFields, volumes);
             this.rows.get(i).putValue(BunduResultType.missAreaFields, areas);
             this.rows.get(i).putValue(BunduResultType.missVolumeTotal, vTotal);
             this.rows.get(i).putValue(BunduResultType.excavationVolume, vExcav);
@@ -301,8 +299,7 @@
         if (Double.isNaN(kmPrev) || Double.isNaN(kmNext)) {
             volumes.add(Double.valueOf(0.0));
             areas.add(Double.valueOf(0.0));
-        }
-        else {
+        } else {
             final double area1 = 0.5 * (areaCurr + areaPrev);
             final double area2 = 0.5 * (areaCurr + areaNext);
             volumes.add(Double.valueOf((Math.abs(kmCurr - kmPrev) * 0.5 * area1) + (Math.abs(kmNext - kmCurr) * 0.5 * area2)));
@@ -315,8 +312,7 @@
      */
     private double missingArea(final int rowIndex, final int first, final int last, final int fieldIndex) {
         if ((first <= rowIndex) && (rowIndex <= last))
-            return getFieldValue(rowIndex, BunduResultType.missDepthFields, fieldIndex)
-                    * getFieldValue(rowIndex, BunduResultType.missWidthFields, fieldIndex);
+            return getFieldValue(rowIndex, BunduResultType.missDepthFields, fieldIndex) * getFieldValue(rowIndex, BunduResultType.missWidthFields, fieldIndex);
         else
             return 0.0;
     }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstMissVolCalculationResult2.java	Wed Aug 22 09:00:54 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstMissVolCalculationResult2.java	Wed Aug 22 11:51:46 2018 +0200
@@ -62,7 +62,8 @@
         assert (vFields.size() == fieldSize()); // immer abgleichen mit der Calculation!
         @SuppressWarnings("unchecked")
         final List<Double> mFields = (List<Double>) row.getValue(BunduResultType.missMassFields);
-        for (int i = 0; i <= vFields.size() - 1; i++) {
+        assert (vFields.size() == mFields.size());
+        for (int i = 0; i < vFields.size(); i++) {
             lines.add(BunduResultType.missVolumeFields.exportValue(exportContext.getContext(), vFields.get(i)));
             lines.add(BunduResultType.missMassFields.exportValue(exportContext.getContext(), mFields.get(i)));
         }
@@ -81,9 +82,11 @@
 
         header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station));
 
-        for (int i = 1; i <= fieldSize(); i++) {
-            header.add(exportContextCSV.msg(fieldVolumeMsgKey, i));
-            header.add(exportContextCSV.msg(fieldMassMsgKey, i));
+        for (int i = 1; i <= fieldSize() * 2; i++) {
+            final double index = Math.ceil(i / 2.);
+            header.add(exportContextCSV.msg(fieldVolumeMsgKey, index));
+            i++;
+            header.add(exportContextCSV.msg(fieldMassMsgKey, index));
         }
         header.add(exportContextCSV.formatCsvHeader(BunduResultType.missVolumeMeanBed));
         header.add(exportContextCSV.formatCsvHeader(BunduResultType.missMassMeanBed));
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractResultType.java	Wed Aug 22 09:00:54 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractResultType.java	Wed Aug 22 11:51:46 2018 +0200
@@ -35,6 +35,9 @@
 
     private final String pdfHeader;
 
+    private static String YES = null;
+    private static String NO = null;
+
     protected AbstractResultType(final String unit, final String csvHeader, final String pdfHeader) {
         this.unit = unit;
         this.csvHeader = csvHeader;
@@ -56,6 +59,25 @@
         return (String) value;
     }
 
+    protected final String exportBooleanValue(final CallContext context, final Object value) {
+
+        if (value == null)
+            return StringUtils.EMPTY; // DISKUSSION; könnte auch "Nein" sein
+
+        if (!(value instanceof Boolean))
+            throw new IllegalStateException();
+
+        if ((boolean) value) {
+            if (YES == null)
+                YES = Resources.getMsg(context.getMeta(), String.valueOf(value));
+            return YES;
+        } else {
+            if (NO == null)
+                NO = Resources.getMsg(context.getMeta(), String.valueOf(value));
+            return NO;
+        }
+    }
+
     @Override
     public final double asDouble(final Object value) {
         if (value == null)

http://dive4elements.wald.intevation.org