comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationInfrastructureFacet.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 f318359b81a2
comparison
equal deleted inserted replaced
9268:ae9dee74e43e 9269:83ebeb620b5a
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
9 */ 9 */
10 10
11 package org.dive4elements.river.artifacts.sinfo.flood_duration; 11 package org.dive4elements.river.artifacts.sinfo.flood_duration;
12 12
13 import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM;
14
15 import java.util.List; 13 import java.util.List;
16 14
17 import org.apache.log4j.Logger; 15 import org.apache.log4j.Logger;
18 import org.dive4elements.artifactdatabase.state.DefaultFacet; 16 import org.dive4elements.artifactdatabase.state.DefaultFacet;
19 import org.dive4elements.artifacts.Artifact; 17 import org.dive4elements.artifacts.Artifact;
20 import org.dive4elements.artifacts.CallContext; 18 import org.dive4elements.artifacts.CallContext;
21 import org.dive4elements.river.artifacts.D4EArtifact; 19 import org.dive4elements.river.artifacts.D4EArtifact;
22 import org.dive4elements.river.artifacts.model.CalculationResult; 20 import org.dive4elements.river.artifacts.model.CalculationResult;
23 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;
24 import org.dive4elements.river.jfree.RiverAnnotation; 23 import org.dive4elements.river.jfree.RiverAnnotation;
25 import org.dive4elements.river.jfree.StickyAxisAnnotation; 24 import org.dive4elements.river.jfree.StickyAxisAnnotation;
26 25
27 26
28 /** 27 /**
41 } 40 }
42 41
43 42
44 /** 43 /**
45 * Returns the data this facet requires. 44 * Returns the data this facet requires.
46 *
47 * @param artifact the owner artifact.
48 * @param context the CallContext (can be used to find out if in
49 * navigable fixation-setting, or durationcurve).
50 *
51 * @return the data.
52 */ 45 */
53 @Override 46 @Override
54 public Object getData(final Artifact artifact, final CallContext context) { 47 public Object getData(final Artifact artifact, final CallContext context) {
55 48
56 log.debug("Get data for flood duration curve infrastructure"); 49 log.debug("Get data for flood duration curve infrastructure");
59 52
60 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); 53 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);
61 54
62 final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData(); 55 final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData();
63 56
64 // final List<StickyAxisAnnotation> annotations = new ArrayList<>(); 57 final double currentKm = FixChartGenerator.getCurrentKm(context);
65 // annotations.add(data.getInfrastructureWAnnotation());
66 // annotations.add(data.getInfrastructureQAnnotation());
67
68 final double currentKm = getCurrentKm(context);
69 58
70 final List<StickyAxisAnnotation> annotations = new FloodDurationCalculation(context).calcInfrastructureAnnotations(currentKm, 59 final List<StickyAxisAnnotation> annotations = new FloodDurationCalculation(context).calcInfrastructureAnnotations(currentKm,
71 data.getResults().get(this.index)); 60 data.getResults().get(this.index));
72 if (annotations != null) {
73 return new RiverAnnotation(this.description, annotations);
74 }
75 else
76 return null;
77 }
78 61
79 /** 62 return new RiverAnnotation(this.description, annotations);
80 * Returns the current km from the context.
81 * If the context is null or doesn't contain a currentKm
82 * then a double value of -1 will be returned.
83 *
84 * @param context
85 * The CallContext instance
86 * @return the current km as double
87 */
88 // FIXME: copied from org.dive4elements.river.artifacts.model.fixings.FixingsFacet
89 private double getCurrentKm(final CallContext context) {
90 if (context == null)
91 return Double.NaN;
92
93 final Double dkm = (Double) context.getContextValue(CURRENT_KM);
94 if (dkm == null)
95 return Double.NaN;
96
97 return dkm.doubleValue();
98 } 63 }
99 64
100 65
101 /** 66 /**
102 * Create a deep copy of this Facet. 67 * Create a deep copy of this Facet.

http://dive4elements.wald.intevation.org