changeset 8146:ce35bdf3d750

Let the facet know the period of it's data.
author Tom Gottfried <tom@intevation.de>
date Wed, 27 Aug 2014 15:09:45 +0200
parents 52504fc2cd58
children 8ad0b7bc3e73
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFacet.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataResult.java artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadDataCalculate.java artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java
diffstat 4 files changed, 32 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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();
--- 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 :
--- 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(
--- 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[]>>();

http://dive4elements.wald.intevation.org