Mercurial > dive4elements > river
changeset 8326:10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 25 Sep 2014 17:23:12 +0200 |
parents | a5e7e2d833ea |
children | 1e4e5ff44aa9 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java artifacts/src/main/java/org/dive4elements/river/exports/injector/ComputedDischargeInjector.java artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java artifacts/src/main/java/org/dive4elements/river/exports/injector/FixWQInjector.java artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java |
diffstat | 5 files changed, 47 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java Wed Sep 24 18:33:11 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java Thu Sep 25 17:23:12 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 Wed Sep 24 18:33:11 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/ComputedDischargeInjector.java Thu Sep 25 17:23:12 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 Wed Sep 24 18:33:11 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java Thu Sep 25 17:23:12 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 Wed Sep 24 18:33:11 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/FixWQInjector.java Thu Sep 25 17:23:12 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 Wed Sep 24 18:33:11 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java Thu Sep 25 17:23:12 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()); }