view artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java @ 8098:09725b65955a

Add new and simplyfied SedimentLoadFacet The SedimentLoadFacet is intended to work with the Measurement stations. It uses the same mechanismn to access the Mesurement station values as the calculation does. SedimentLoadLS values need a different facet that will come soon.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 15 Aug 2014 18:27:19 +0200
parents 20a32dbdbb59
children 8578babdb2c8
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.artifacts.model;

import java.util.Arrays;
import java.util.Map;

import org.dive4elements.artifacts.Artifact;
import org.dive4elements.artifacts.CallContext;

import org.dive4elements.artifactdatabase.state.DefaultFacet;
import org.dive4elements.artifactdatabase.state.Facet;

import org.dive4elements.river.artifacts.D4EArtifact;

import org.dive4elements.river.model.Gauge;

import org.dive4elements.river.utils.RiverUtils;

import org.apache.log4j.Logger;

/**
 * A Facet that returns discharge curve data at a gauge
 *
 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
 */
public class GaugeDischargeCurveFacet
extends      DefaultFacet
implements FacetTypes
{
    private static final Logger log =
        Logger.getLogger(GaugeDischargeCurveFacet.class);

    public GaugeDischargeCurveFacet(String name, String description) {
        super(0, name, description);
    }

    @Override
    public Object getData(Artifact art, CallContext context) {
        return getWQKms(art, context);
    }

    protected WQKms getWQKms(Artifact art, CallContext context) {
        if (!(art instanceof D4EArtifact)) {
            log.warn("Invalid artifact type");
            return null;
        }

        D4EArtifact flys = (D4EArtifact)art;

        String river = flys.getDataAsString("river");

        Gauge gauge = RiverUtils.getReferenceGauge(flys);

        if (river == null || gauge == null) {
            log.warn("Unknown river or gauge");
            return null;
        }

        String name = gauge.getName();

        DischargeTables dt = new DischargeTables(river, name);

        Map<String, double [][]> map = dt.getValues();

        double [][] values = map.get(name);
        if (values == null) {
            return null;
        }
        double [] kms = new double[values[0].length];
        Arrays.fill(kms, gauge.getStation().doubleValue());
        return new WQKms(kms, values[0], values[1], name, WQKms.CENTIMETER_AT_GAUGE);
    }

    @Override
    public Facet deepCopy() {
        GaugeDischargeCurveFacet copy = new GaugeDischargeCurveFacet(
                this.name,
                this.description);
        copy.set(this);
        return copy;
    }
}

http://dive4elements.wald.intevation.org