view artifacts/src/main/java/org/dive4elements/river/exports/process/KMIndexProcessor.java @ 7691:fa4fbd66e752

(issue1579) Fix axes syncronisation at Gauges The SyncNumberAxis was completely broken. It only synced in one direction and even that did not work correctly when data was added to the axis (and the syncAxis rescaled but forgot the old axis) then there were lots of ways to bypass that scaling. And i also think the trans calculation was wrong. It has been replaced by a "mostly" simple method to just keep the W in M and W in CM+Datum axes in sync. I say "Mostly" because it had to deal with the Bounds interface.
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 13 Dec 2013 19:03:00 +0100
parents 253d80af5b7f
children
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.exports.process;

import org.apache.log4j.Logger;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.model.FacetTypes;
import org.dive4elements.river.artifacts.model.fixings.AnalysisPeriod;
import org.dive4elements.river.artifacts.model.fixings.QWD;
import org.dive4elements.river.exports.XYChartGenerator;
import org.dive4elements.river.jfree.StyledXYSeries;
import org.dive4elements.river.themes.ThemeDocument;
import org.dive4elements.river.utils.KMIndex;

public class KMIndexProcessor extends DefaultProcessor {

    private static final Logger logger = Logger.getLogger(KMIndexProcessor.class);

    @Override
    public void doOut(XYChartGenerator generator, ArtifactAndFacet bundle,
            ThemeDocument theme, boolean visible, int index) {
        String facettype = bundle.getFacetName();
        if (facettype.contains(FacetTypes.FIX_SECTOR_AVERAGE_LS)) {
            doSectorAverageOut(generator, bundle, theme, visible, index);
        }
        else if (facettype.equals(FacetTypes.FIX_REFERENCE_EVENTS_LS)) {
            doReferenceEventsOut(generator, bundle, theme, visible, index);
        }
        else if (facettype.equals(FacetTypes.FIX_ANALYSIS_EVENTS_LS)) {
            doAnalysisEventsOut(generator, bundle, theme, visible, index);
        }

    }

    @Override
    public boolean canHandle(String facettype) {
        if (facettype == null) {
            return false;
        }

        if (facettype.contains(FacetTypes.FIX_SECTOR_AVERAGE_LS)
                || facettype.equals(FacetTypes.FIX_REFERENCE_EVENTS_LS)
                || facettype.equals(FacetTypes.FIX_ANALYSIS_EVENTS_LS))
        {
            return true;
        }
        return false;
    }

    private void doSectorAverageOut(XYChartGenerator generator, ArtifactAndFacet bundle,
            ThemeDocument doc, boolean visible, int idx) {
        logger.debug("doSectorAverageOut" + bundle.getFacet().getIndex());

        CallContext context = generator.getCallContext();
        int index = bundle.getFacet().getIndex();
        int sectorNdx = index & 3;

        @SuppressWarnings("unchecked")
        KMIndex<AnalysisPeriod> kms =
                (KMIndex<AnalysisPeriod>)bundle.getData(context);

        if(kms == null) {
            return;
        }

        XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), doc);

        for (KMIndex.Entry<AnalysisPeriod> entry: kms) {
            double km = entry.getKm();
            AnalysisPeriod ap = entry.getValue();
            QWD qwd = ap.getQSectorAverages()[sectorNdx];
            if (qwd == null) {
                continue;
            }
            double deltaW = qwd.getDeltaW();
            series.add(km, deltaW);
        }

        generator.addAxisSeries(series, idx, visible);
    }

    private void doReferenceEventsOut(XYChartGenerator generator,
            ArtifactAndFacet bundle, ThemeDocument doc, boolean visible, int idx) {
        logger.debug("doReferenceEventOut");

        CallContext context = generator.getCallContext();

        @SuppressWarnings("unchecked")
        KMIndex<QWD> kms =
                (KMIndex<QWD>)bundle.getData(context);

        if(kms == null) {
            return;
        }

        XYSeriesCollection col = new XYSeriesCollection();

        StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), false,
                doc);

        for (KMIndex.Entry<QWD> entry: kms) {
            double km = entry.getKm();
            QWD qwd = entry.getValue();

            series.add(km, qwd.getDeltaW());
        }
        col.addSeries(series);

        generator.addAxisDataset(col, idx, visible);
    }

    private void doAnalysisEventsOut(XYChartGenerator generator,
            ArtifactAndFacet bundle, ThemeDocument doc, boolean visible, int idx) {
        logger.debug("doAnalysisEventsOut");

        CallContext context = generator.getCallContext();

        @SuppressWarnings("unchecked")
        KMIndex<QWD> kms =
                (KMIndex<QWD>)bundle.getData(context);

        if(kms == null) {
            return;
        }

        XYSeriesCollection col = new XYSeriesCollection();

        StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), false, doc);

        for (KMIndex.Entry<QWD> entry: kms) {
            double km = entry.getKm();
            QWD qwd = entry.getValue();

            series.add(km, qwd.getDeltaW());
        }
        col.addSeries(series);

        generator.addAxisDataset(col, idx, visible);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org