[PATCH] Let the facet know the period of it's data

Wald Commits scm-commit at wald.intevation.org
Wed Aug 27 15:09:51 CEST 2014


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1409144985 -7200
# Node ID ce35bdf3d75025fc06660f480f860cc662f906da
# Parent  52504fc2cd588646911ad248bac09c503d4ea2c1
Let the facet know the period of it's data.

diff -r 52504fc2cd58 -r ce35bdf3d750 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFacet.java	Wed Aug 27 15:01:54 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFacet.java	Wed Aug 27 15:09:45 2014 +0200
@@ -49,14 +49,18 @@
 
     public String fraction;
 
+    public String period;
+
     public SedimentLoadDataFacet() {
     }
 
     public SedimentLoadDataFacet(int idx, String fraction_name, String unit,
+        String periodString,
         ComputeType type, String stateId, String hash, CallContext context) {
         super(idx, /*name*/"", ""/*description*/, type, hash, stateId);
 
         this.fraction = fraction_name;
+        this.period   = periodString;
 
         String typeUnit; /* Gnah someone should unify unit strings,... */
         String i18nUnit;
@@ -80,8 +84,7 @@
                 meta,
                 "facet.sedimentload." + isCalculated + fraction_name,
                 "Error: please add l10n for facet.sedimentload." + fraction_name,
-                /* TODO handle multiple periods per fraction */
-                new Object[] { "period", i18nUnit });
+                new Object[] { periodString, i18nUnit });
 
         /* Is this necessary? */
         metaData.put("X", "chart.longitudinal.section.xaxis.label");
@@ -103,15 +106,18 @@
 
         SedimentLoadDataResult sdResult = (SedimentLoadDataResult) payload;
 
-        List<Fraction> fractions = sdResult.getFractionsByName(fraction);
+        List<Fraction> fractions = sdResult.getFractionsByNameAndPeriod(
+            fraction, period
+        );
         if (fractions == null) {
-            logger.warn("No result for: " + fraction);
+            logger.warn("No result for fraction '" + fraction +
+                        "' and period '" + period + "'");
             return null;
         }
 
-        /* TODO handle multiple periods per fraction */
         if (fractions.size() > 1) {
-            logger.warn("Multiple periods not implemented.");
+            logger.error("Multiple results for fraction '" + fraction +
+                        "' and period '" + period + "'");
         }
 
         return fractions.get(0).getData();
diff -r 52504fc2cd58 -r ce35bdf3d750 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataResult.java	Wed Aug 27 15:01:54 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataResult.java	Wed Aug 27 15:09:45 2014 +0200
@@ -82,5 +82,19 @@
         }
         return result.isEmpty() ? null : result;
     }
+
+    public List<Fraction> getFractionsByNameAndPeriod(
+            String name,
+            String period
+        ) {
+        List<Fraction> result = new ArrayList<Fraction>();
+        for (Fraction fraction: fractions) {
+            if (fraction.getName().equals(name) &&
+                fraction.getPeriod().equals(period)) {
+                result.add(fraction);
+            }
+        }
+        return result.isEmpty() ? null : result;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
diff -r 52504fc2cd58 -r ce35bdf3d750 artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadDataCalculate.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadDataCalculate.java	Wed Aug 27 15:01:54 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadDataCalculate.java	Wed Aug 27 15:09:45 2014 +0200
@@ -170,9 +170,11 @@
 
         int i = 0;
         for (Fraction fract: sdRes.getFractions()) {
-            logger.debug("Adding facet for fraction: " + fract.getName());
+            logger.debug("Adding facet for fraction '" + fract.getName() +
+                         "' and period '" + fract.getPeriod() + "'");
             facets.add(new SedimentLoadDataFacet(i++, fract.getName(),
-                          unit, ComputeType.ADVANCE, id, hash, context));
+                          unit, fract.getPeriod(),
+                          ComputeType.ADVANCE, id, hash, context));
         }
 
         facets.add(
diff -r 52504fc2cd58 -r ce35bdf3d750 artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java	Wed Aug 27 15:01:54 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java	Wed Aug 27 15:09:45 2014 +0200
@@ -100,8 +100,8 @@
         /* Prepare the values. The order of the fractions is given by the
          * header and thus static. */
 
-        /* The result is ordered by the peridods. For each period there is
-         * then a map of km - fractions pairs which are the actual result. */
+        /* The result is ordered by the periods. For each period there is
+         * then a map of km-fraction pairs which are the actual result. */
 
         TreeMap <String, TreeMap <Double, Double[]>> result_map =
             new TreeMap<String, TreeMap<Double, Double[]>>();


More information about the Dive4Elements-commits mailing list