[PATCH] Individual facets/themes for single years i the S-Info collisions output

Wald Commits scm-commit at wald.intevation.org
Mon Jul 2 17:41:02 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1530546039 -7200
# Node ID 4f411c6ee3aec4c9fa9be05b1823d71e39782889
# Parent  9831f6c60473e86cf6346b6e8c440e98c8880aae
Individual facets/themes for single years i the S-Info collisions output

diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/doc/conf/artifacts/sinfo.xml
--- a/artifacts/doc/conf/artifacts/sinfo.xml	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/doc/conf/artifacts/sinfo.xml	Mon Jul 02 17:40:39 2018 +0200
@@ -281,6 +281,8 @@
         <outputmode name="sinfo_collision" description="output.sinfo_collision" mime-type="image/png" type="chart">
           <facets>
             <facet name="sinfo_facet_collision_calc_count" description="bed collisions" />
+            <facet name="sinfo_facet_collision_calc_count.2" description="bed collisions" />
+            <facet name="sinfo_facet_collision_calc_count.3" description="bed collisions" />
             <facet name="longitudinal_section.annotations" description="facet.longitudinal_section.annotations" />
             <facet name="sinfo_collision.manualpoints" description="Manual Points" />
           </facets>
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/doc/conf/themes.xml
--- a/artifacts/doc/conf/themes.xml	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/doc/conf/themes.xml	Mon Jul 02 17:40:39 2018 +0200
@@ -442,6 +442,9 @@
         <mapping from="sinfo_facet_bedheight_difference.filtered" to="SInfoBedHeightDifference" />
         
         <mapping from="sinfo_facet_collision_calc_count" to="SInfoCollisionCount" />
+        <mapping from="sinfo_facet_collision_calc_count.2" to="SInfoCollisionCount2" />
+        <mapping from="sinfo_facet_collision_calc_count.3" to="SInfoCollisionCount3" />
+        
         <mapping from="sinfo_facet_flood_duration" to="SInfoFloodDuration" />
         <mapping from="mainvalue.1.duration" to="SInfoMainValues1" />
         <mapping from="mainvalue.2.duration" to="SInfoMainValues2" />
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/doc/conf/themes/default.xml
--- a/artifacts/doc/conf/themes/default.xml	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/doc/conf/themes/default.xml	Mon Jul 02 17:40:39 2018 +0200
@@ -3070,6 +3070,24 @@
         </inherits>
         <fields>
             <field name="pointsize" type="int" display="Punktdicke" default="3" />
+            <field name="pointcolor" type="Color" display="Punktfarbe" default="64, 192, 64" />
+        </fields>
+    </theme>
+    <theme name="SInfoCollisionCount2">
+        <inherits>
+            <inherit from="LongitudinalSectionPoints" />
+        </inherits>
+        <fields>
+            <field name="pointsize" type="int" display="Punktdicke" default="2" />
+            <field name="pointcolor" type="Color" display="Punktfarbe" default="192, 0, 0" />
+        </fields>
+    </theme>
+    <theme name="SInfoCollisionCount3">
+        <inherits>
+            <inherit from="LongitudinalSectionPoints" />
+        </inherits>
+        <fields>
+            <field name="pointsize" type="int" display="Punktdicke" default="2" />
             <field name="pointcolor" type="Color" display="Punktfarbe" default="48, 96, 255" />
         </fields>
     </theme>
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/doc/conf/themes/second.xml
--- a/artifacts/doc/conf/themes/second.xml	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/doc/conf/themes/second.xml	Mon Jul 02 17:40:39 2018 +0200
@@ -3058,6 +3058,24 @@
         </inherits>
         <fields>
             <field name="pointsize" type="int" display="Punktdicke" default="3" />
