view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java @ 1180:1aba1a75beb2

Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE. flys-artifacts/trunk@2770 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 16 Sep 2011 08:47:09 +0000
parents 2490d6ef394e
children 9c1cda9e2bc4
line wrap: on
line source
package de.intevation.flys.artifacts.states;

import java.util.List;

import org.apache.log4j.Logger;

import de.intevation.artifacts.CallContext;

import de.intevation.artifactdatabase.state.Facet;

import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.WINFOArtifact;

import de.intevation.flys.artifacts.math.WKmsOperation;

import de.intevation.flys.artifacts.model.FacetTypes;
import de.intevation.flys.artifacts.model.WKms;
import de.intevation.flys.artifacts.model.WQKms;

import de.intevation.flys.artifacts.model.DataFacet;
import de.intevation.flys.artifacts.model.WaterlevelFacet;

import de.intevation.flys.utils.FLYSUtils;

//import net.sf.json.JSONObject;

public class WDifferencesState
extends      DefaultState
implements   FacetTypes
{
    /** The logger that is used in this state. */
    private static Logger logger = Logger.getLogger(WDifferencesState.class);


    public WDifferencesState() {
    }


    /** Specify to display nothing (this is kind of a "final" state). */
    @Override
    protected String getUIProvider() {
        return "noinput";
    }


    @Override
    public Object computeAdvance(
        FLYSArtifact artifact,
        String       hash,
        CallContext  context,
        List<Facet>  facets,
        Object       old
    ) {
        WINFOArtifact winfo = (WINFOArtifact)artifact;
        String id = getID();

        // Get a data item (uuids) or parameterization of the respective
        // artifacts.
        // TODO Fix, choose artifacts/parameterization dynamically.
        WINFOArtifact flys1 = (WINFOArtifact) FLYSUtils.getArtifact(
            //"a110a16d-d155-4115-ab0d-c4c61101c9cb", //Collection
            "a0ec533f-b05b-4dcd-9db3-7850686f90a2",
            context);
        WINFOArtifact flys2 = (WINFOArtifact) FLYSUtils.getArtifact(
            //"8ebb696d-771a-4540-bd18-15e19744a6e2", //Collection
            "ce5a2c4e-3f9c-4c4d-a35c-109dd8670992",
            context);

        if (flys1 == null) {
            logger.warn("One of the artifacts (1) for diff calculation could not be loaded");
        }
        if (flys2 == null) {
            logger.warn("One of the artifacts (2) for diff calculation could not be loaded");
        }
        WKms wkms = null;
        String facetName = "diff ()";

        if (flys1 != null && flys2 != null) {
            // TODO also check size.
            // TODO also need index of wqkms.
            WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData().getData();
            WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData().getData();
            wkms = WKmsOperation.SUBTRACTION.operate(minuend[0], subtrahend[0]);
            facetName = "W ("+minuend[0].getName() + ") - W (" + subtrahend[0].getName()+")";
            logger.warn("Did a WKMSSubtraction");
            // Add these datasets also as facets.
            // TODO Store parameterization.
            // Therefore need: getKmRange, getQs, getRiver, eventually getWs
            Facet minuendAbsFacet = new WaterlevelFacet(0, LONGITUDINAL_W,
                "Minuend: W (_todo_)", ComputeType.ADVANCE, id, hash);
            Facet subtrahendAbsFacet = new WaterlevelFacet(1, LONGITUDINAL_W,
                "Subtrahend: W (_todo_)", ComputeType.ADVANCE, id, hash);
            //JSONObject jsonObject = new JSONObject().accumulate("string", 2.0f);
            //facets.add(minuendAbsFacet);
            //facets.add(subtrahendAbsFacet);
        }

        if (facets != null) {
            // TODO: pass computetype and state id.
            //, ComputeType.ADVANCE, getID(), hash));
            facets.add(new DataFacet(W_DIFFERENCES, facetName));
            facets.add(new DataFacet(CSV, "CSV data"));
        }
        else {
            logger.debug("Not adding facets in WDifferencesState.");
        }

        return wkms;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org