Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationProcessor.java @ 9573:b9c87bbff6a4
mean bed height -> mean bed LEVEL
author | gernotbelger |
---|---|
date | Tue, 06 Nov 2018 10:56:22 +0100 |
parents | 08f46ccd37ba |
children | f8308db94634 |
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * 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.sinfo.flood_duration; import java.util.HashSet; import java.util.Set; import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifactdatabase.state.Facet; import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.common.AbstractCalculationResult; import org.dive4elements.river.artifacts.common.AbstractProcessor; import org.dive4elements.river.artifacts.common.ResultFacet; import org.dive4elements.river.artifacts.resources.Resources; import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; import org.dive4elements.river.artifacts.sinfo.flood_duration.FloodDurationCalculationResult.ValueGetter; import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; import org.dive4elements.river.exports.DiagramGenerator; import org.dive4elements.river.model.Attribute.AttributeKey; import org.dive4elements.river.themes.ThemeDocument; /** * Processor to generate the facet and data series of infrastructure flood durations * * @author Matthias Schäfer * */ public final class FloodDurationProcessor extends AbstractProcessor { private static final String FACET_FLOOD_DURATION_LEFT = "sinfo_facet_flood_duration.left"; private static final String FACET_FLOOD_DURATION_RIGHT = "sinfo_facet_flood_duration.right"; private static final String FACET_FLOOD_DURATION_DESCRIPTION = "sinfo_facet_flood_duration.description"; private static final String FACET_MAIN_VALUE_DURATION = "mainvalue.duration"; private static final String FACET_MAIN_VALUE_DURATION_DESCRIPTION = "mainvalue.duration.description"; private static final String I18N_AXIS_LABEL = "sinfo.chart.flood_duration.section.yaxis.label"; private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); static { HANDLED_FACET_TYPES.add(FACET_FLOOD_DURATION_LEFT); HANDLED_FACET_TYPES.add(FACET_FLOOD_DURATION_RIGHT); HANDLED_FACET_TYPES.add(FACET_MAIN_VALUE_DURATION); } public FloodDurationProcessor() { super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES); } public static Facet createFloodDurationFacet(final CallContext context, final String hash, final String id, final AbstractCalculationResult result, final int facetIndex, final int resultIndex) { if (facetIndex == 0) { final String description = Resources.getMsg(context.getMeta(), FACET_FLOOD_DURATION_DESCRIPTION, FACET_FLOOD_DURATION_DESCRIPTION, SInfoResultType.localizeRiverside(context, AttributeKey.LEFT)); return new ResultFacet(facetIndex, resultIndex, FACET_FLOOD_DURATION_LEFT, description, I18N_AXIS_LABEL, ComputeType.ADVANCE, id, hash); } else { final String description = Resources.getMsg(context.getMeta(), FACET_FLOOD_DURATION_DESCRIPTION, FACET_FLOOD_DURATION_DESCRIPTION, SInfoResultType.localizeRiverside(context, AttributeKey.RIGHT)); return new ResultFacet(facetIndex, resultIndex, FACET_FLOOD_DURATION_RIGHT, description, I18N_AXIS_LABEL, ComputeType.ADVANCE, id, hash); } } public static Facet createMainValueDurationFacet(final CallContext context, final String hash, final String id, final FloodDurationCalculationResult result, final int facetIndex, final int resultIndex, final int dataIndex) { final String description = Resources.getMsg(context.getMeta(), FACET_MAIN_VALUE_DURATION_DESCRIPTION, FACET_MAIN_VALUE_DURATION_DESCRIPTION, result.getWaterlevelLabel(dataIndex)); return new FloodDurationFacet(facetIndex, resultIndex, dataIndex, FACET_MAIN_VALUE_DURATION, description, ComputeType.ADVANCE, I18N_AXIS_LABEL, hash, id); } @Override protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { final String facetName = bundle.getFacetName(); if (FACET_FLOOD_DURATION_LEFT.contentEquals(facetName)) { return buildInfrastructureSeries(generator, bundle, theme, visible, AttributeKey.LEFT); } if (FACET_FLOOD_DURATION_RIGHT.contentEquals(facetName)) return buildInfrastructureSeries(generator, bundle, theme, visible, AttributeKey.RIGHT); if (FACET_MAIN_VALUE_DURATION.contentEquals(facetName)) { final AbstractCalculationResult data = getResult(generator, bundle); final FloodDurationFacet facet = (FloodDurationFacet) bundle.getFacet(); final int index = facet.getWaterlevelIndex(); if (data instanceof FloodDurationCalculationResult) { final FloodDurationCalculationResult.ValueGetter valuegetter = new ValueGetter() { @Override public double getValue(final DurationWaterlevel waterlevel) { return waterlevel.getFloodDurDaysPerYear(); } }; final double[][] points = ((FloodDurationCalculationResult) data).getMainValueDurationPoints(valuegetter, index); return buildStepLineSeriesForType(points, generator, bundle, theme, visible); } } final String error = String.format("Unknown facet name: %s", facetName); throw new UnsupportedOperationException(error); } private String buildInfrastructureSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible, final AttributeKey riverside) { final FloodDurationCalculationResult data = (FloodDurationCalculationResult) getResult(generator, bundle); final double[][] points = data.getInfrastructurePoints(SInfoResultType.floodDuration, riverside); return buildSeriesForPoints(points, generator, bundle, theme, visible, null); } }