# HG changeset patch # User Felix Wolfsteller # Date 1372836842 -7200 # Node ID 30c6da3bfc86b6321e8a928748fffc6a3f2d73b7 # Parent cf3065a17057a3bc33a8ebdaa592fcf585bd4be2 In analogy to w values allow q values to be calculated at the correct km in fix settings (bug spotted while working on issue1370). diff -r cf3065a17057 -r 30c6da3bfc86 artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java --- 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 getMainValuesQ(double[] kms) { + List filteredList = new ArrayList(); + 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 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 getMainValuesQ(boolean atGauge) { List filteredList = new ArrayList(); 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 orig = gauge.getMainValues(); for (MainValue mv : orig) { if (mv.getMainValue().getType().getName().equals("Q")) { diff -r cf3065a17057 -r 30c6da3bfc86 artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesQFacet.java --- 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(