changeset 8328:f0b78f7498ae

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 25 Sep 2014 17:25:07 +0200
parents 1e4e5ff44aa9 (diff) 02782ed6c8de (current diff)
children 274d606ea50e
files
diffstat 8 files changed, 54 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/conf.xml	Thu Sep 25 12:21:47 2014 +0200
+++ b/artifacts/doc/conf/conf.xml	Thu Sep 25 17:25:07 2014 +0200
@@ -13,6 +13,7 @@
     <!ENTITY porosity-artifact  SYSTEM "artifacts/porosity.xml">
     <!ENTITY gaugedischargecurve-artifact  SYSTEM "artifacts/gaugedischargecurve.xml">
     <!ENTITY sqrelation-artifact SYSTEM "artifacts/sqrelation.xml">
+    <!ENTITY sqrelation-datacage-artifact SYSTEM "artifacts/sqrelation-datacage.xml">
     <!ENTITY sedimentload-artifact  SYSTEM "artifacts/sedimentload.xml">
     <!ENTITY sedimentload-ls-artifact  SYSTEM "artifacts/sedimentload-ls.xml">
 
@@ -142,6 +143,9 @@
             <artifact-factory name="staticsqrelation" description="Factory to create an artifact that generates sq relations from db."
                 ttl="3600000"
                 artifact="org.dive4elements.river.artifacts.D4EArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+            <artifact-factory name="sqrelationdatacage" description="Factory to create an artifact that generates sq relations from db."
+                ttl="3600000"
+                artifact="org.dive4elements.river.artifacts.SQRelationArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="morph-width" description="Factory to create an artifact used in minfo datacage."
                 ttl="3600000"
                 artifact="org.dive4elements.river.artifacts.StaticMorphWidthArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
@@ -293,6 +297,7 @@
         <artifact name="gaugedischarge" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/gaugedischarge.xml" />
         <artifact name="qsector" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/qsector.xml" />
         &sqrelation-artifact;
+        &sqrelation-datacage-artifact;
         &porosity-artifact;
         &gaugedischargecurve-artifact;
         &sedimentload-artifact;
--- a/artifacts/doc/conf/meta-data.xml	Thu Sep 25 12:21:47 2014 +0200
+++ b/artifacts/doc/conf/meta-data.xml	Thu Sep 25 17:25:07 2014 +0200
@@ -2157,7 +2157,7 @@
                                            $start_time), ' bis ',
                                            dc:date-format('yyyy',
                                            $stop_time))"/>
-                        <sqvalue factory="staticsqrelation"
+                        <sqvalue factory="sqrelationdatacage"
                                  target_out="{$out}"
                                  ids="{$sqvid};{dc:uppercase($parameter)} - {$station_name}: {$combined_desc}"
                                  description="{$combined_desc}"/>
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/SQRelationArtifact.java	Thu Sep 25 12:21:47 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/SQRelationArtifact.java	Thu Sep 25 17:25:07 2014 +0200
@@ -37,7 +37,7 @@
     public static final String XPATH_RIVER = "/art:action/art:river/@art:name";
     public static final String XPATH_STATION =
         "/art:action/art:measurement_station/@art:number";
-    public static final String NAME = "staticsqrelation";
+    public static final String NAME = "sqrelationdatacage";
     public static final String STATIC_STATE_NAME = "state.sqrelation.static";
     public static final String UIPROVIDER = "static_sqrelation";
     public static final String SQ_RELATION_OUT_A = "sq_relation_a";
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java	Thu Sep 25 12:21:47 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java	Thu Sep 25 17:25:07 2014 +0200
@@ -24,6 +24,8 @@
 
 import org.apache.log4j.Logger;
 
