[PATCH] Fixed adding missing files for the river bed collision counts selectable in the datacage
Wald Commits
scm-commit at wald.intevation.org
Wed Jun 6 08:03:30 CEST 2018
# HG changeset patch
# User mschaefer
# Date 1528264975 -7200
# Node ID 820ae41c81b6ea66178813d19304b75948f597b6
# Parent 3f619f8dfa8e4ddeb4d843a638979025f08b4b94
Fixed adding missing files for the river bed collision counts selectable in the datacage
diff -r 3f619f8dfa8e -r 820ae41c81b6 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionArtifact.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionArtifact.java Wed Jun 06 08:02:55 2018 +0200
@@ -0,0 +1,138 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ * Björnsen Beratende Ingenieure GmbH
+ * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.sinfo.collision;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifactdatabase.state.DefaultOutput;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifactdatabase.state.FacetActivity;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.ArtifactFactory;
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.river.artifacts.AbstractStaticStateArtifact;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.sinfo.common.CollisionCountProcessor;
+import org.dive4elements.river.artifacts.states.StaticState;
+import org.w3c.dom.Document;
+
+/**
+ * Display of a river bed collision data series loaded from database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class CollisionArtifact extends AbstractStaticStateArtifact implements FacetTypes {
+
+ /** The log for this class. */
+ private static Logger log = Logger.getLogger(CollisionArtifact.class);
+
+ /** Artifact name. */
+ private static final String NAME = "collision";
+
+ static {
+ // TODO: Move to configuration.
+ FacetActivity.Registry.getInstance().register(NAME, FacetActivity.INACTIVE);
+ }
+
+ public static final String STATIC_STATE_NAME = "state.collision.static";
+
+ /**
+ * Trivial Constructor.
+ */
+ public CollisionArtifact() {
+ log.debug("new CollisionArtifact");
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ /**
+ * Gets called from factory, to set things up.
+ */
+ @Override
+ public void setup(final String identifier, final ArtifactFactory factory, final Object context, final CallMeta callMeta, final Document data,
+ final List<Class> loadFacets) {
+
+ log.debug("CollisionArtifact.setup");
+
+ if (log.isDebugEnabled()) {
+ log.debug(XMLUtils.toString(data));
+ }
+
+ final String code = getDatacageIDValue(data);
+ final String[] parts = code.split("-");
+ if (parts.length >= 2)
+ addStringData("collision_id", parts[1]);
+ if (parts.length >= 3)
+ addStringData("year", parts[2]);
+ else
+ addStringData("year", "jahr?");
+ String seriesName;
+ if (parts.length >= 4)
+ seriesName = parts[3];
+ else
+ seriesName = "name?";
+
+ createFacets(callMeta, code, seriesName, getDataAsString("year"));
+
+ super.setup(identifier, factory, context, callMeta, data, loadFacets);
+ }
+
+ private void createFacets(final CallMeta callMeta, final String code, final String seriesName, final String year) {
+ if (code == null)
+ return;
+ final String[] parts = code.split("-");
+ if (parts.length < 2) {
+ log.error("Invalid datacage ID '" + code + "'");
+ return;
+ }
+ final ArrayList<Facet> facets = new ArrayList<>(2);
+ facets.add(CollisionCountProcessor.createFacet(callMeta, year));
+ // facets.add(CollisionGaugeWProcessor.createFacet(callMeta, seriesName)); //REMARK gauge_w is the cm above gauge datum,
+ // therefore only useful with transformation to NHN
+ addFacets(STATIC_STATE_NAME, facets);
+ }
+
+ @Override
+ protected void initStaticState() {
+
+ log.debug("initStaticState " + getName() + " " + identifier());
+
+ final StaticState state = new StaticState(STATIC_STATE_NAME);
+ final DefaultOutput output = new DefaultOutput("general", "general", "image/png", "chart");
+
+ final List<Facet> facets = getFacets(STATIC_STATE_NAME);
+ output.addFacets(facets);
+ state.addOutput(output);
+
+ setStaticState(state);
+ }
+
+ @Override
+ protected void initialize(final Artifact artifact, final Object context, final CallMeta meta) {
+ // do not clone facets, etc. from master artifact
+
+ log.debug("initialize");
+ importData((D4EArtifact) artifact, "river");
+ importData((D4EArtifact) artifact, "ld_from");
+ importData((D4EArtifact) artifact, "ld_to");
+
+ log.debug("ld_from " + getDataAsString("ld_from"));
+ log.debug("ld_to " + getDataAsString("ld_to"));
+ }
+}
\ No newline at end of file
diff -r 3f619f8dfa8e -r 820ae41c81b6 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionDbAccess.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionDbAccess.java Wed Jun 06 08:02:55 2018 +0200
@@ -0,0 +1,52 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ * Björnsen Beratende Ingenieure GmbH
+ * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.sinfo.collision;
+
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RangeAccess;
+
+/**
+ * Access to the database loaded river bed collision artifact data
+ *
+ * @author Matthias Schäfer
+ */
+final class CollisionDbAccess extends RangeAccess {
+
+ /***** FIELDS *****/
+
+ private Integer id;
+
+ private String name;
+
+
+ /***** CONSTRUCTORS *****/
+
+ public CollisionDbAccess(final D4EArtifact artifact) {
+ super(artifact);
+ }
+
+
+ /***** METHODS *****/
+
+ public Integer getId() {
+ if (this.id == null) {
+ this.id = getInteger("collision_id");
+ }
+ return this.id;
+ }
+
+ public String getName() {
+ if (this.name == null) {
+ this.name = getString("name");
+ }
+ return this.name;
+ }
+}
\ No newline at end of file
diff -r 3f619f8dfa8e -r 820ae41c81b6 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionFacet.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionFacet.java Wed Jun 06 08:02:55 2018 +0200
@@ -0,0 +1,81 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ * Björnsen Beratende Ingenieure GmbH
+ * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.sinfo.collision;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.common.GeneralResultType;
+import org.dive4elements.river.artifacts.common.ResultRow;
+import org.dive4elements.river.artifacts.model.BlackboardDataFacet;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
+import org.dive4elements.river.model.sinfo.Collision;
+import org.dive4elements.river.model.sinfo.CollisionAggregateValue;
+
+/**
+ * Facet for a river bed collision value series loaded from the database
+ *
+ * @author Matthias Schäfer
+ */
+public class CollisionFacet extends BlackboardDataFacet implements FacetTypes {
+
+ private static final long serialVersionUID = 1;
+
+ public CollisionFacet(final String name, final String description, final String yAxisLabel) {
+ super(0, name, description);
+
+ this.metaData.put("X", "chart.longitudinal.section.xaxis.label");
+ this.metaData.put("Y", yAxisLabel);
+ }
+
+ /**
+ * Returns the data this facet requires.
+ *
+ * @param artifact
+ * the owner artifact.
+ * @param context
+ * the CallContext (ignored).
+ *
+ * @return
+ * the data as CollisionQueryCalculationResult
+ */
+ @Override
+ public Object getData(final Artifact artifact, final CallContext context) {
+
+ final CollisionDbAccess access = new CollisionDbAccess((D4EArtifact) artifact);
+ final Collision series = Collision.getSeries(access.getId());
+ final List<CollisionAggregateValue> values = CollisionAggregateValue.getValuesByKm(series, access.getFrom(true), access.getTo(true));
+ final Collection<ResultRow> rows = new ArrayList<>();
+ for (final CollisionAggregateValue value : values) {
+ rows.add(ResultRow.create().putValue(GeneralResultType.station, value.getStation()) //
+ .putValue(SInfoResultType.collisionCount, value.getCount())
+ .putValue(SInfoResultType.collisionGaugeW, value.getGaugeW()));
+ }
+ return new CollisionQueryCalculationResult(series.getFilename(), rows);
+ }
+
+ /**
+ * Create a deep copy of this Facet.
+ *
+ * @return a deep copy.
+ */
+ @Override
+ public CollisionFacet deepCopy() {
+ final CollisionFacet copy = new CollisionFacet(this.name, this.description, this.metaData.get("Y"));
+ copy.set(this);
+ return copy;
+ }
+}
\ No newline at end of file
diff -r 3f619f8dfa8e -r 820ae41c81b6 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionQueryCalculationResult.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionQueryCalculationResult.java Wed Jun 06 08:02:55 2018 +0200
@@ -0,0 +1,29 @@
+/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ * Björnsen Beratende Ingenieure GmbH
+ * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.artifacts.sinfo.collision;
+
+import java.util.Collection;
+
+import org.dive4elements.river.artifacts.common.ResultRow;
+import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoCalculationResult;
+
+/**
+ * Contains the results of a database query of a river bed collision series
+ *
+ * @author Matthias Schäfer
+ */
+public final class CollisionQueryCalculationResult extends AbstractSInfoCalculationResult {
+
+ private static final long serialVersionUID = 1L;
+
+ public CollisionQueryCalculationResult(final String label, final Collection<ResultRow> rows) {
+ super(label, null, rows);
+ }
+}
\ No newline at end of file
diff -r 3f619f8dfa8e -r 820ae41c81b6 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/CollisionCountProcessor.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/CollisionCountProcessor.java Wed Jun 06 08:02:55 2018 +0200
@@ -0,0 +1,87 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ * Björnsen Beratende Ingenieure GmbH
+ * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.sinfo.common;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.collision.CollisionFacet;
+import org.dive4elements.river.artifacts.sinfo.collision.CollisionQueryCalculationResult;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.themes.ThemeDocument;
+
+/**
+ * Processor to generate a data series for bed collision count data loaded from the database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class CollisionCountProcessor extends AbstractSInfoProcessor {
+
+ // private final static Logger log = Logger.getLogger(CollisionCountProcessor.class);
+
+ public static final String FACET_COLLISION_COUNT = "sinfo_facet_collision_count";
+
+ private static final String I18N_AXIS_LABEL = "chart.longitudinal.section.yaxis.label";
+
+ private static final String I18N_SERIES_NAME_PATTERN = "collision.count.title";
+
+ private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
+
+ static {
+ HANDLED_FACET_TYPES.add(FACET_COLLISION_COUNT);
+ }
+
+ public CollisionCountProcessor() {
+ super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
+ }
+
+ @Override
+ protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
+
+ 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 CollisionQueryCalculationResult data = (CollisionQueryCalculationResult) 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 = data.getStationPoints(SInfoResultType.collisionCount);
+
+ StyledSeriesBuilder.addPoints(series, points, true);
+ generator.addAxisSeries(series, getAxisName(), visible);
+
+ return metaData.get("Y");
+ }
+
+ public static Facet createFacet(final CallMeta callMeta, final String seriesName) {
+ return new CollisionFacet(FACET_COLLISION_COUNT,
+ Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, seriesName), I18N_AXIS_LABEL);
+ }
+}
\ No newline at end of file
diff -r 3f619f8dfa8e -r 820ae41c81b6 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/CollisionGaugeWProcessor.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/CollisionGaugeWProcessor.java Wed Jun 06 08:02:55 2018 +0200
@@ -0,0 +1,87 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ * Björnsen Beratende Ingenieure GmbH
+ * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.sinfo.common;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.collision.CollisionFacet;
+import org.dive4elements.river.artifacts.sinfo.collision.CollisionQueryCalculationResult;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.themes.ThemeDocument;
+
+/**
+ * Processor to generate a data series for collision gauge W data loaded from the database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class CollisionGaugeWProcessor extends AbstractSInfoProcessor {
+
+ // private final static Logger log = Logger.getLogger(CollisionGaugeWProcessor.class);
+
+ public static final String FACET_COLLISION_GAUGEW = "sinfo_facet_collision_gaugew";
+
+ private static final String I18N_AXIS_LABEL = "chart.longitudinal.section.yaxis.label";
+
+ private static final String I18N_SERIES_NAME_PATTERN = "collision.gaugew.title";
+
+ private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
+
+ static {
+ HANDLED_FACET_TYPES.add(FACET_COLLISION_GAUGEW);
+ }
+
+ public CollisionGaugeWProcessor() {
+ super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
+ }
+
+ @Override
+ protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
+
+ 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 CollisionQueryCalculationResult data = (CollisionQueryCalculationResult) 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 = data.getStationPoints(SInfoResultType.collisionGaugeW);
+
+ StyledSeriesBuilder.addPoints(series, points, true);
+ generator.addAxisSeries(series, getAxisName(), visible);
+
+ return metaData.get("Y");
+ }
+
+ public static Facet createFacet(final CallMeta callMeta, final String seriesName) {
+ return new CollisionFacet(FACET_COLLISION_GAUGEW,
+ Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, seriesName), I18N_AXIS_LABEL);
+ }
+}
\ No newline at end of file
More information about the Dive4Elements-commits
mailing list