teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * 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@5867: import org.dive4elements.river.artifacts.D4EArtifact; 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) { sascha@3074: teichmann@6868: logger.debug("getData"); teichmann@6868: if (!(artifact instanceof D4EArtifact)) { teichmann@5867: logger.debug("Not an instance of D4EArtifact / FixationArtifact."); raimund@3035: return null; raimund@3035: } teichmann@6868: teichmann@6868: D4EArtifact flys = (D4EArtifact)artifact; teichmann@6868: FixAnalysisAccess access = new FixAnalysisAccess(flys); teichmann@6868: teichmann@6868: CalculationResult res = teichmann@6868: (CalculationResult) flys.compute(context, teichmann@6868: ComputeType.ADVANCE, teichmann@6868: false); teichmann@6868: teichmann@6868: FixResult result = (FixResult) res.getData(); teichmann@6868: double currentKm = getCurrentKm(context); teichmann@6868: teichmann@6868: logger.debug("getData: km = " + currentKm); teichmann@6868: teichmann@6868: String function = access.getFunction(); teichmann@6868: Function ff = FunctionFactory.getInstance().getFunction(function); teichmann@6868: teichmann@6868: if (ff == null) { teichmann@6868: logger.warn("getData: ff == null"); teichmann@6868: return null; teichmann@6868: } teichmann@6868: teichmann@6868: Parameters params = result.getParameters(); teichmann@6868: String[] paramNames = ff.getParameterNames(); teichmann@6868: teichmann@6868: double [] coeffs = params.interpolate("km", currentKm, paramNames); teichmann@6868: teichmann@6868: if (coeffs == null) { teichmann@6868: logger.warn("getData: coeffs == null"); teichmann@6868: return null; teichmann@6868: } teichmann@6868: teichmann@6868: org.dive4elements.river.artifacts.math.Function mf = teichmann@6868: ff.instantiate(coeffs); teichmann@6868: teichmann@6868: double maxQ = FixFacetUtils.getMaxQ(params, currentKm); teichmann@6868: logger.debug("getData: maxQ = " + maxQ); teichmann@6868: teichmann@6868: FixFunction fix = new FixFunction( teichmann@6868: ff.getName(), teichmann@6868: ff.getDescription(), teichmann@6868: mf, teichmann@6868: maxQ); teichmann@6868: teichmann@6868: return fix; 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 :