Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationState.java @ 9631:6ecd1a28017f
Nachtrag Pos. 20: Q theme for height chart added, calculator corrected (rows for km without any infrastructure)
author | mschaefer |
---|---|
date | Tue, 15 Oct 2019 12:26:13 +0200 |
parents | 26e113e8224f |
children |
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.List; import java.util.Set; import org.apache.commons.lang.StringUtils; import org.dive4elements.artifactdatabase.state.Facet; import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.ChartArtifact; import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.model.Calculation; import org.dive4elements.river.artifacts.model.CalculationResult; import org.dive4elements.river.artifacts.model.DataFacet; import org.dive4elements.river.artifacts.model.EmptyFacet; import org.dive4elements.river.artifacts.model.FacetTypes; import org.dive4elements.river.artifacts.model.ReportFacet; import org.dive4elements.river.artifacts.resources.Resources; import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; import org.dive4elements.river.artifacts.states.DefaultState; import org.dive4elements.river.model.Attribute.AttributeKey; /** * Last state of the S-Info flood duration workflow that calculates and outputs the result */ public class FloodDurationState extends DefaultState { private static final long serialVersionUID = 1L; /** * From this state can only be continued trivially. */ @Override protected String getUIProvider() { return "continue"; } @Override public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { if (artifact instanceof ChartArtifact) { facets.add(new EmptyFacet()); return null; } return compute((SINFOArtifact) artifact, context, hash, facets, old); } @Override public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { if (artifact instanceof ChartArtifact) { facets.add(new EmptyFacet()); return null; } return compute((SINFOArtifact) artifact, context, hash, facets, old); } /** * Compute result or returned object from cache, create facets. * * @param old * Object that was cached. */ private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { final CalculationResult res = doCompute(sinfo, context, old); if (facets == null) return res; final FloodDurationCalculationResults results = (FloodDurationCalculationResults) res.getData(); final List<FloodDurationCalculationResult> resultList = results.getResults(); int resultIndex = 0; int themeCount = 0; for (final FloodDurationCalculationResult result : resultList) { if (resultIndex == 0) { /* we only have one result, but safety first... */ /* Setting the valid stations as data to the state, so the NaviChartOutputTab knows what are the valid stations */ final List<Double> validDurationChartKilometers = result.getValidDurationChartKilometers(); final String validKilometerString = StringUtils.join(validDurationChartKilometers, ','); sinfo.addStringData("validStations", validKilometerString); } final FloodDurationAccess access = new FloodDurationAccess(sinfo); final int waterlevelCount = result.getWaterlevelCount(); for (int j = 0; j < waterlevelCount; j++) { // final String waterlevelLabel = result.getMainValueLabel(j); // FIXME: use label as label for theme // final int facetIndex, final int resultIndex, final int dataIndex facets.add(FloodDurationProcessor.createMainValueDurationFacet(context, hash, this.id, result, themeCount++, resultIndex, j)); facets.add(FloodHeightProcessor.createMainValueHeightFacet(context, hash, this.id, result, themeCount++, resultIndex, j)); facets.add(FloodQProcessor.createMainValueQFacet(context, hash, this.id, result, themeCount++, resultIndex, j)); } final String nameW = Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.w"); final String nameQ = Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.q"); facets.add(FloodDurationCurveProcessor.createFloodDurationWCurveFacet(context, hash, this.id, result, themeCount++, resultIndex, nameW)); facets.add(FloodDurationCurveProcessor.createFloodDurationQCurveFacet(context, hash, this.id, result, themeCount++, resultIndex, nameQ)); if (waterlevelCount >= 1) { facets.add(FloodDurationCurveProcessor.createMainValuesWFacet(context, hash, this.id, result, themeCount++, resultIndex, Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.mainw"))); facets.add(FloodDurationCurveProcessor.createMainValuesQFacet(context, hash, this.id, result, themeCount++, resultIndex, Resources.getMsg(context.getMeta(), "sinfo.chart.flood_duration.curve.mainq"), null)); } final AttributeKey choice = access.getRiverside().getAttributeKey(); for (final AttributeKey riversideC : getRiversides(choice)) { facets.add(FloodDurationCurveProcessor.createInfrastructureFacet(context, hash, this.id, result, themeCount++, resultIndex, true, riversideC)); facets.add(FloodDurationCurveProcessor.createInfrastructureFacet(context, hash, this.id, result, themeCount++, resultIndex, false, riversideC)); } final Set<FloodDurationInfrastructureChoice> infrastructures = result.getInfrastructureMap(); for (final FloodDurationInfrastructureChoice entry : infrastructures) { facets.add(FloodDurationProcessor.createFloodDurationFacet(context, hash, this.id, result, themeCount++, resultIndex, entry)); facets.add(FloodHeightProcessor.createFloodHeightFacet(context, hash, this.id, result, themeCount++, resultIndex, entry)); } facets.add(new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id)); facets.add(new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id)); resultIndex++; } final Calculation report = res.getReport(); if (report.hasProblems()) facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); return res; } private Set<AttributeKey> getRiversides(final AttributeKey choice) { final Set<AttributeKey> usedRiversides = new HashSet<>(); if (choice.equals(AttributeKey.LEFT)) usedRiversides.add(AttributeKey.LEFT); else if (choice.equals(AttributeKey.RIGHT)) usedRiversides.add(AttributeKey.RIGHT); else { usedRiversides.add(AttributeKey.RIGHT); usedRiversides.add(AttributeKey.LEFT); } return usedRiversides; } private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { if (old instanceof CalculationResult) return (CalculationResult) old; return new FloodDurationCalculation(context).calculate(sinfo); } }