annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationInfrastructureFacet.java @ 9266:465347d12990

Station specific calculation of flood duration curve and infrastructure annotations
author mschaefer
date Wed, 18 Jul 2018 12:20:01 +0200
parents 66b003701546
children 83ebeb620b5a
rev   line source
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
2 * Software engineering by
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
5 *
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
9 */
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
10
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
11 package org.dive4elements.river.artifacts.sinfo.flood_duration;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
12
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
13 import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM;
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
14
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
15 import java.util.List;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
16
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
17 import org.apache.log4j.Logger;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
18 import org.dive4elements.artifactdatabase.state.DefaultFacet;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
19 import org.dive4elements.artifacts.Artifact;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
20 import org.dive4elements.artifacts.CallContext;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
21 import org.dive4elements.river.artifacts.D4EArtifact;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
22 import org.dive4elements.river.artifacts.model.CalculationResult;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
23 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
24 import org.dive4elements.river.jfree.RiverAnnotation;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
25 import org.dive4elements.river.jfree.StickyAxisAnnotation;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
26
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
27
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
28 /**
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
29 * Facet to show W and Q annotation lines of an infrastructure height.
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
30 */
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
31 public class FloodDurationInfrastructureFacet extends DefaultFacet {
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
32
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
33 /** Own log. */
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
34 private static Logger log = Logger.getLogger(FloodDurationInfrastructureFacet.class);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
35
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
36 /** Trivial Constructor. */
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
37 public FloodDurationInfrastructureFacet(final String name, final String description) {
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
38 this.description = description;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
39 this.name = name;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
40 this.index = 0;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
41 }
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
42
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
43
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
44 /**
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
45 * Returns the data this facet requires.
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
46 *
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
47 * @param artifact the owner artifact.
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
48 * @param context the CallContext (can be used to find out if in
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
49 * navigable fixation-setting, or durationcurve).
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
50 *
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
51 * @return the data.
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
52 */
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
53 @Override
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
54 public Object getData(final Artifact artifact, final CallContext context) {
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
55
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
56 log.debug("Get data for flood duration curve infrastructure");
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
57
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
58 final D4EArtifact flys = (D4EArtifact) artifact;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
59
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
60 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
61
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
62 final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData();
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
63
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
64 // final List<StickyAxisAnnotation> annotations = new ArrayList<>();
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
65 // annotations.add(data.getInfrastructureWAnnotation());
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
66 // annotations.add(data.getInfrastructureQAnnotation());
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
67
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
68 final double currentKm = getCurrentKm(context);
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
69
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
70 final List<StickyAxisAnnotation> annotations = new FloodDurationCalculation(context).calcInfrastructureAnnotations(currentKm,
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
71 data.getResults().get(this.index));
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
72 if (annotations != null) {
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
73 return new RiverAnnotation(this.description, annotations);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
74 }
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
75 else
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
76 return null;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
77 }
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
78
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
79 /**
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
80 * Returns the current km from the context.
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
81 * If the context is null or doesn't contain a currentKm
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
82 * then a double value of -1 will be returned.
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
83 *
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
84 * @param context
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
85 * The CallContext instance
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
86 * @return the current km as double
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
87 */
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
88 // FIXME: copied from org.dive4elements.river.artifacts.model.fixings.FixingsFacet
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
89 private double getCurrentKm(final CallContext context) {
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
90 if (context == null)
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
91 return Double.NaN;
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
92
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
93 final Double dkm = (Double) context.getContextValue(CURRENT_KM);
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
94 if (dkm == null)
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
95 return Double.NaN;
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
96
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
97 return dkm.doubleValue();
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
98 }
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
99
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
100
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
101 /**
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
102 * Create a deep copy of this Facet.
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
103 * @return a deep copy.
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
104 */
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
105 @Override
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
106 public FloodDurationInfrastructureFacet deepCopy() {
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
107 final FloodDurationInfrastructureFacet copy = new FloodDurationInfrastructureFacet(this.name, this.description);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
108 copy.set(this);
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
109 return copy;
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
110 }
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
111 }
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
112

http://dive4elements.wald.intevation.org