changeset 9460:8d6e56e57c4a

log-Ausgaben crossSection isStart
author gernotbelger
date Wed, 29 Aug 2018 16:57:13 +0200
parents f06e3766997f
children da7b5f07303d
files artifacts/src/main/java/org/dive4elements/river/artifacts/CrossSectionArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/FixationArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/BUNDUArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/CrossSectionFactory.java artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java backend/src/main/java/org/dive4elements/river/model/CrossSection.java
diffstat 6 files changed, 114 insertions(+), 184 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/CrossSectionArtifact.java	Tue Aug 28 19:21:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/CrossSectionArtifact.java	Wed Aug 29 16:57:13 2018 +0200
@@ -13,31 +13,22 @@
 import java.util.NavigableMap;
 
 import org.apache.log4j.Logger;
-
-import org.w3c.dom.Document;
-
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifactdatabase.state.FacetActivity;
+import org.dive4elements.artifactdatabase.state.State;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.ArtifactFactory;
 import org.dive4elements.artifacts.CallMeta;
-
 import org.dive4elements.river.artifacts.access.RangeAccess;
 import org.dive4elements.river.artifacts.model.CrossSectionFacet;
+import org.dive4elements.river.artifacts.model.CrossSectionFactory;
 import org.dive4elements.river.artifacts.model.FastCrossSectionLineFactory;
-
-import org.dive4elements.river.model.FastCrossSectionLine;
-
+import org.dive4elements.river.artifacts.services.CrossSectionKMService;
+import org.dive4elements.river.artifacts.states.StaticState;
 import org.dive4elements.river.model.CrossSection;
 import org.dive4elements.river.model.CrossSectionLine;
-import org.dive4elements.river.artifacts.model.CrossSectionFactory;
-
-import org.dive4elements.river.artifacts.states.StaticState;
-
-import org.dive4elements.artifactdatabase.state.Facet;
-import org.dive4elements.artifactdatabase.state.FacetActivity;
-import org.dive4elements.artifactdatabase.state.State;
-
-import org.dive4elements.river.artifacts.services.CrossSectionKMService;
-
+import org.dive4elements.river.model.FastCrossSectionLine;
+import org.w3c.dom.Document;
 
 /**
  * Artifact describing a cross-section.
@@ -60,10 +51,10 @@
     public static final String DATA_DBID = "cross_section.dbid";
 
     /** Name of data item flagging whether we think that we are master. */
-    public static final String DATA_IS_MASTER = "cross_section.master?";
+    private static final String DATA_IS_MASTER = "cross_section.master?";
 
     /** Name of data item flagging whether we are the newest. */
-    public static final String DATA_IS_NEWEST = "cross_section.newest?";
+    private static final String DATA_IS_NEWEST = "cross_section.newest?";
 
     /** Name of data item storing the previous possible km. */
     public static final String DATA_PREV_KM = "cross_section.km.previous";
@@ -72,28 +63,21 @@
     public static final String DATA_NEXT_KM = "cross_section.km.next";
 
     /** Own log. */
-    private static final Logger log =
-        Logger.getLogger(CrossSectionArtifact.class);
+    private static final Logger log = Logger.getLogger(CrossSectionArtifact.class);
 
     static {
         // TODO: Move to configuration.
-        FacetActivity.Registry.getInstance().register(
-            CS_ARTIFACT_NAME,
-            new FacetActivity() {
-                @Override
-                public Boolean isInitialActive(
-                    Artifact artifact,
-                    Facet    facet,
-                    String   outputName
-                ) {
-                    if (artifact instanceof D4EArtifact) {
-                        D4EArtifact flys = (D4EArtifact)artifact;
-                        String data = flys.getDataAsString(DATA_IS_NEWEST);
-                        return data != null && data.equals("1");
-                    }
-                    return null;
+        FacetActivity.Registry.getInstance().register(CS_ARTIFACT_NAME, new FacetActivity() {
+            @Override
+            public Boolean isInitialActive(final Artifact artifact, final Facet facet, final String outputName) {
+                if (artifact instanceof D4EArtifact) {
+                    final D4EArtifact flys = (D4EArtifact) artifact;
+                    final String data = flys.getDataAsString(DATA_IS_NEWEST);
+                    return data != null && data.equals("1");
                 }
-            });
+                return null;
+            }
+        });
     }
 
     /** Return given name. */
@@ -102,44 +86,33 @@
         return CS_ARTIFACT_NAME;
     }
 
-
     /** Store ids, create a CrossSectionFacet. */
     @Override