+            <field name="pointcolor" type="Color" display="Punktfarbe" default="64, 192, 64" />
+        </fields>
+    </theme>
+    <theme name="SInfoCollisionCount2">
+        <inherits>
+            <inherit from="LongitudinalSectionPoints" />
+        </inherits>
+        <fields>
+            <field name="pointsize" type="int" display="Punktdicke" default="2" />
+            <field name="pointcolor" type="Color" display="Punktfarbe" default="192, 0, 0" />
+        </fields>
+    </theme>
+    <theme name="SInfoCollisionCount3">
+        <inherits>
+            <inherit from="LongitudinalSectionPoints" />
+        </inherits>
+        <fields>
+            <field name="pointsize" type="int" display="Punktdicke" default="2" />
             <field name="pointcolor" type="Color" display="Punktfarbe" default="48, 96, 255" />
         </fields>
     </theme>
@@ -3070,7 +3088,7 @@
             <field name="pointcolor" type="Color" display="Punktfarbe" default="68, 216, 40" />
         </fields>
     </theme>
-    <theme name="MainValues1">
+    <theme name="SInfoMainValues1">
         <inherits>
             <inherit from="MainValuesW" />
         </inherits>
@@ -3078,7 +3096,7 @@
             <field name="linecolor" type="Color" display="Farbe" default="0, 96, 192" />
         </fields>
     </theme>
-    <theme name="MainValues2">
+    <theme name="SInfoMainValues2">
         <inherits>
             <inherit from="MainValuesW" />
         </inherits>
@@ -3086,7 +3104,7 @@
             <field name="linecolor" type="Color" display="Farbe" default="192, 0, 0" />
         </fields>
     </theme>
-    <theme name="MainValues3">
+    <theme name="SInfoMainValues3">
         <inherits>
             <inherit from="MainValuesW" />
         </inherits>
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCalculationResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCalculationResult.java	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCalculationResult.java	Mon Jul 02 17:40:39 2018 +0200
@@ -66,6 +66,10 @@
         return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
     }
 
+    public double[][] getStationPoints(final IResultType type, final int index) {
+        return getStationPoints(type);
+    }
+
     protected final <TYPE> List<TYPE> getValues(final IResultType type) {
 
         final List<TYPE> values = new ArrayList<>();
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcFacet.java	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcFacet.java	Mon Jul 02 17:40:39 2018 +0200
@@ -47,7 +47,7 @@
 
         final CollisionCalculationResults data = (CollisionCalculationResults) res.getData();
 
-        return data.getResults().get(this.index);
+        return data.getResults().get(0); // first result is always the one and only CollisionCalcOverviewResult
     }
 
     /** Copy deeply. */
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcOverviewResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcOverviewResult.java	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcOverviewResult.java	Mon Jul 02 17:40:39 2018 +0200
@@ -16,11 +16,14 @@
 import org.dive4elements.river.artifacts.common.ExportContextCSV;
 import org.dive4elements.river.artifacts.common.ExportContextPDF;
 import org.dive4elements.river.artifacts.common.GeneralResultType;
+import org.dive4elements.river.artifacts.common.IResultType;
 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
 import org.dive4elements.river.artifacts.common.ResultRow;
 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
 
