comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesWFacet.java @ 8331:27d42c9ee367

Main values: Reduce code duplication and correct logic to specify whether we are at gauge or not.
author "Tom Gottfried <tom@intevation.de>"
date Fri, 26 Sep 2014 09:44:48 +0200
parents e4606eae8ea5
children 5e38e2924c07
comparison
equal deleted inserted replaced
8330:e87a993c6611 8331:27d42c9ee367
22 import org.dive4elements.river.artifacts.MainValuesArtifact; 22 import org.dive4elements.river.artifacts.MainValuesArtifact;
23 import org.dive4elements.river.jfree.RiverAnnotation; 23 import org.dive4elements.river.jfree.RiverAnnotation;
24 import org.dive4elements.river.jfree.StickyAxisAnnotation; 24 import org.dive4elements.river.jfree.StickyAxisAnnotation;
25 import org.dive4elements.river.exports.fixings.FixChartGenerator; 25 import org.dive4elements.river.exports.fixings.FixChartGenerator;
26 26
27 import static org.dive4elements.river.exports.injector.InjectorConstants.PNP;
27 28
28 /** 29 /**
29 * Facet to show Main W Values. 30 * Facet to show Main W Values.
30 */ 31 */
31 public class MainValuesWFacet 32 public class MainValuesWFacet
33 implements FacetTypes { 34 implements FacetTypes {
34 35
35 /** Own log. */ 36 /** Own log. */
36 private static Logger log = Logger.getLogger(MainValuesWFacet.class); 37 private static Logger log = Logger.getLogger(MainValuesWFacet.class);
37 38
38 /** Do we want MainValues at Gauge (not interpolated)? */
39 protected boolean isAtGauge;
40
41 /** Trivial Constructor. */ 39 /** Trivial Constructor. */
42 public MainValuesWFacet(String name, String description, boolean atGauge) { 40 public MainValuesWFacet(String name, String description) {
43 this.description = description; 41 this.description = description;
44 this.name = name; 42 this.name = name;
45 this.index = 0; 43 this.index = 0;
46 this.isAtGauge = atGauge;
47 } 44 }
48 45
49 46
50 /** 47 /**
51 * Set the hit-point in W where a line drawn from the axis would hit the 48 * Set the hit-point in W where a line drawn from the axis would hit the
77 */ 74 */
78 @Override 75 @Override
79 public Object getData(Artifact artifact, CallContext context) { 76 public Object getData(Artifact artifact, CallContext context) {
80 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact; 77 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact;
81 78
82 List<NamedDouble> ws = mvArtifact.getMainValuesW(isAtGauge); 79 List<NamedDouble> ws = mvArtifact.getMainValuesW(
80 context.getContextValue(PNP));
83 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); 81 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>();
84 82
85 // Find whether a duration curve is on the blackboard. 83 // Find whether a duration curve is on the blackboard.
86 WQDay wqdays = null; 84 WQDay wqdays = null;
87 List<DataProvider> providers = context. 85 List<DataProvider> providers = context.
88 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE); 86 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE);
89 if (providers.size() < 1) { 87 if (providers.size() < 1) {
90 log.warn("Could not find durationcurve data provider.");
91 // Do we have a current km in context? 88 // Do we have a current km in context?
92 // If so, we are likely fetching data for a navigable 89 // If so, we are likely fetching data for a navigable
93 // diagram (i.e. in fixation branch). 90 // diagram (i.e. in fixation branch).
94 Object xkm = context.getContextValue(FixChartGenerator.CURRENT_KM); 91 Object xkm = context.getContextValue(FixChartGenerator.CURRENT_KM);
95 if (xkm != null) { 92 if (xkm != null) {
96 Double ckm = (Double)xkm; 93 Double ckm = (Double)xkm;
97 // Return linearly interpolated values, in m if not at gauge, 94 // Return linearly interpolated values. Always in m, as
98 // in cm over datum if at gauge. 95 // cm over datum ist represented by a second axis.
99 ws = mvArtifact.getMainValuesW(new double[] {ckm}); 96 ws = mvArtifact.getMainValuesW(
97 new double[] {ckm},
98 context.getContextValue(PNP)
99 );
100 } 100 }
101 } 101 }
102 else { 102 else {
103 wqdays = (WQDay) providers.get(0).provideData( 103 wqdays = (WQDay) providers.get(0).provideData(
104 DurationCurveFacet.BB_DURATIONCURVE, 104 DurationCurveFacet.BB_DURATIONCURVE,
105 null, 105 null,
106 context); 106 context);
107 } 107 }
108 108
109 for (NamedDouble w: ws) { 109 for (NamedDouble w: ws) {
110 log.debug("W Annotation at " + w.getValue() + " ("+w.getName()+")"+ wqdays);
111 if (Double.isNaN(w.getValue())) { 110 if (Double.isNaN(w.getValue())) {
112 log.warn("NaN MainValue " + w.getName()); 111 log.warn("NaN MainValue " + w.getName());
113 continue; 112 continue;
114 } 113 }
115 StickyAxisAnnotation annotation = 114 StickyAxisAnnotation annotation =
132 * @return a deep copy. 131 * @return a deep copy.
133 */ 132 */
134 @Override 133 @Override
135 public MainValuesWFacet deepCopy() { 134 public MainValuesWFacet deepCopy() {
136 MainValuesWFacet copy = new MainValuesWFacet(this.name, 135 MainValuesWFacet copy = new MainValuesWFacet(this.name,
137 description, this.isAtGauge); 136 description);
138 copy.set(this); 137 copy.set(this);
139 return copy; 138 return copy;
140 } 139 }
141 } 140 }
142 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 141 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org