-    public void setup(
-        String          identifier,
-        ArtifactFactory factory,
-        Object          context,
-        CallMeta        callMeta,
-        Document        data,
-        List<Class>     loadFacets)
-    {
+    public void setup(final String identifier, final ArtifactFactory factory, final Object context, final CallMeta callMeta, final Document data,
+            final List<Class> loadFacets) {
         log.info("CrossSectionArtifact.setup");
 
         super.setup(identifier, factory, context, callMeta, data, loadFacets);
 
-        String ids = getDatacageIDValue(data);
+        final String ids = getDatacageIDValue(data);
 
         if (ids != null && ids.length() > 0) {
             addStringData(DATA_DBID, ids);
             log.debug("CrossSectionArtifacts db-id: " + ids);
-        }
-        else {
+        } else {
             throw new IllegalArgumentException("No attribute 'ids' found!");
         }
 
-        List<Facet> fs = new ArrayList<Facet>();
-        CrossSection cs = CrossSectionFactory.getCrossSection(
-            Integer.parseInt(ids));
+        final List<Facet> fs = new ArrayList<>();
+        final CrossSection cs = CrossSectionFactory.getCrossSection(Integer.parseInt(ids));
 
-        List<CrossSectionLine> csls = cs.getLines();
+        final List<CrossSectionLine> csls = cs.getLines();
         if (!csls.isEmpty()) {
-            CrossSectionLine csl = csls.get(0);
+            final CrossSectionLine csl = csls.get(0);
             // Find min-km of cross sections,
             // then set DATA_KM to min(DATA_KM, minCross).
-            String dataKmValue = getDataAsString(DATA_KM);
-            double dataKm = (dataKmValue != null)
-                ? Double.valueOf(dataKmValue)
-                : Double.MIN_VALUE;
+            final String dataKmValue = getDataAsString(DATA_KM);
+            final double dataKm = (dataKmValue != null) ? Double.valueOf(dataKmValue) : Double.MIN_VALUE;
             if (dataKm < csl.getKm().doubleValue()) {
                 addStringData(DATA_KM, csl.getKm().toString());
             }
@@ -147,57 +120,54 @@
         fs.add(new CrossSectionFacet(0, cs.getDescription()));
 
         // Find out if we are newest and become master if so.
-        boolean isNewest = cs.shouldBeMaster(getParentKm());
-        String newString = (isNewest) ? "1" : "0";
+        final boolean isNewest = cs.shouldBeMaster(getParentKm());
+        final String newString = (isNewest) ? "1" : "0";
         addStringData(DATA_IS_NEWEST, newString);
         addStringData(DATA_IS_MASTER, newString);
+        final StringBuilder builder = new StringBuilder();
+        builder.append("CrossSectionArtifact line 128 cross_section_id = ").append(cs.getId()).append(" IS_START? : ").append(String.valueOf(isNewest));
+        log.info(builder.toString()); // TODO: remove ALL
+        log.debug(builder.toString());
+        log.warn(builder.toString());
 
         if (!fs.isEmpty()) {
             addFacets(getCurrentStateId(), fs);
         }
     }
 
-
     /** Copy km where master-artifact "starts". */
     @Override
-    protected void initialize(
-        Artifact master,
-        Object   context,
-        CallMeta callMeta)
-    {
-        D4EArtifact masterArtifact = (D4EArtifact) master;
+    protected void initialize(final Artifact master, final Object context, final CallMeta callMeta) {
+        final D4EArtifact masterArtifact = (D4EArtifact) master;
 
-        RangeAccess rangeAccess = new RangeAccess(masterArtifact);
-        double[] range = rangeAccess.getKmRange();
+        final RangeAccess rangeAccess = new RangeAccess(masterArtifact);
+        final double[] range = rangeAccess.getKmRange();
         if (range != null && range.length > 0) {
             this.addStringData(DATA_KM, Double.toString(range[0]));
             this.addStringData(PARENT_KM, Double.toString(range[0]));
         }
     }
 
-
     /** Returns next possible km for a cross-section. */
     public Double getNextKm() {
         return getDataAsDouble(DATA_NEXT_KM);
     }
 
-
     /** Returns previous possible km for a cross-section. */
     public Double getPrevKm() {
         return getDataAsDouble(DATA_PREV_KM);
     }
 
-
     /**
      * Create and return a new StaticState with charting output.
      */
     @Override
-    public State getCurrentState(Object cc) {
+    public State getCurrentState(final Object cc) {
         final List<Facet> fs = getFacets(getCurrentStateId());
 
-        StaticState state = new StaticState(STATIC_STATE_NAME) {
+        final StaticState state = new StaticState(STATIC_STATE_NAME) {
             @Override
-            public Object staticCompute(List<Facet> facets) {
+            public Object staticCompute(final List<Facet> facets) {
                 if (facets != null) {
                     facets.addAll(fs);
                 }
@@ -210,15 +180,16 @@
         return state;
     }
 
-
     /**
      * Get a list containing the one and only State.
-     * @param  context ignored.
+     *
+     * @param context
+     *            ignored.
      * @return list with one and only state.
      */
     @Override
-    protected List<State> getStates(Object context) {
-        ArrayList<State> states = new ArrayList<State>();
+    protected List<State> getStates(final Object context) {
+        final ArrayList<State> states = new ArrayList<>();
         states.add(getCurrentState(context));
 
         return states;
@@ -229,29 +200,27 @@
     /**
      * Get a DataItem casted to int (0 if fails).
      */
-    public int getDataAsIntNull(String dataName) {
-        String val = getDataAsString(dataName);
+    public int getDataAsIntNull(final String dataName) {
+        final String val = getDataAsString(dataName);
         try {
             return Integer.parseInt(val);
         }
-        catch (NumberFormatException e) {
+        catch (final NumberFormatException e) {
             log.warn("Could not get data " + dataName + " as int", e);
             return 0;
         }
     }
 
-
     /** Returns database-id of cross-section (from data). */
     protected int getDBID() {
         return getDataAsIntNull(DATA_DBID);
     }
 
-
     /**
      * Return position (km) from parent (initial km), 0 if not found.
      */
     private double getParentKm() {
-        String val = getDataAsString(PARENT_KM);
+        final String val = getDataAsString(PARENT_KM);
         if (val == null) {
             log.warn("Empty data: " + PARENT_KM);
             return 0;
@@ -259,7 +228,7 @@
         try {
             return Double.valueOf(val);
         }
-        catch (NumberFormatException e) {
+        catch (final NumberFormatException e) {
             log.warn("Could not get data " + PARENT_KM + " as double", e);
             return 0;
         }
@@ -269,41 +238,37 @@
      * Return position (km) from data, 0 if not found.
      */
     protected double getKm() {
-        String val = getDataAsString(DATA_KM);
+        final String val = getDataAsString(DATA_KM);
         try {
             return Double.valueOf(val);
         }
-        catch (NumberFormatException e) {
+        catch (final NumberFormatException e) {
             log.warn("Could not get data " + DATA_KM + " as double", e);
             return 0;
         }
     }
 
-
-    /** Returns true if artifact is set to be a "master" (other facets will
-     * refer to this). */
+    /**
+     * Returns true if artifact is set to be a "master" (other facets will
+     * refer to this).
+     */
     public boolean isMaster() {
         return !getDataAsString(DATA_IS_MASTER).equals("0");
     }
 
-
     /**
      * Get points of Profile of cross section at given kilometer.
      *
      * @return an array holding coordinates of points of profile (
      *         in the form {{x1, x2} {y1, y2}} ).
      */
-    public double [][] getCrossSectionData() {
-        log.info("getCrossSectionData() for cross_section.km "
-            + getDataAsString(DATA_KM));
-        FastCrossSectionLine line = searchCrossSectionLine();
+    public double[][] getCrossSectionData() {
+        log.info("getCrossSectionData() for cross_section.km " + getDataAsString(DATA_KM));
+        final FastCrossSectionLine line = searchCrossSectionLine();
 
-        return line != null
-               ? line.fetchCrossSectionProfile()
-               : null;
+        return line != null ? line.fetchCrossSectionProfile() : null;
     }
 
-
     /**
      * Get CrossSectionLine spatially closest to what is specified in the data
      * "cross_section.km", null if considered too far.
@@ -315,38 +280,31 @@
      *         if considered too far.
      */
     public FastCrossSectionLine searchCrossSectionLine() {
-        double TOO_FAR = 1d;
-        CrossSection crossSection = CrossSectionFactory
-            .getCrossSection(getDBID());
+        final double TOO_FAR = 1d;
+        final CrossSection crossSection = CrossSectionFactory.getCrossSection(getDBID());
 
         if (log.isDebugEnabled()) {
             log.debug("dbid " + getDBID() + " : " + crossSection);
         }
 
-        NavigableMap<Double, Integer> kms = CrossSectionKMService
-            .getKms(crossSection.getId());
+        final NavigableMap<Double, Integer> kms = CrossSectionKMService.getKms(crossSection.getId());
 
-        Double wishKM = getKm();
+        final Double wishKM = getKm();
 
-        Double floor = kms.floorKey(wishKM);
-        Double ceil  = kms.ceilingKey(wishKM);
+        final Double floor = kms.floorKey(wishKM);
+        final Double ceil = kms.ceilingKey(wishKM);
 
         Double nextKm;
         Double prevKm;
 
-        double floorD = floor != null
-            ? Math.abs(floor - wishKM)
-            : Double.MAX_VALUE;
+        final double floorD = floor != null ? Math.abs(floor - wishKM) : Double.MAX_VALUE;
 
-        double ceilD = ceil != null
-            ? Math.abs(ceil - wishKM)
-            : Double.MAX_VALUE;
+        final double ceilD = ceil != null ? Math.abs(ceil - wishKM) : Double.MAX_VALUE;
 
         double km;
         if (floorD < ceilD) {
             km = floor;
-        }
-        else {
+        } else {
             km = ceil;
         }
 
@@ -369,8 +327,7 @@
         addStringData(DATA_PREV_KM, prevKm.toString());
         addStringData(DATA_NEXT_KM, nextKm.toString());
 
-        return FastCrossSectionLineFactory
-            .getCrossSectionLine(crossSection, km);
+        return FastCrossSectionLineFactory.getCrossSectionLine(crossSection, km);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/FixationArtifact.java	Tue Aug 28 19:21:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/FixationArtifact.java	Wed Aug 29 16:57:13 2018 +0200
@@ -8,21 +8,14 @@
 
 package org.dive4elements.river.artifacts;
 
-import java.io.Serializable;
-
 import org.apache.log4j.Logger;
-import org.dive4elements.artifacts.CallContext;
-import org.dive4elements.river.artifacts.model.CalculationResult;
-import org.dive4elements.river.artifacts.model.WKms;
-import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult;
-import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
 
 /**
  * The default fixation analysis artifact.
  *
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class FixationArtifact extends D4EArtifact implements WaterLineArtifact {
+public class FixationArtifact extends AbstractFixBunduArtifact {
 
     private static final long serialVersionUID = 1L;
 
@@ -38,7 +31,7 @@
      * The default constructor.
      */
     public FixationArtifact() {
-        log.debug("ctor()");
+        super();
     }
 
     /**
@@ -51,24 +44,4 @@
         return ARTIFACT_NAME;
     }
 
-    /** Calculate waterlines against a cross section. */
-    @Override
-    public double getWaterLevel(final ComputeType type, final String hash, final String stateId, final double currentKm, final Serializable waterLineIndex,
-            final double nextKm, final double prevKm, final CallContext context) {
-        final FixRealizingResult result = (FixRealizingResult) ((CalculationResult) this.compute(context, ComputeType.ADVANCE, false)).getData();
-
-        final int wstIndex = (Integer) waterLineIndex;
-
-        final WKms wkms = result.getWQKms()[wstIndex];
-
-        // Find W at km.
-        final double wAtKm = StaticWKmsArtifact.getWAtKm(wkms, currentKm);
-
-        if (wAtKm == -1 || Double.isNaN(wAtKm)) {
-            log.warn("Waterlevel at km " + currentKm + " unknown.");
-            return Double.NaN;
-        }
-
-        return wAtKm;
-    }
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/BUNDUArtifact.java	Tue Aug 28 19:21:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/BUNDUArtifact.java	Wed Aug 29 16:57:13 2018 +0200
@@ -13,7 +13,7 @@
 import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.artifactdatabase.state.FacetActivity;
 import org.dive4elements.artifacts.Artifact;
-import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.AbstractFixBunduArtifact;
 import org.dive4elements.river.artifacts.bundu.bezugswst.BezugswstDepthProcessor;
 import org.dive4elements.river.artifacts.bundu.bezugswst.BezugswstHeightProcessor;
 import org.dive4elements.river.artifacts.model.FacetTypes;
@@ -23,7 +23,7 @@
  *
  * @author Gernot Belger
  */
-public class BUNDUArtifact extends D4EArtifact {
+public class BUNDUArtifact extends AbstractFixBunduArtifact {
 
     private static final long serialVersionUID = 1L;
 
@@ -98,4 +98,5 @@
     public String getRiver() {
         return getDataAsString(FIELD_RIVER);
     }
+
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/CrossSectionFactory.java	Tue Aug 28 19:21:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/CrossSectionFactory.java	Wed Aug 29 16:57:13 2018 +0200
@@ -28,35 +28,35 @@
  */
 public class CrossSectionFactory {
 
-    protected final static String CACHE_NAME = "cross_sections";
-
-    // TODO use caching consistently, streamline access.
-    /**
-     * Get CrossSections for an instantiated River.
-     *
-     * @param river river object.
-     *
-     * @return List of Cross Sections of river.
-     */
-    public static List<CrossSection> getCrossSections(River river) {
-        return getCrossSections(river.getName());
-    }
+    private final static String CACHE_NAME = "cross_sections";
 
-
-    /**
-     * Get Cross Sections for a river by name.
-     *
-     * @param riverName name of the river of interest.
-     *
-     * @return List of Cross Sections of river.
-     */
-    public static List<CrossSection> getCrossSections(String riverName) {
-        Session session = SessionHolder.HOLDER.get();
-        Query query = session.createQuery(
-            "from CrossSection where river.name = :rivername");
-        query.setParameter("rivername", riverName);
-        return query.list();
-    }
+//    // TODO use caching consistently, streamline access.
+//    /**
+//     * Get CrossSections for an instantiated River.
+//     *
+//     * @param river river object.
+//     *
+//     * @return List of Cross Sections of river.
+//     */
+//    public static List<CrossSection> getCrossSections(River river) {
+//        return getCrossSections(river.getName());
+//    }
+//
+//
+//    /**
+//     * Get Cross Sections for a river by name.
+//     *
+//     * @param riverName name of the river of interest.
+//     *
+//     * @return List of Cross Sections of river.
+//     */
+//    public static List<CrossSection> getCrossSections(String riverName) {
+//        Session session = SessionHolder.HOLDER.get();
+//        Query query = session.createQuery(
+//            "from CrossSection where river.name = :rivername");
+//        query.setParameter("rivername", riverName);
+//        return query.list();
+//    }
 
 
 
@@ -84,7 +84,7 @@
 
 
     /** Get specific CrossSection from database. */
-    protected static CrossSection getCrossSectionUncached(int id) {
+    private static CrossSection getCrossSectionUncached(int id) {
         Session session = SessionHolder.HOLDER.get();
         Query query = session.createQuery(
                 "from CrossSection where id=:id");
--- a/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java	Tue Aug 28 19:21:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java	Wed Aug 29 16:57:13 2018 +0200
@@ -25,14 +25,13 @@
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.artifacts.common.utils.Config;
+import org.dive4elements.river.artifacts.AbstractFixBunduArtifact;
 import org.dive4elements.river.artifacts.D4EArtifact;
-import org.dive4elements.river.artifacts.FixationArtifact;
 import org.dive4elements.river.artifacts.StaticWQKmsArtifact;
 import org.dive4elements.river.artifacts.WINFOArtifact;
 import org.dive4elements.river.artifacts.access.FixRealizingAccess;
 import org.dive4elements.river.artifacts.access.IsOfficialAccess;
 import org.dive4elements.river.artifacts.access.RangeAccess;
-import org.dive4elements.river.artifacts.bundu.BUNDUArtifact;
 import org.dive4elements.river.artifacts.model.CalculationResult;
 import org.dive4elements.river.artifacts.model.ConstantWQKms;
 import org.dive4elements.river.artifacts.model.Segment;
@@ -615,7 +614,7 @@
 
         desc = getDesc(wqkms, isQ);
 
-        if (flys instanceof FixationArtifact || flys instanceof BUNDUArtifact) {
+        if (flys instanceof AbstractFixBunduArtifact) {
             // Get W/Q input per gauge for this case.
             final FixRealizingAccess fixAccess = new FixRealizingAccess(flys);
             segments = fixAccess.getSegments();
--- a/backend/src/main/java/org/dive4elements/river/model/CrossSection.java	Tue Aug 28 19:21:44 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/CrossSection.java	Wed Aug 29 16:57:13 2018 +0200
@@ -48,9 +48,9 @@
     private static Logger log =
         Logger.getLogger(CrossSection.class);
 
-    public static final MathContext PRECISION = new MathContext(6);
+    private static final MathContext PRECISION = new MathContext(6);
 
-    public static final String SQL_FAST_CROSS_SECTION_LINES =
+    private static final String SQL_FAST_CROSS_SECTION_LINES =
         "SELECT km, x, y, csl.id AS csl_id " +
         "FROM cross_section_lines csl JOIN cross_section_points csp " +
         "ON csp.cross_section_line_id = csl.id " +
@@ -58,7 +58,7 @@
         "km between :from_km AND :to_km " +
         "ORDER BY csl.km, csl.id, csp.col_pos";
 
-    public static final String SQL_MIN_MAX =
+    private static final String SQL_MIN_MAX =
         "SELECT * FROM ( "+
             "SELECT cross_section_id, MIN(km) AS minkm, MAX(km) AS maxkm " +
             "FROM cross_section_lines " +

http://dive4elements.wald.intevation.org