annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodHeightProcessor.java @ 9620:26e113e8224f

Nachtrag Pos. 20: flood duration calculation for multiple infrastructure groups/types, local class FloodDurationCalculationResult.Infrastructure renamed and extracted into own class
author mschaefer
date Thu, 10 Oct 2019 17:11:54 +0200
parents f8308db94634
children
rev   line source
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
2 * Software engineering by
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
5 *
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
9 */
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
10
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9208
diff changeset
11 package org.dive4elements.river.artifacts.sinfo.flood_duration;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
12
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
13 import java.util.HashSet;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
14 import java.util.Set;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
15
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
17 import org.dive4elements.artifactdatabase.state.Facet;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
18 import org.dive4elements.artifacts.CallContext;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
19 import org.dive4elements.river.artifacts.common.AbstractCalculationResult;
9347
08f46ccd37ba salix.regional refactoring
gernotbelger
parents: 9297
diff changeset
20 import org.dive4elements.river.artifacts.common.AbstractProcessor;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
21 import org.dive4elements.river.artifacts.resources.Resources;
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9208
diff changeset
22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
23 import org.dive4elements.river.artifacts.sinfo.flood_duration.FloodDurationCalculationResult.ValueGetter;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
24 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
25 import org.dive4elements.river.exports.DiagramGenerator;
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
26 import org.dive4elements.river.model.Attribute.AttributeKey;
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
27 import org.dive4elements.river.themes.ThemeDocument;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
28
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
29 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
30 * Processor to generate the facet and data series of infrastructure flood heights
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
31 *
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
32 * @author Matthias Schäfer
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
33 *
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
34 */
9347
08f46ccd37ba salix.regional refactoring
gernotbelger
parents: 9297
diff changeset
35 public final class FloodHeightProcessor extends AbstractProcessor {
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
36
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
37 private static final String FACET_FLOOD_HEIGHT_LEFT = "sinfo_facet_flood_height.left";
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
38
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
39 private static final String FACET_FLOOD_HEIGHT_RIGHT = "sinfo_facet_flood_height.right";
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
40
9612
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
41 private static final String FACET_MAIN_VALUE_HEIGHT_DESCRIPTION = "mainvalue.w.description";
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
42
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
43 private static final String FACET_MAIN_VALUE_HEIGHT = "mainvalue.w";
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
44
9297
7100a555607c Small fixes of the S-Info flood duration outputs
mschaefer
parents: 9285
diff changeset
45 private static final String I18N_AXIS_LABEL = "sinfo.chart.flood_duration.height.section.yaxis.label";
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
46
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
47 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
48
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
49 static {
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
50 HANDLED_FACET_TYPES.add(FACET_FLOOD_HEIGHT_LEFT);
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
51 HANDLED_FACET_TYPES.add(FACET_FLOOD_HEIGHT_RIGHT);
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
52 HANDLED_FACET_TYPES.add(FACET_MAIN_VALUE_HEIGHT);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
53 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
54
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
55 public FloodHeightProcessor() {
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
56 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
57 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
58
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
59 public static Facet createFloodHeightFacet(final CallContext context, final String hash, final String id, final AbstractCalculationResult result,
9620
26e113e8224f Nachtrag Pos. 20: flood duration calculation for multiple infrastructure groups/types,
mschaefer
parents: 9612
diff changeset
60 final int facetIndex, final int resultIndex, final FloodDurationInfrastructureChoice infrastructure) {
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
61
9612
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
62 final String facetName = infrastructure.getRiverside().equals(AttributeKey.LEFT) ? FACET_FLOOD_HEIGHT_LEFT : FACET_FLOOD_HEIGHT_RIGHT;
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
63 final String description = infrastructure.getFloodHeightLabel(context);
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
64 return new InfrastructureResultFacet(facetIndex, resultIndex, facetName, description, I18N_AXIS_LABEL, id, hash, infrastructure);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
65 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
66
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
67 public static Facet createMainValueHeightFacet(final CallContext context, final String hash, final String id, final FloodDurationCalculationResult result,
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
68 final int facetIndex, final int resultIndex, final int dataIndex) {
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
69 final String description = Resources.getMsg(context.getMeta(), FACET_MAIN_VALUE_HEIGHT_DESCRIPTION, FACET_MAIN_VALUE_HEIGHT_DESCRIPTION,
9285
9b16f58c62a7 Small cleanup/renames
mschaefer
parents: 9265
diff changeset
70 result.getWaterlevelLabel(dataIndex));
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
71
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9208
diff changeset
72 return new FloodDurationFacet(facetIndex, resultIndex, dataIndex, FACET_MAIN_VALUE_HEIGHT, description, ComputeType.ADVANCE, I18N_AXIS_LABEL, hash, id);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
73 }
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
74
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
75 @Override
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
76 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
77
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
78 final String facetName = bundle.getFacetName();
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
79
9612
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
80 if (FACET_FLOOD_HEIGHT_LEFT.contentEquals(facetName) || FACET_FLOOD_HEIGHT_RIGHT.contentEquals(facetName))
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
81 return buildInfrastructureSeries(generator, bundle, theme, visible);
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
82
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
83 if (FACET_MAIN_VALUE_HEIGHT.contentEquals(facetName)) {
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
84
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
85 final AbstractCalculationResult data = getResult(generator, bundle);
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
86
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9208
diff changeset
87 final FloodDurationFacet facet = (FloodDurationFacet) bundle.getFacet();
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9208
diff changeset
88 final int index = facet.getWaterlevelIndex();
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9208
diff changeset
89
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
90 if (data instanceof FloodDurationCalculationResult) {
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
91 final FloodDurationCalculationResult.ValueGetter valuegetter = new ValueGetter() {
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
92 @Override
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
93 public double getValue(final DurationWaterlevel waterlevel) {
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
94 return waterlevel.getWaterlevel();
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
95 }
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
96 };
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9229
diff changeset
97 final double[][] points = ((FloodDurationCalculationResult) data).getMainValueDurationPoints(valuegetter, index);
9347
08f46ccd37ba salix.regional refactoring
gernotbelger
parents: 9297
diff changeset
98 return buildSeriesForPoints(points, generator, bundle, theme, visible, null);
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
99 }
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
100 }
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
101
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
102 final String error = String.format("Unknown facet name: %s", facetName);
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
103 throw new UnsupportedOperationException(error);
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
104 }
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
105
9612
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
106 private String buildInfrastructureSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme,
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
107 final boolean visible) {
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
108
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
109 final InfrastructureResultFacet infFacet = (InfrastructureResultFacet) bundle.getFacet();
9620
26e113e8224f Nachtrag Pos. 20: flood duration calculation for multiple infrastructure groups/types,
mschaefer
parents: 9612
diff changeset
110 final FloodDurationInfrastructureChoice infrastructure = infFacet.getInfrastructure();
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
111
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
112 final FloodDurationCalculationResult data = (FloodDurationCalculationResult) getResult(generator, bundle);
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
113
9612
f8308db94634 #20 UI, Diagramme
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents: 9347
diff changeset
114 final double[][] points = data.getInfrastructurePoints(SInfoResultType.infrastructureHeight, infrastructure);
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
115
9347
08f46ccd37ba salix.regional refactoring
gernotbelger
parents: 9297
diff changeset
116 return buildSeriesForPoints(points, generator, bundle, theme, visible, null);
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
117 }
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
diff changeset
118 }

http://dive4elements.wald.intevation.org