teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5863: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5863: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.model.fixings; sascha@3203: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.CallContext; sascha@3074: teichmann@5831: import org.dive4elements.river.artifacts.FLYSArtifact; raimund@3035: teichmann@5831: import org.dive4elements.river.artifacts.access.FixAnalysisAccess; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.math.fitting.Function; teichmann@5831: import org.dive4elements.river.artifacts.math.fitting.FunctionFactory; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.model.CalculationResult; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.Parameters; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; raimund@3028: sascha@3074: import org.apache.log4j.Logger; raimund@3028: raimund@3028: /** raimund@3028: * Facet to show the W|Q values. raimund@3028: * raimund@3028: * @author Raimund Renkert raimund@3028: */ raimund@3028: public class FixWQCurveFacet bjoern@4442: extends FixingsFacet raimund@3028: implements FacetTypes { raimund@3028: raimund@3028: /** House logger. */ raimund@3028: private static Logger logger = Logger.getLogger(FixWQCurveFacet.class); raimund@3028: felix@4312: raimund@3028: /** Trivial Constructor. */ raimund@3028: public FixWQCurveFacet() { raimund@3028: } raimund@3028: raimund@3028: raimund@3028: /** felix@3269: * @param description Description of the facet. raimund@3028: */ raimund@3028: public FixWQCurveFacet(String description) { raimund@3028: super(0, FIX_WQ_CURVE, description, ComputeType.ADVANCE, null, null); raimund@3028: } raimund@3028: christian@3192: public FixWQCurveFacet(int index, String description) { christian@3192: super(index, FIX_WQ_CURVE, description, ComputeType.ADVANCE, null, null); christian@3192: } christian@3192: raimund@3028: raimund@3028: /** felix@4312: * Returns the data this facet provides at given km, a function. raimund@3028: * raimund@3028: * @param artifact the owner artifact. felix@4312: * @param context the CallContext. raimund@3028: * raimund@3028: * @return the data. raimund@3028: */ raimund@3028: @Override raimund@3028: public Object getData(Artifact artifact, CallContext context) { bjoern@4441: logger.debug("getData"); raimund@3035: if (artifact instanceof FLYSArtifact) { raimund@3035: FLYSArtifact flys = (FLYSArtifact)artifact; rrenkert@4866: FixAnalysisAccess access = new FixAnalysisAccess(flys, context); raimund@3035: raimund@3035: CalculationResult res = raimund@3035: (CalculationResult) flys.compute(context, raimund@3035: ComputeType.ADVANCE, raimund@3035: false); raimund@3035: ingo@3466: FixResult result = (FixResult) res.getData(); bjoern@4442: double currentKm = getCurrentKm(context); raimund@3035: christian@3081: logger.debug("getData: km = " + currentKm); raimund@3035: raimund@3035: String function = access.getFunction(); raimund@3035: Function ff = FunctionFactory.getInstance().getFunction(function); raimund@3035: sascha@3074: if (ff == null) { christian@3081: logger.warn("getData: ff == null"); sascha@3074: return null; sascha@3074: } sascha@3074: raimund@3035: Parameters params = result.getParameters(); sascha@3073: String[] paramNames = ff.getParameterNames(); sascha@3073: raimund@3080: double [] coeffs = params.interpolate("km", currentKm, paramNames); sascha@3073: sascha@3073: if (coeffs == null) { christian@3081: logger.warn("getData: coeffs == null"); sascha@3073: return null; christian@3056: } raimund@3035: teichmann@5831: org.dive4elements.river.artifacts.math.Function mf = raimund@3035: ff.instantiate(coeffs); raimund@3035: christian@3091: double maxQ = FixFacetUtils.getMaxQ(params, currentKm); christian@3056: logger.debug("getData: maxQ = " + maxQ); raimund@3035: raimund@3035: FixFunction fix = new FixFunction( raimund@3035: ff.getName(), raimund@3035: ff.getDescription(), raimund@3035: mf, raimund@3035: maxQ); raimund@3035: raimund@3035: return fix; raimund@3035: } raimund@3035: else { felix@4308: logger.debug("Not an instance of FLYSArtifact / FixationArtifact."); raimund@3035: return null; raimund@3035: } raimund@3028: } raimund@3028: raimund@3028: /** raimund@3028: * Create a deep copy of this Facet. raimund@3028: * @return a deep copy. raimund@3028: */ raimund@3028: @Override raimund@3028: public FixWQCurveFacet deepCopy() { raimund@3028: FixWQCurveFacet copy = new FixWQCurveFacet(); raimund@3028: copy.set(this); raimund@3028: return copy; raimund@3028: } raimund@3028: } raimund@3028: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :