Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadLSGenerator.java @ 5866:9a6741ccf6d4
FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 28 Apr 2013 15:14:30 +0200 |
parents | f2e46a668fe6 |
children | 59ff03ff48f1 |
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.minfo; import java.util.Arrays; import org.apache.log4j.Logger; import org.jfree.data.xy.XYSeries; import org.w3c.dom.Document; import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifactdatabase.state.Facet; import org.dive4elements.river.artifacts.FLYSArtifact; import org.dive4elements.river.artifacts.access.RangeAccess; import org.dive4elements.river.artifacts.access.SedimentLoadAccess; import org.dive4elements.river.artifacts.model.FacetTypes; import org.dive4elements.river.artifacts.model.FlowVelocityData; import org.dive4elements.river.artifacts.model.WKms; import org.dive4elements.river.artifacts.model.minfo.BedDiffEpochResult; import org.dive4elements.river.artifacts.model.minfo.BedDiffYearResult; import org.dive4elements.river.exports.StyledSeriesBuilder; import org.dive4elements.river.exports.XYChartGenerator; import org.dive4elements.river.jfree.Bounds; import org.dive4elements.river.jfree.DoubleBounds; import org.dive4elements.river.jfree.RiverAnnotation; import org.dive4elements.river.jfree.StyledXYSeries; import org.dive4elements.river.utils.DataUtil; public class SedimentLoadLSGenerator extends XYChartGenerator implements FacetTypes { public enum YAXIS { L(0), D(1), DW(2), V(3); protected int idx; private YAXIS(int c) { idx = c; } } /** The logger that is used in this generator. */ private static Logger logger = Logger.getLogger(SedimentLoadLSGenerator.class); public static final String I18N_CHART_TITLE = "chart.sedimentload.ls.title"; public static final String I18N_XAXIS_LABEL = "chart.sedimentload.ls.xaxis.label"; public static final String I18N_YAXIS_LABEL_1 = "chart.sedimentload.ls.yaxis.label.tpera"; public static final String I18N_YAXIS_LABEL_2 = "chart.sedimentload.ls.yaxis.label.m3pera"; public static final String I18N_YAXIS_D_LABEL = "chart.beddifference.yaxis.label.diff"; public static final String I18N_YAXIS_V_LABEL = "chart.flow_velocity.section.yaxis.label"; public final static String I18N_WDIFF_YAXIS_LABEL = "chart.w_differences.yaxis.label"; public final static String I18N_WDIFF_YAXIS_LABEL_DEFAULT = "m"; public static final String I18N_CHART_TITLE_DEFAULT = "Sedimentfracht"; public static final String I18N_XAXIS_LABEL_DEFAULT = "Fluss-Km"; public static final String I18N_YAXIS_LABEL_DEFAULT_1 = "[t/a]"; public static final String I18N_YAXIS_LABEL_DEFAULT_2 = "[m\u00b3/a]"; public static final String I18N_YAXIS_D_LABEL_DEFAULT = "delta S [m]"; public static final String I18N_YAXIS_V_LABEL_DEFAULT = "Geschwindigkeit v [m/s]"; private FLYSArtifact artifact; @Override protected YAxisWalker getYAxisWalker() { return new YAxisWalker() { @Override public int length() { return YAXIS.values().length; } @Override public String getId(int idx) { YAXIS[] yaxes = YAXIS.values(); return yaxes[idx].toString(); } }; } @Override public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) { String name = bundle.getFacetName(); logger.debug("doOut: " + name); if (name == null) { logger.error("No facet name for doOut(). No output generated!"); return; } Facet facet = bundle.getFacet(); artifact = (FLYSArtifact)bundle.getArtifact(); if (facet == null) { return; } if (getXBounds(0) != null && getDomainAxisRange() != null) { logger.debug(Arrays.toString(getDomainAxisRangeFromRequest())); Bounds bounds = calculateZoom(getXBounds(0), getDomainAxisRange()); context.putContextValue("startkm", bounds.getLower()); context.putContextValue("endkm", bounds.getUpper()); } else if (getXBounds(0) != null && getDomainAxisRange() == null) { context.putContextValue("startkm", getXBounds(0).getLower()); context.putContextValue("endkm", getXBounds(0).getUpper()); } else if (getXBounds(0) == null && getDomainAxisRange() == null) { FLYSArtifact artifact = (FLYSArtifact)bundle.getArtifact(); RangeAccess access = new RangeAccess(artifact, context); context.putContextValue("startkm", access.getFrom()); context.putContextValue("endkm", access.getTo()); } else if (getXBounds(0) == null && getDomainAxisRange() != null){ FLYSArtifact artifact = (FLYSArtifact)bundle.getArtifact(); RangeAccess access = new RangeAccess(artifact, context); Bounds b = new DoubleBounds(access.getFrom(), access.getTo()); Bounds bounds = calculateZoom(b, getDomainAxisRange()); context.putContextValue("startkm", bounds.getLower()); context.putContextValue("endkm", bounds.getUpper()); } if (FacetTypes.IS.SEDIMENT_LOAD(SEDIMENT_LOAD_COARSE)) { doSedimentLoadOut( (double[][]) bundle.getData(context), bundle, attr, visible); } else if (name.equals(FLOW_VELOCITY_TOTALCHANNEL)) { doFlowVelocityTotalOut( (FlowVelocityData) bundle.getData(context), bundle, attr, visible); } else if (name.equals(FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) { doFlowVelocityTotalOut( (FlowVelocityData) bundle.getData(context), bundle, attr, visible); } else if (name.equals(FLOW_VELOCITY_MAINCHANNEL)) { doFlowVelocityMainOut( (FlowVelocityData) bundle.getData(context), bundle, attr, visible); } else if (name.equals(FLOW_VELOCITY_MAINCHANNEL_FILTERED)) { doFlowVelocityMainOut( (FlowVelocityData) bundle.getData(context), bundle, attr, visible); } else if (name.equals(BED_DIFFERENCE_YEAR)) { doBedDifferenceYearOut( (BedDiffYearResult) bundle.getData(context), bundle, attr, visible); } else if (name.equals(BED_DIFFERENCE_YEAR_FILTERED)) { doBedDifferenceYearOut( (BedDiffYearResult) bundle.getData(context), bundle, attr, visible); } else if (name.equals(BED_DIFFERENCE_EPOCH)) { doBedDifferenceEpochOut( (BedDiffEpochResult) bundle.getData(context), bundle, attr, visible); } else if (name.equals(W_DIFFERENCES)) { doWDifferencesOut( (WKms) bundle.getData(context), bundle, attr, visible); } else if (name.equals(LONGITUDINAL_ANNOTATION)) { doAnnotations( (RiverAnnotation) bundle.getData(context), bundle, attr, visible); } else if (FacetTypes.IS.MANUALPOINTS(name)) { doPoints( bundle.getData(context), bundle, attr, visible, YAXIS.L.idx); } } @Override protected String getDefaultChartTitle() { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); } @Override protected String getDefaultXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } @Override protected String getDefaultYAxisLabel(int pos) { String label = "default"; if (pos == YAXIS.L.idx) { SedimentLoadAccess access = new SedimentLoadAccess(artifact, context); if (access.getUnit().equals("m3_per_a")) { label = msg(I18N_YAXIS_LABEL_2, I18N_YAXIS_LABEL_DEFAULT_2); } else { label = msg(I18N_YAXIS_LABEL_1, I18N_YAXIS_LABEL_DEFAULT_1); } } else if (pos == YAXIS.V.idx) { label = msg(I18N_YAXIS_V_LABEL, I18N_YAXIS_V_LABEL_DEFAULT); } else if (pos == YAXIS.D.idx) { label = msg(I18N_YAXIS_D_LABEL, I18N_YAXIS_D_LABEL_DEFAULT); } else if (pos == YAXIS.DW.idx) { label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT); } return label; } protected void doSedimentLoadOut(double[][] data, ArtifactAndFacet aandf, Document theme, boolean visible) { // Allow for gaps (NaNs). XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), false, theme); StyledSeriesBuilder.addPoints(series, data, false); addAxisSeries(series, YAXIS.L.idx, visible); } protected void doFlowVelocityMainOut( FlowVelocityData data, ArtifactAndFacet aandf, Document theme, boolean visible ) { XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); StyledSeriesBuilder.addPoints(series, data.getMainChannelPoints(), true); addAxisSeries(series, YAXIS.V.idx, visible); } protected void doFlowVelocityTotalOut( FlowVelocityData data, ArtifactAndFacet aandf, Document theme, boolean visible ) { if (data == null) { logger.warn("No data to add to FlowVelocity chart."); return; } XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); StyledSeriesBuilder.addPoints(series, data.getTotalChannelPoints(), true); addAxisSeries(series, YAXIS.V.idx, visible); } protected void doBedDifferenceYearOut( BedDiffYearResult data, ArtifactAndFacet aandf, Document theme, boolean visible ) { XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); StyledSeriesBuilder.addPoints(series, data.getDifferencesData(), true); addAxisSeries(series, YAXIS.D.idx, visible); } protected void doBedDifferenceEpochOut( BedDiffEpochResult data, ArtifactAndFacet aandf, Document theme, boolean visible ) { XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); StyledSeriesBuilder.addPoints(series, data.getDifferencesData(), true); addAxisSeries(series, YAXIS.D.idx, visible); } protected void doWDifferencesOut( WKms wkms, ArtifactAndFacet aandf, Document theme, boolean visible ) { if (wkms == null) { logger.warn("No data to add to WDifferencesChart."); return; } XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); StyledSeriesBuilder.addPoints(series, wkms); addAxisSeries(series, YAXIS.D.idx, visible); if (DataUtil.guessWaterIncreasing(wkms.allWs())) { setInverted(true); } } }