+import static org.dive4elements.river.exports.injector.InjectorConstants.PNP;
+
 /**
  * A Facet that returns discharge curve data at a gauge
  *
@@ -77,7 +79,23 @@
         }
         double [] kms = new double[values[0].length];
         Arrays.fill(kms, gauge.getStation().doubleValue());
-        return new WQKms(kms, values[0], values[1], name, WQKms.CENTIMETER_AT_GAUGE);
+
+        Object pnpObject = context.getContextValue(PNP);
+        if (!(pnpObject instanceof Number)) {
+            return new WQKms(kms, values[0], values[1], name, W.CENTIMETER_AT_GAUGE);
+        }
+        double pnp = Double.valueOf(pnpObject.toString());
+        double[] ws = transformToM(values[1], pnp);
+
+        return new WQKms(kms, values[0], ws, name);
+    }
+
+    private double[] transformToM(double[] ws, double pnp) {
+        double[] retVals = new double[ws.length];
+        for (int i = 0; i < ws.length; i++) {
+            retVals[i] = ws[i]/100 + pnp;
+        }
+        return retVals;
     }
 
     @Override
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/ComputedDischargeInjector.java	Thu Sep 25 12:21:47 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/ComputedDischargeInjector.java	Thu Sep 25 17:25:07 2014 +0200
@@ -29,8 +29,11 @@
     ) {
         RangeAccess access = new RangeAccess((D4EArtifact)artifact);
         if (access.hasFrom()) {
-            double km = access.getFrom();
-            ctx.putContextValue(CURRENT_KM, km);
+            ctx.putContextValue(CURRENT_KM, access.getFrom());
+        }
+        else if (access.getLocations() != null &&
+            access.getLocations().length > 0) {
+            ctx.putContextValue(CURRENT_KM, access.getLocations()[0]);
         }
     }
 }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java	Thu Sep 25 12:21:47 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java	Thu Sep 25 17:25:07 2014 +0200
@@ -27,17 +27,22 @@
     @Override
     public void injectContext(CallContext ctx, Artifact artifact, Document doc) {
         RangeAccess access = new RangeAccess((D4EArtifact)artifact);
-        if (!access.hasFrom()) {
+        if (access.hasFrom()) {
+            ctx.putContextValue(CURRENT_KM, access.getFrom());
             return;
         }
-        double km = access.getFrom();
-        Gauge gauge = access.getRiver().determineGaugeByStation(
-            km - GAUGE_EPSILON, km + GAUGE_EPSILON);
-        if (gauge == null) {
-            log.error("No Gauge could be found at station " + km + "!");
+        D4EArtifact d4e = (D4EArtifact)artifact;
+        String name = d4e.getDataAsString("gauge_name");
+        if (name == null || name.equals("")) {
             return;
         }
-        ctx.putContextValue(CURRENT_KM, km);
+        Gauge gauge = access.getRiver().determineGaugeByName(name);
+        if (gauge == null) {
+            log.error("No Gauge could be found for name " + name + "!");
+            return;
+        }
+        ctx.putContextValue(CURRENT_KM, gauge.getStation());
+        return;
     }
 
 }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/FixWQInjector.java	Thu Sep 25 12:21:47 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/FixWQInjector.java	Thu Sep 25 17:25:07 2014 +0200
@@ -33,7 +33,7 @@
         Artifact artifact,
         Document request) {
         Double km = getCurrentKmFromRequest(request);
-        if (km == Double.NaN) {
+        if (Double.isNaN(km)) {
             RangeAccess access = new RangeAccess((D4EArtifact)artifact);
             km = access.getFrom();
             log.debug("from access");
--- a/artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java	Thu Sep 25 12:21:47 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java	Thu Sep 25 17:25:07 2014 +0200
@@ -1,5 +1,6 @@
 package org.dive4elements.river.exports.injector;
 
+import org.apache.log4j.Logger;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.ContextInjector;
@@ -17,6 +18,7 @@
 implements ContextInjector
 {
 
+    private Logger log = Logger.getLogger(PNPInjector.class);
     @Override
     public void setup(Element cfg) {
         // TODO Auto-generated method stub
@@ -31,19 +33,26 @@
     ) {
         Object currentKm = ctx.getContextValue(CURRENT_KM);
         if (currentKm == null) {
+            log.debug("no current km. not injecting pnp");
             return;
         }
 
         RiverAccess access = new RiverAccess((D4EArtifact)artifact);
-        Double km = (Double)currentKm;
+        Double km = Double.valueOf(currentKm.toString());
+        if (Double.isNaN(km) || Double.isInfinite(km)) {
+            log.debug("current km is NAN or infinte. not injecting pnp.");
+            return;
+        }
         Gauge gauge =
             access.getRiver().determineGaugeByStation(
                 km - GAUGE_EPSILON,
                 km + GAUGE_EPSILON);
 
         if (gauge == null) {
+            log.debug("no gauge found at current km. not injecting pnp");
             return;
         }
+        log.debug("injecting pnp: " + gauge.getDatum());
         ctx.putContextValue(PNP, gauge.getDatum());
     }
 

http://dive4elements.wald.intevation.org