annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationMainValuesWFacet.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
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
2 * Software engineering by Intevation GmbH
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
3 *
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
7 */
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
8
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
9 package org.dive4elements.river.artifacts.sinfo.flood_duration;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
10
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
11 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
12
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
13 import org.apache.log4j.Logger;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
14 import org.dive4elements.artifactdatabase.state.DefaultFacet;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
15 import org.dive4elements.artifacts.Artifact;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
16 import org.dive4elements.artifacts.CallContext;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
17 import org.dive4elements.river.artifacts.D4EArtifact;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
18 import org.dive4elements.river.artifacts.model.CalculationResult;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
19 import org.dive4elements.river.artifacts.model.WQDay;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
20 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
21 import org.dive4elements.river.jfree.RiverAnnotation;
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
22 import org.dive4elements.river.jfree.StickyAxisAnnotation;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
23
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
24 /**
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
25 * Facet to show Main W Values.
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
26 */
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
27 public class FloodDurationMainValuesWFacet extends DefaultFacet {
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
28
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
29 /** Own log. */
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
30 private static Logger log = Logger.getLogger(FloodDurationMainValuesWFacet.class);
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
31
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
32 /** Trivial Constructor. */
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
33 public FloodDurationMainValuesWFacet(final String name, final String description) {
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
34 this.description = description;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
35 this.name = name;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
36 this.index = 0;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
37 }
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
38
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
39
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
40 /**
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
41 * Set the hit-point in W where a line drawn from the axis would hit the
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
42 * curve in WQDay (if hit).
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
43 * Employ linear interpolation.
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
44 */
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
45 public static void setHitPoint(final WQDay wqday, final StickyAxisAnnotation annotation) {
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
46
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
47 final float w = annotation.getPos();
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
48 final Double day = wqday.interpolateDayByW(w);
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
49 if (day != null)
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
50 annotation.setHitPoint(day.floatValue());
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
51 else
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
52 log.debug("StickyAnnotation does not hit wqday curve: " + w);
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
53 }
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
54
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
55
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
56 /**
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
57 * Returns the data this facet provides.
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
58 *
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
59 * @param artifact the owner artifact.
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
60 * @param context the CallContext (can be used to find out if in
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
61 * navigable fixation-setting, or durationcurve).
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
62 *
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
63 * @return the data.
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
64 */
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
65 @Override
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
66 public Object getData(final Artifact artifact, final CallContext context) {
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
67
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
68 log.debug("Get data for flood duration main value W data");
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
69
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
70 final D4EArtifact flys = (D4EArtifact) artifact;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
71
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
72 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
73
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
74 final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData();
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
75
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
76 final double currentKm = getCurrentKm(context);
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
77
9259
66b003701546 Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents: 9257
diff changeset
78 return new RiverAnnotation(this.description, data.getMainValueWAnnotations());
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
79 }
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
80
9266
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
81 /**
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
82 * Returns the current km from the context.
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
83 * 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
84 * 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
85 *
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
86 * @param context
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
87 * The CallContext instance
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
88 * @return the current km as double
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
89 */
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
90 // 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
91 private double getCurrentKm(final CallContext context) {
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
92 if (context == null)
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
93 return Double.NaN;
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
94
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
95 final Double dkm = (Double) context.getContextValue(CURRENT_KM);
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
96 if (dkm == null)
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
97 return Double.NaN;
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 return dkm.doubleValue();
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
100 }
465347d12990 Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents: 9259
diff changeset
101
9257
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
102
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
103 /**
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
104 * Create a deep copy of this Facet.
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
105 * @return a deep copy.
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
106 */
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
107 @Override
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
108 public FloodDurationMainValuesWFacet deepCopy() {
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
109 final FloodDurationMainValuesWFacet copy = new FloodDurationMainValuesWFacet(this.name, this.description);
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
110 copy.set(this);
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
111 return copy;
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
112 }
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
113 }
ef7b65576d4b Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
diff changeset
114 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org