Mercurial > dive4elements > river
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 | 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 | 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 | 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 | 22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
9208 | 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 | 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 | 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 | 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 | 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 | 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 | 62 final String facetName = infrastructure.getRiverside().equals(AttributeKey.LEFT) ? FACET_FLOOD_HEIGHT_LEFT : FACET_FLOOD_HEIGHT_RIGHT; |
63 final String description = infrastructure.getFloodHeightLabel(context); | |
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 | 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 | 70 result.getWaterlevelLabel(dataIndex)); |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9203
diff
changeset
|
71 |
9215 | 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 | 74 |
75 @Override | |
76 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { | |
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 | 80 if (FACET_FLOOD_HEIGHT_LEFT.contentEquals(facetName) || FACET_FLOOD_HEIGHT_RIGHT.contentEquals(facetName)) |
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 | 84 |
85 final AbstractCalculationResult data = getResult(generator, bundle); | |
86 | |
9215 | 87 final FloodDurationFacet facet = (FloodDurationFacet) bundle.getFacet(); |
88 final int index = facet.getWaterlevelIndex(); | |
89 | |
9208 | 90 if (data instanceof FloodDurationCalculationResult) { |
91 final FloodDurationCalculationResult.ValueGetter valuegetter = new ValueGetter() { | |
92 @Override | |
93 public double getValue(final DurationWaterlevel waterlevel) { | |
94 return waterlevel.getWaterlevel(); | |
95 } | |
96 }; | |
9265 | 97 final double[][] points = ((FloodDurationCalculationResult) data).getMainValueDurationPoints(valuegetter, index); |
9347 | 98 return buildSeriesForPoints(points, generator, bundle, theme, visible, null); |
9208 | 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 | 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 | 106 private String buildInfrastructureSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, |
107 final boolean visible) { | |
108 | |
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 | 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 | 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 } |