annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationProcessor.java @ 9229:0dcd1cd41915

Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
author mschaefer
date Thu, 05 Jul 2018 16:49:42 +0200
parents 0fc9c82e744e
children e5367900dd6d
rev   line source
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
2 * Software engineering by
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
5 *
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
9 */
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
10
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9209
diff changeset
11 package org.dive4elements.river.artifacts.sinfo.flood_duration;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
12
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
13 import java.util.HashSet;
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
14 import java.util.Set;
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
15
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
17 import org.dive4elements.artifactdatabase.state.Facet;
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
18 import org.dive4elements.artifacts.CallContext;
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
19 import org.dive4elements.river.artifacts.common.AbstractCalculationResult;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
20 import org.dive4elements.river.artifacts.resources.Resources;
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9209
diff changeset
21 import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoProcessor;
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
22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultFacet;
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9209
diff changeset
23 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
24 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: 9176
diff changeset
25 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
26 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
27 import org.dive4elements.river.model.Attribute.AttributeKey;
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
28 import org.dive4elements.river.themes.ThemeDocument;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
29
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
30 /**
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
31 * Processor to generate the facet and data series of infrastructure flood durations
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
32 *
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
33 * @author Matthias Schäfer
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
34 *
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
35 */
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
36 public final class FloodDurationProcessor extends AbstractSInfoProcessor {
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
37
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
38 private static final String FACET_FLOOD_DURATION_LEFT = "sinfo_facet_flood_duration.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
39
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
40 private static final String FACET_FLOOD_DURATION_RIGHT = "sinfo_facet_flood_duration.right";
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
41
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
42 private static final String FACET_FLOOD_DURATION_DESCRIPTION = "sinfo_facet_flood_duration.description";
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
43
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
44 private static final String FACET_MAIN_VALUE_DURATION = "mainvalue.duration";
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
45
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
46 private static final String FACET_MAIN_VALUE_DURATION_DESCRIPTION = "mainvalue.duration.description";
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
47
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
48 private static final String I18N_AXIS_LABEL = "sinfo.chart.flood_duration.section.yaxis.label";
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
49
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
50 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
51
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
52 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
53 HANDLED_FACET_TYPES.add(FACET_FLOOD_DURATION_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
54 HANDLED_FACET_TYPES.add(FACET_FLOOD_DURATION_RIGHT);
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
55 HANDLED_FACET_TYPES.add(FACET_MAIN_VALUE_DURATION);
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
56 }
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
57
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
58 public FloodDurationProcessor() {
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
59 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
60 }
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
61
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
62 public static Facet createFloodDurationFacet(final CallContext context, final String hash, final String id, final AbstractCalculationResult result,
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
63 final int facetIndex, final int resultIndex) {
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
64
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
65 if (facetIndex == 0) {
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
66 final String description = Resources.getMsg(context.getMeta(), FACET_FLOOD_DURATION_DESCRIPTION, FACET_FLOOD_DURATION_DESCRIPTION,
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
67 SInfoResultType.localizeRiverside(context, AttributeKey.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
68 return new SInfoResultFacet(facetIndex, resultIndex, FACET_FLOOD_DURATION_LEFT, description, I18N_AXIS_LABEL, ComputeType.ADVANCE, id, hash);
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
69 }
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
70 else {
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
71 final String description = Resources.getMsg(context.getMeta(), FACET_FLOOD_DURATION_DESCRIPTION, FACET_FLOOD_DURATION_DESCRIPTION,
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
72 SInfoResultType.localizeRiverside(context, AttributeKey.RIGHT));
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
73 return new SInfoResultFacet(facetIndex, resultIndex, FACET_FLOOD_DURATION_RIGHT, description, I18N_AXIS_LABEL, ComputeType.ADVANCE, id, hash);
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
74 }
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
75 }
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
76
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
77 public static Facet createMainValueDurationFacet(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
78 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: 9176
diff changeset
79
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
80 final String description = Resources.getMsg(context.getMeta(), FACET_MAIN_VALUE_DURATION_DESCRIPTION, FACET_MAIN_VALUE_DURATION_DESCRIPTION,
9209
gernotbelger
parents: 9208
diff changeset
81 result.getMainValueLabel(dataIndex));
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
82
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9209
diff changeset
83 return new FloodDurationFacet(facetIndex, resultIndex, dataIndex, FACET_MAIN_VALUE_DURATION, description, ComputeType.ADVANCE, I18N_AXIS_LABEL, hash,
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9209
diff changeset
84 id);
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
85 }
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
86
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
87 @Override
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
88 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
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
89
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
90 final String facetName = bundle.getFacetName();
9203
9831f6c60473 AbstractSInfoLineProcessor refactoring
gernotbelger
parents: 9202
diff changeset
91
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
92 if (FACET_FLOOD_DURATION_LEFT.contentEquals(facetName)) {
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
93 return buildInfrastructureSeries(generator, bundle, theme, visible, AttributeKey.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
94 }
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
95
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
96 if (FACET_FLOOD_DURATION_RIGHT.contentEquals(facetName))
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
97 return buildInfrastructureSeries(generator, bundle, theme, visible, AttributeKey.RIGHT);
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
98
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
99 if (FACET_MAIN_VALUE_DURATION.contentEquals(facetName)) {
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
100
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
101 final AbstractCalculationResult data = getResult(generator, bundle);
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
102
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9209
diff changeset
103 final FloodDurationFacet facet = (FloodDurationFacet) bundle.getFacet();
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9209
diff changeset
104 final int index = facet.getWaterlevelIndex();
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9209
diff changeset
105
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
106 if (data instanceof FloodDurationCalculationResult) {
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
107 final FloodDurationCalculationResult.ValueGetter valuegetter = new ValueGetter() {
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
108 @Override
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
109 public double getValue(final DurationWaterlevel waterlevel) {
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
110 return waterlevel.getFloodDurDaysPerYear();
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
111 }
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
112 };
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9209
diff changeset
113 final double[][] points = ((FloodDurationCalculationResult) data).getMainValueDurationPoints(generator, valuegetter, index);
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
114 return buildStepLineSeriesForType(points, generator, bundle, theme, visible);
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
115 }
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
116 }
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
117
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
118 final String error = String.format("Unknown facet name: %s", facetName);
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
119 throw new UnsupportedOperationException(error);
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9203
diff changeset
120 }
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
121
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
122 private String buildInfrastructureSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible,
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
123 final AttributeKey riverside) {
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
124
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
125 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
126
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
127 final double[][] points = data.getInfrastructurePoints(SInfoResultType.floodDuration, riverside);
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
128
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
129 return buildSeriesForType(points, generator, bundle, theme, visible, null);
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9215
diff changeset
130 }
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff changeset
131 }

http://dive4elements.wald.intevation.org