bjoern@3936: package de.intevation.flys.artifacts.model;
bjoern@3936:
bjoern@3936: import java.util.Arrays;
bjoern@3936: import java.util.Map;
bjoern@3936:
bjoern@3936: import de.intevation.artifacts.Artifact;
bjoern@3936: import de.intevation.artifacts.CallContext;
bjoern@3936:
bjoern@3936: import de.intevation.artifactdatabase.state.DefaultFacet;
bjoern@3936: import de.intevation.artifactdatabase.state.Facet;
bjoern@3936:
teichmann@3986: import de.intevation.flys.artifacts.FLYSArtifact;
teichmann@3986:
bjoern@3936: import de.intevation.flys.model.Gauge;
bjoern@3936:
teichmann@3986: import de.intevation.flys.utils.FLYSUtils;
teichmann@3986:
teichmann@3986: import org.apache.log4j.Logger;
teichmann@3986:
bjoern@3936: /**
bjoern@3936: * A Facet that returns discharge curve data at a gauge
bjoern@3936: *
bjoern@3936: * @author Björn Ricks
bjoern@3936: */
bjoern@3936: public class GaugeDischargeCurveFacet
bjoern@3936: extends DefaultFacet
bjoern@4032: implements FacetTypes
bjoern@3936: {
teichmann@3986: private static final Logger log =
teichmann@3986: Logger.getLogger(GaugeDischargeCurveFacet.class);
bjoern@3936:
bjoern@4032: public GaugeDischargeCurveFacet(String description) {
bjoern@4032: super(0, GAUGE_DISCHARGE_CURVE, description);
bjoern@3936: }
bjoern@3936:
bjoern@3936: @Override
bjoern@3936: public Object getData(Artifact art, CallContext context) {
bjoern@3936:
teichmann@3986: if (!(art instanceof FLYSArtifact)) {
teichmann@3986: log.warn("Invalid artifact type");
teichmann@3986: return null;
teichmann@3986: }
teichmann@3986:
teichmann@3986: FLYSArtifact flys = (FLYSArtifact)art;
teichmann@3986:
teichmann@3986: String river = flys.getDataAsString("river");
teichmann@3986:
teichmann@3986: Gauge gauge = FLYSUtils.getReferenceGauge(flys);
teichmann@3986:
teichmann@3986: if (river == null || gauge == null) {
teichmann@3986: log.warn("Unknown river or gauge");
teichmann@3986: return null;
teichmann@3986: }
teichmann@3986:
teichmann@3986: String name = gauge.getName();
teichmann@3986:
teichmann@3986: DischargeTables dt = new DischargeTables(river, name);
bjoern@3936:
bjoern@3936: Map map = dt.getValues(100d);
bjoern@3936:
bjoern@3936: double [][] values = map.get(name);
bjoern@3936: if (values == null) {
bjoern@3936: return null;
bjoern@3936: }
bjoern@3936: double [] kms = new double[values[0].length];
bjoern@3936: Arrays.fill(kms, gauge.getStation().doubleValue());
teichmann@3986: return new WQKms(kms, values[0], values[1], name);
bjoern@3936: }
bjoern@3936:
bjoern@3936: @Override
bjoern@3936: public Facet deepCopy() {
bjoern@4032: GaugeDischargeCurveFacet copy = new GaugeDischargeCurveFacet(
bjoern@4032: this.description);
bjoern@3936: copy.set(this);
bjoern@3936: return copy;
bjoern@3936: }
bjoern@3936: }