+import gnu.trove.TDoubleArrayList;
+
 /**
  * Contains the results of a {@link CollisionCalculation}.
  *
@@ -32,8 +35,36 @@
 
     private static final String JASPER_FILE = "/jasper/templates/sinfo.collision.overview.jrxml";
 
-    public CollisionCalcOverviewResult(final String label, final Collection<ResultRow> rows) {
+    private final int[] singleYears;
+
+    public CollisionCalcOverviewResult(final String label, final int[] singleYears, final Collection<ResultRow> rows) {
         super(label, rows);
+        this.singleYears = singleYears;
+    }
+
+    public int[] getSingleYears() {
+        return this.singleYears;
+    }
+
+    @Override
+    public double[][] getStationPoints(final IResultType type, final int index) {
+
+        final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
+        final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
+
+        for (final ResultRow row : this.rows) {
+
+            if ((this.singleYears == null) || (Integer.valueOf(row.getValue(SInfoResultType.years).toString()) == this.singleYears[index])) {
+
+                final double station = row.getDoubleValue(GeneralResultType.station);
+                final double value = row.getDoubleValue(type);
+
+                xPoints.add(station);
+                yPoints.add(value);
+            }
+        }
+
+        return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
     }
 
     @Override
@@ -45,7 +76,7 @@
     public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) {
         final int colSize = 3;
         exportContextCSV.writeTitleForTabs("sinfo.export.csv.title.collison.overview", 3); // Voraussetzung für Tabs ist, dass der Titel vor den Headern
-                                                                                           // geschrieben wird.
+        // geschrieben wird.
         // Das ist etwas doof.
 
         final Collection<String> header = new ArrayList<>(colSize);
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalculation.java	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalculation.java	Mon Jul 02 17:40:39 2018 +0200
@@ -74,7 +74,7 @@
             for (final DateRange dr : access.getEpochs())
                 calculateOverview(overViewRows, river, access.getLowerKm(), access.getUpperKm(), dr.getFromYear(), dr.getToYear(), true);
         }
-        final CollisionCalcOverviewResult overviewResult = new CollisionCalcOverviewResult(access.getYearsHeader(), overViewRows);
+        final CollisionCalcOverviewResult overviewResult = new CollisionCalcOverviewResult(access.getYearsHeader(), access.getYears(), overViewRows);
         results.addResult(overviewResult, problems);
 
         // create q-for-w-finders for all gauges of the calculation km range
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionState.java	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionState.java	Mon Jul 02 17:40:39 2018 +0200
@@ -78,10 +78,18 @@
 
         /* add themes for chart, for each result */
         final List<AbstractCalculationExportableResult> resultList = results.getResults();
+        int j = -1;
         for (int index = 0; index < resultList.size(); index++) {
             if (resultList.get(index) instanceof CollisionCalcOverviewResult) {
                 final CollisionCalcOverviewResult result = (CollisionCalcOverviewResult) resultList.get(index);
-                facets.add(CollisionCalcProcessor.createFacet(context, hash, this.id, result, index));
+                if (result.getSingleYears() == null)
+                    facets.add(CollisionCalcProcessor.createFacet(context, hash, this.id, result, index));
+                else {
+                    for (int i = 0; i <= result.getSingleYears().length - 1; i++) {
+                        j++;
+                        facets.add(CollisionCalcProcessor.createFacet(context, hash, this.id, result, j));
+                    }
+                }
             }
         }
 
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoProcessor.java	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoProcessor.java	Mon Jul 02 17:40:39 2018 +0200
@@ -104,6 +104,38 @@
         return metaData.get("Y");
     }
 
+    protected final String buildSeriesForType1(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme,
+            final boolean visible,
+            final IResultType resultType, final Double gapDistance) {
+        final CallContext context = generator.getContext();
+        final Map<String, String> metaData = bundle.getFacet().getMetaData();
+
+        final Artifact artifact = bundle.getArtifact();
+
+        final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
+        series.putMetaData(metaData, artifact, context);
+
+        final String facetName = bundle.getFacetName();
+
+        final AbstractCalculationResult data = (AbstractCalculationResult) bundle.getData(context);
+        if (data == null) {
+            // Check has been here before so we keep it for security reasons
+            // this should never happen though.
+            throw new IllegalStateException("Data is null for facet: " + facetName);
+        }
+
+        final double[][] points = generatePoints(context, artifact, data, facetName, resultType, bundle.getFacet().getIndex());
+
+        if (gapDistance == null)
+            StyledSeriesBuilder.addPoints(series, points, true);
+        else
+            StyledSeriesBuilder.addPoints(series, points, true, gapDistance);
+
+        generator.addAxisSeries(series, getAxisName(), visible);
+
+        return metaData.get("Y");
+    }
+
     protected final String buildSeriesForTkh(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme,
             final boolean visible) {
         final CallContext context = generator.getContext();
@@ -162,6 +194,18 @@
         return points;
     }
 
