mschaefer@9269: /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde mschaefer@9269: * Software engineering by mschaefer@9269: * Björnsen Beratende Ingenieure GmbH mschaefer@9269: * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt mschaefer@9257: * mschaefer@9257: * This file is Free Software under the GNU AGPL (>=v3) mschaefer@9257: * and comes with ABSOLUTELY NO WARRANTY! Check out the mschaefer@9257: * documentation coming with Dive4Elements River for details. mschaefer@9257: */ mschaefer@9257: mschaefer@9257: package org.dive4elements.river.artifacts.sinfo.flood_duration; mschaefer@9257: mschaefer@9269: import java.util.List; mschaefer@9269: mschaefer@9257: import org.apache.log4j.Logger; mschaefer@9257: import org.dive4elements.artifactdatabase.state.DefaultFacet; mschaefer@9257: import org.dive4elements.artifacts.Artifact; mschaefer@9257: import org.dive4elements.artifacts.CallContext; mschaefer@9257: import org.dive4elements.river.artifacts.D4EArtifact; d@9612: import org.dive4elements.river.artifacts.model.Calculation; mschaefer@9257: import org.dive4elements.river.artifacts.model.CalculationResult; mschaefer@9257: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; mschaefer@9269: import org.dive4elements.river.exports.fixings.FixChartGenerator; mschaefer@9259: import org.dive4elements.river.jfree.RiverAnnotation; mschaefer@9257: import org.dive4elements.river.jfree.StickyAxisAnnotation; mschaefer@9257: mschaefer@9257: /** mschaefer@9257: * Facet to show Main Q Values. mschaefer@9257: */ mschaefer@9257: public class FloodDurationMainValuesQFacet extends DefaultFacet { mschaefer@9257: d@9612: private static final long serialVersionUID = 1L; d@9612: mschaefer@9257: /** Own log. */ mschaefer@9257: private static Logger log = Logger.getLogger(FloodDurationMainValuesQFacet.class); mschaefer@9257: mschaefer@9620: private final FloodDurationInfrastructureChoice m_infrastructure; d@9612: mschaefer@9257: /** Trivial Constructor. */ mschaefer@9620: public FloodDurationMainValuesQFacet(final String name, final String description, final int facetIndex, mschaefer@9620: final FloodDurationInfrastructureChoice infrastructure) { mschaefer@9257: this.description = description; mschaefer@9259: this.name = name; d@9612: this.index = facetIndex; d@9612: this.m_infrastructure = infrastructure; mschaefer@9257: } mschaefer@9257: mschaefer@9257: /** mschaefer@9257: * Returns the data this facet requires. mschaefer@9257: */ mschaefer@9257: @Override mschaefer@9257: public Object getData(final Artifact artifact, final CallContext context) { mschaefer@9257: mschaefer@9257: log.debug("Get data for flood duration main value Q data"); mschaefer@9257: mschaefer@9257: final D4EArtifact flys = (D4EArtifact) artifact; mschaefer@9257: mschaefer@9257: final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); mschaefer@9257: mschaefer@9257: final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData(); mschaefer@9257: mschaefer@9269: final double currentKm = FixChartGenerator.getCurrentKm(context); mschaefer@9269: d@9612: final FloodDurationCalculationResult result = data.getResults().get(0); d@9612: d@9612: final Calculation problems = new Calculation(); d@9612: d@9612: final FacetCalculator calculator = new FacetCalculator(context); d@9612: final List annotations = calculator.calcMainValueQAnnotations(problems, currentKm, result); mschaefer@9269: mschaefer@9269: return new RiverAnnotation(this.description, annotations); mschaefer@9257: } mschaefer@9257: mschaefer@9257: /** mschaefer@9257: * Create a deep copy of this Facet. d@9612: * mschaefer@9257: * @return a deep copy. mschaefer@9257: */ mschaefer@9257: @Override mschaefer@9257: public FloodDurationMainValuesQFacet deepCopy() { d@9612: final FloodDurationMainValuesQFacet copy = new FloodDurationMainValuesQFacet(this.name, this.description, this.index, this.m_infrastructure); mschaefer@9257: copy.set(this); mschaefer@9257: return copy; mschaefer@9257: } d@9612: }