Mercurial > dive4elements > river
changeset 6533:30c6da3bfc86
In analogy to w values allow q values to be calculated at the
correct km in fix settings (bug spotted while working on issue1370).
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 03 Jul 2013 09:34:02 +0200 |
parents | cf3065a17057 |
children | 480fb71ab73f |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesQFacet.java |
diffstat | 2 files changed, 48 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java Tue Jul 02 15:43:11 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java Wed Jul 03 09:34:02 2013 +0200 @@ -373,6 +373,41 @@ * Get a list of "Q" main values. * @return list of Q main values. */ + public List<NamedDouble> getMainValuesQ(double[] kms) { + List<NamedDouble> filteredList = new ArrayList<NamedDouble>(); + boolean atGauge = false; + Gauge gauge = getGauge(kms[0]); + WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this)); + Calculation c = new Calculation(); + double w_out[] = {0.0f}; + double q_out[] = {0.0f}; + if (gauge != null) { + double gaugeStation = gauge.getStation().doubleValue(); + atGauge = Math.abs(kms[0] - gaugeStation) < 1e-4; + List<MainValue> orig = gauge.getMainValues(); + for (MainValue mv : orig) { + if (mv.getMainValue().getType().getName().equals("Q")) { + if (atGauge) { + q_out[0] = mv.getValue().doubleValue(); + } + else { + interpolator.interpolate(mv.getValue().doubleValue(), + gaugeStation, kms, w_out, q_out, c); + } + filteredList.add(new NamedDouble( + mv.getMainValue().getName(), + q_out[0] + )); + } + } + } + return filteredList; + } + + /** + * Get a list of "Q" main values. + * @return list of Q main values. + */ public List<NamedDouble> getMainValuesQ(boolean atGauge) { List<NamedDouble> filteredList = new ArrayList<NamedDouble>(); Gauge gauge = getGauge(); @@ -381,8 +416,8 @@ double w_out[] = {0.0f}; double q_out[] = {0.0f}; double kms[] = {getLocation()}; - double gaugeStation = gauge.getStation().doubleValue(); if (gauge != null) { + double gaugeStation = gauge.getStation().doubleValue(); List<MainValue> orig = gauge.getMainValues(); for (MainValue mv : orig) { if (mv.getMainValue().getType().getName().equals("Q")) {
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesQFacet.java Tue Jul 02 15:43:11 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesQFacet.java Wed Jul 03 09:34:02 2013 +0200 @@ -25,6 +25,7 @@ import org.dive4elements.river.jfree.StickyAxisAnnotation; import org.dive4elements.river.exports.DurationCurveGenerator; +import org.dive4elements.river.exports.fixings.FixChartGenerator; /** @@ -89,7 +90,8 @@ * Returns the data this facet requires. * * @param artifact the owner artifact. - * @param context the CallContext (ignored). + * @param context the CallContext (can be used to find out if in + * navigable fixation-setting, or durationcurve). * * @return the data. */ @@ -105,6 +107,15 @@ getDataProvider(DurationCurveFacet.BB_DURATIONCURVE); if (providers.size() < 1) { logger.warn("Could not find durationcurve data provider."); + // Do we have a current km in context? + // If so, we are likely fetching data for a navigable + // diagram (i.e. in fixation branch). + if (context.getContextValue(FixChartGenerator.CURRENT_KM) != null) { + Double ckm = (Double) context.getContextValue(FixChartGenerator.CURRENT_KM); + // Return linearly interpolated values, in m if not at gauge, + // in cm if at gauge. + qs = mvArtifact.getMainValuesQ(new double[] {ckm}); + } } else { wqdays = (WQDay) providers.get(0).provideData(