+    private double[][] generatePoints(final CallContext context, final Artifact artifact, final AbstractCalculationResult data, final String facetName,
+            final IResultType resultType, final int index) {
+
+        final double[][] points = data.getStationPoints(resultType, index);
+        if (facetName.endsWith(".filtered")) {
+            final Double radius = findRadius(context, artifact);
+            return movingAverage(radius, points);
+        }
+
+        return points;
+    }
+
     private double[][] movingAverage(final Double radius, final double[][] points) {
 
         if (radius == null)
diff -r 9831f6c60473 -r 4f411c6ee3ae artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/CollisionCalcProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/CollisionCalcProcessor.java	Mon Jul 02 13:00:59 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/CollisionCalcProcessor.java	Mon Jul 02 17:40:39 2018 +0200
@@ -19,6 +19,7 @@
 import org.dive4elements.river.artifacts.common.AbstractCalculationResult;
 import org.dive4elements.river.artifacts.resources.Resources;
 import org.dive4elements.river.artifacts.sinfo.collision.CollisionCalcFacet;
+import org.dive4elements.river.artifacts.sinfo.collision.CollisionCalcOverviewResult;
 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
 import org.dive4elements.river.exports.DiagramGenerator;
 import org.dive4elements.river.themes.ThemeDocument;
@@ -33,6 +34,10 @@
 
     public static final String FACET_COLLISION_CALC_COUNT = "sinfo_facet_collision_calc_count";
 
+    public static final String FACET_COLLISION_CALC_COUNT_2 = "sinfo_facet_collision_calc_count.2";
+
+    public static final String FACET_COLLISION_CALC_COUNT_3 = "sinfo_facet_collision_calc_count.3";
+
     private static final String I18N_AXIS_LABEL = "chart.collision_count.section.yaxis.label";
 
     private static final String I18N_SERIES_NAME_PATTERN = "collision.count.title";
@@ -41,6 +46,8 @@
 
     static {
         HANDLED_FACET_TYPES.add(FACET_COLLISION_CALC_COUNT);
+        HANDLED_FACET_TYPES.add(FACET_COLLISION_CALC_COUNT_2);
+        HANDLED_FACET_TYPES.add(FACET_COLLISION_CALC_COUNT_3);
     }
 
     public CollisionCalcProcessor() {
@@ -50,12 +57,24 @@
     @Override
     protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
 
-        return buildSeriesForType(generator, bundle, theme, visible, SInfoResultType.collisionCount, null);
+        return buildSeriesForType1(generator, bundle, theme, visible, SInfoResultType.collisionCount, null);
     }
 
     public static final Facet createFacet(final CallContext context, final String hash, final String id, final AbstractCalculationResult result,
             final int index) {
-        final String facetDescription = Resources.getMsg(context.getMeta(), I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, result.getLabel());
-        return new CollisionCalcFacet(index, FACET_COLLISION_CALC_COUNT, facetDescription, I18N_AXIS_LABEL, ComputeType.ADVANCE, id, hash);
+
+        final CollisionCalcOverviewResult ccoResult = (CollisionCalcOverviewResult) result;
+        String facetDescription;
+        String facetName;
+        if (ccoResult.getSingleYears() == null) {
+            facetDescription = Resources.getMsg(context.getMeta(), I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, result.getLabel());
+            facetName = FACET_COLLISION_CALC_COUNT;
+        }
+        else {
+            facetDescription = Resources.getMsg(context.getMeta(), I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN,
+                    Integer.toString(ccoResult.getSingleYears()[index]));
+            facetName = new String[] { FACET_COLLISION_CALC_COUNT, FACET_COLLISION_CALC_COUNT_2, FACET_COLLISION_CALC_COUNT_3 }[index % 3].toString();
+        }
+        return new CollisionCalcFacet(index, facetName, facetDescription, I18N_AXIS_LABEL, ComputeType.ADVANCE, id, hash);
     }
 }
\ No newline at end of file


More information about the Dive4Elements-commits mailing list