comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationMainValuesWFacet.java @ 9269:83ebeb620b5a

Station specific main value annotations in S-Info flood duration curve, corrected infrastructure flood duration calculation
author mschaefer
date Thu, 19 Jul 2018 08:07:03 +0200
parents 465347d12990
children b40fbca03024
comparison
equal deleted inserted replaced
9268:ae9dee74e43e 9269:83ebeb620b5a
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH 2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
3 * 5 *
4 * This file is Free Software under the GNU AGPL (>=v3) 6 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
7 */ 9 */
8 10
9 package org.dive4elements.river.artifacts.sinfo.flood_duration; 11 package org.dive4elements.river.artifacts.sinfo.flood_duration;
10 12
11 import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; 13 import java.util.List;
12 14
13 import org.apache.log4j.Logger; 15 import org.apache.log4j.Logger;
14 import org.dive4elements.artifactdatabase.state.DefaultFacet; 16 import org.dive4elements.artifactdatabase.state.DefaultFacet;
15 import org.dive4elements.artifacts.Artifact; 17 import org.dive4elements.artifacts.Artifact;
16 import org.dive4elements.artifacts.CallContext; 18 import org.dive4elements.artifacts.CallContext;
17 import org.dive4elements.river.artifacts.D4EArtifact; 19 import org.dive4elements.river.artifacts.D4EArtifact;
18 import org.dive4elements.river.artifacts.model.CalculationResult; 20 import org.dive4elements.river.artifacts.model.CalculationResult;
19 import org.dive4elements.river.artifacts.model.WQDay;
20 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; 21 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
22 import org.dive4elements.river.exports.fixings.FixChartGenerator;
21 import org.dive4elements.river.jfree.RiverAnnotation; 23 import org.dive4elements.river.jfree.RiverAnnotation;
22 import org.dive4elements.river.jfree.StickyAxisAnnotation; 24 import org.dive4elements.river.jfree.StickyAxisAnnotation;
23 25
24 /** 26 /**
25 * Facet to show Main W Values. 27 * Facet to show Main W Values.
34 this.description = description; 36 this.description = description;
35 this.name = name; 37 this.name = name;
36 this.index = 0; 38 this.index = 0;
37 } 39 }
38 40
39
40 /**
41 * Set the hit-point in W where a line drawn from the axis would hit the
42 * curve in WQDay (if hit).
43 * Employ linear interpolation.
44 */
45 public static void setHitPoint(final WQDay wqday, final StickyAxisAnnotation annotation) {
46
47 final float w = annotation.getPos();
48 final Double day = wqday.interpolateDayByW(w);
49 if (day != null)
50 annotation.setHitPoint(day.floatValue());
51 else
52 log.debug("StickyAnnotation does not hit wqday curve: " + w);
53 }
54
55
56 /** 41 /**
57 * Returns the data this facet provides. 42 * Returns the data this facet provides.
58 *
59 * @param artifact the owner artifact.
60 * @param context the CallContext (can be used to find out if in
61 * navigable fixation-setting, or durationcurve).
62 *
63 * @return the data.
64 */ 43 */
65 @Override 44 @Override
66 public Object getData(final Artifact artifact, final CallContext context) { 45 public Object getData(final Artifact artifact, final CallContext context) {
67 46
68 log.debug("Get data for flood duration main value W data"); 47 log.debug("Get data for flood duration main value W data");
71 50
72 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); 51 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
73 52
74 final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData(); 53 final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData();
75 54
76 final double currentKm = getCurrentKm(context); 55 final double currentKm = FixChartGenerator.getCurrentKm(context);
77 56
78 return new RiverAnnotation(this.description, data.getMainValueWAnnotations()); 57 final List<StickyAxisAnnotation> annotations = new FloodDurationCalculation(context).calcMainValueWAnnotations(currentKm,
79 } 58 data.getResults().get(0));
80 59
81 /** 60 return new RiverAnnotation(this.description, annotations);
82 * Returns the current km from the context.
83 * If the context is null or doesn't contain a currentKm
84 * then a double value of -1 will be returned.
85 *
86 * @param context
87 * The CallContext instance
88 * @return the current km as double
89 */
90 // FIXME: copied from org.dive4elements.river.artifacts.model.fixings.FixingsFacet
91 private double getCurrentKm(final CallContext context) {
92 if (context == null)
93 return Double.NaN;
94
95 final Double dkm = (Double) context.getContextValue(CURRENT_KM);
96 if (dkm == null)
97 return Double.NaN;
98
99 return dkm.doubleValue();
100 } 61 }
101 62
102 63
103 /** 64 /**
104 * Create a deep copy of this Facet. 65 * Create a deep copy of this Facet.
109 final FloodDurationMainValuesWFacet copy = new FloodDurationMainValuesWFacet(this.name, this.description); 70 final FloodDurationMainValuesWFacet copy = new FloodDurationMainValuesWFacet(this.name, this.description);
110 copy.set(this); 71 copy.set(this);
111 return copy; 72 return copy;
112 } 73 }
113 } 74 }
114 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 75

http://dive4elements.wald.intevation.org