Mercurial > dive4elements > river
changeset 8253:b6d54b946f4c
merged.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 10 Sep 2014 10:02:46 +0200 |
parents | 1e30489d0958 (diff) 2414154673e9 (current diff) |
children | c87c87544cc6 5b87aaac8447 |
files | |
diffstat | 7 files changed, 214 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/doc/conf/generators/discharge-diagram-defaults.xml Tue Sep 09 20:08:12 2014 +0200 +++ b/artifacts/doc/conf/generators/discharge-diagram-defaults.xml Wed Sep 10 10:02:46 2014 +0200 @@ -1,11 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <discharge-defaults> <axis name="W"/> - <domain-axis key="chart.discharge.xaxis.label" default="Q [m\u00b3/s]"/> - <subtitle key="chart.computed.discharge.curve.subtitle" default="-"> - <arg expr="artifact.river"/> - <arg expr="artifact.ld_locations" type="double"/> - </subtitle> + <domain-axis key="chart.discharge.xaxis.label" default="Q [kubikmeter]"/> <processor class="org.dive4elements.river.exports.process.DischargeProcessor" axis="W"/> <processor class="org.dive4elements.river.exports.process.MiscDischargeProcessor" axis="W"/> <processor class="org.dive4elements.river.exports.process.ComputedDischargeProcessor" axis="W"/>
--- a/artifacts/doc/conf/generators/discharge-diagrams2.xml Tue Sep 09 20:08:12 2014 +0200 +++ b/artifacts/doc/conf/generators/discharge-diagrams2.xml Wed Sep 10 10:02:46 2014 +0200 @@ -3,29 +3,45 @@ <output-generator names="historical_discharge_wq,historical_discharge_wq_chartinfo" class="org.dive4elements.river.exports.DischargeGenerator" - converter="org.dive4elements.river.exports.DiagramAttributes"> + converter="org.dive4elements.river.exports.DiagramAttributes" + injector="org.dive4elements.river.exports.injector.HistoricalDischargeInjector"> <title key="chart.historical.discharge.title" default="chart.historical.discharge.title"/> &discharge-defaults; </output-generator> <output-generator names="computed_discharge_curve_chartinfo,computed_discharge_curve" class="org.dive4elements.river.exports.DischargeGenerator" - converter="org.dive4elements.river.exports.DiagramAttributes"> + converter="org.dive4elements.river.exports.DiagramAttributes" + injector="org.dive4elements.river.exports.injector.ComputedDischargeInjector"> <title key="chart.computed.discharge.curve.title" default="chart.computed.discharge.curve.title"/> + <subtitle key="chart.computed.discharge.curve.subtitle" default="-"> + <arg expr="artifact.river"/> + <arg expr="artifact.ld_locations" type="double"/> + </subtitle> &discharge-defaults; </output-generator> <output-generator names="discharge_curve_chartinfo,discharge_curve" class="org.dive4elements.river.exports.DischargeGenerator" - converter="org.dive4elements.river.exports.DiagramAttributes"> + converter="org.dive4elements.river.exports.DiagramAttributes" + injector="org.dive4elements.river.exports.injector.DischargeInjector"> <title key="chart.discharge.curve.title" default="chart.discharge.curve.title"/> + <subtitle key="chart.computed.discharge.curve.subtitle" default="-"> + <arg expr="artifact.river"/> + <arg expr="artifact.ld_locations" type="double"/> + </subtitle> &discharge-defaults; </output-generator> <output-generator names="fix_wq_curve,fix_wq_curve_chartinfo" class="org.dive4elements.river.exports.DischargeGenerator" - converter="org.dive4elements.river.exports.DiagramAttributes"> - <title key="chart.fixings.discharge.curve.title" default="chart.fixings.discharge.curve.title"/> + converter="org.dive4elements.river.exports.DiagramAttributes" + injector="org.dive4elements.river.exports.injector.FixWQInjector"> + <title key="chart.fixings.discharge.curve.title" default="Fixierungsanalyse W/Q"/> + <subtitle key="chart.computed.discharge.curve.subtitle" default="-"> + <arg expr="artifact.river"/> + <arg expr="artifact.ld_locations" type="double"/> + </subtitle> &discharge-defaults; </output-generator>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/ComputedDischargeInjector.java Wed Sep 10 10:02:46 2014 +0200 @@ -0,0 +1,34 @@ +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; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.RangeAccess; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; + +public class ComputedDischargeInjector +implements ContextInjector +{ + + private static Logger log = Logger.getLogger(ComputedDischargeInjector.class); + + @Override + public void setup(Element cfg) { + } + + @Override + public void injectContext( + CallContext ctx, + Artifact artifact, + Document doc + ) { + RangeAccess access = new RangeAccess((D4EArtifact)artifact); + double km = access.getFrom(); + ctx.putContextValue(CURRENT_KM, km); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java Wed Sep 10 10:02:46 2014 +0200 @@ -0,0 +1,40 @@ +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; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.RangeAccess; +import org.dive4elements.river.model.Gauge; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; +import static org.dive4elements.river.exports.injector.InjectorConstants.GAUGE_EPSILON;; + + +public class DischargeInjector +implements ContextInjector +{ + + private static Logger log = Logger.getLogger(DischargeInjector.class); + + @Override + public void setup(Element cfg) { + } + + @Override + public void injectContext(CallContext ctx, Artifact artifact, Document doc) { + RangeAccess access = new RangeAccess((D4EArtifact)artifact); + 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 + "!"); + return; + } + ctx.putContextValue(CURRENT_KM, km); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/FixWQInjector.java Wed Sep 10 10:02:46 2014 +0200 @@ -0,0 +1,63 @@ +package org.dive4elements.river.exports.injector; + +import org.apache.log4j.Logger; +import org.dive4elements.artifacts.Artifact; +import org.dive4elements.artifacts.ArtifactNamespaceContext; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.artifacts.ContextInjector; +import org.dive4elements.artifacts.common.utils.XMLUtils; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.RangeAccess; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; + + +public class FixWQInjector +implements ContextInjector +{ + private static final Logger log = Logger.getLogger(FixWQInjector.class); + + public static final Double INVALID_KM = Double.valueOf(-1d); + public static final String XPATH_CHART_CURRENTKM = + "/art:action/art:attributes/art:currentKm/@art:km"; + @Override + public void setup(Element cfg) { + + } + + @Override + public void injectContext( + CallContext ctx, + Artifact artifact, + Document request) { + Double km = getCurrentKmFromRequest(request); + if (km == Double.NaN) { + RangeAccess access = new RangeAccess((D4EArtifact)artifact); + km = access.getFrom(); + log.debug("from access"); + } + log.debug("current km: " + km); + ctx.putContextValue(CURRENT_KM, km); + } + + private Double getCurrentKmFromRequest(Document request) { + + String km = XMLUtils.xpathString( + request, + XPATH_CHART_CURRENTKM, + ArtifactNamespaceContext.INSTANCE); + + if (km == null) { + return Double.NaN; + } + + try { + return Double.valueOf(km); + } + catch (NumberFormatException nfe) { + return Double.NaN; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/HistoricalDischargeInjector.java Wed Sep 10 10:02:46 2014 +0200 @@ -0,0 +1,47 @@ +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; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.HistoricalDischargeAccess; +import org.dive4elements.river.artifacts.access.RangeAccess; +import org.dive4elements.river.model.Gauge; +import org.dive4elements.river.model.River; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; + +public class HistoricalDischargeInjector +implements ContextInjector +{ + private static Logger log = + Logger.getLogger(HistoricalDischargeInjector.class); + + @Override + public void setup(Element cfg) { + + } + + @Override + public void injectContext( + CallContext ctx, + Artifact artifact, + Document request + ) { + HistoricalDischargeAccess access = + new HistoricalDischargeAccess((D4EArtifact)artifact); + Long gaugeNumber = access.getOfficialGaugeNumber(); + if (gaugeNumber == null) { + return; + } + Gauge gauge = Gauge.getGaugeByOfficialNumber(gaugeNumber); + if (gauge == null) { + return; + } + double km = gauge.getStation().doubleValue(); + ctx.putContextValue(CURRENT_KM, km); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/InjectorConstants.java Wed Sep 10 10:02:46 2014 +0200 @@ -0,0 +1,8 @@ +package org.dive4elements.river.exports.injector; + + +public interface InjectorConstants +{ + public static final String CURRENT_KM = "currentkm"; + public static final double GAUGE_EPSILON = 0.1; +}