comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesQFacet.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
20 import org.dive4elements.artifactdatabase.state.DefaultFacet; 20 import org.dive4elements.artifactdatabase.state.DefaultFacet;
21 21
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.jfree.StickyAxisAnnotation.SimpleAxis;
25 26
26 import org.dive4elements.river.exports.DurationCurveGenerator; 27 import org.dive4elements.river.exports.DurationCurveGenerator;
27 import org.dive4elements.river.exports.fixings.FixChartGenerator; 28 import org.dive4elements.river.exports.fixings.FixChartGenerator;
29
30 import static org.dive4elements.river.exports.injector.InjectorConstants.PNP;
28 31
29 32
30 /** 33 /**
31 * Facet to show Main Q Values. 34 * Facet to show Main Q Values.
32 * TODO Join with W implementation. 35 * TODO Join with W implementation.
36 implements FacetTypes { 39 implements FacetTypes {
37 40
38 /** Own log. */ 41 /** Own log. */
39 private static Logger log = Logger.getLogger(MainValuesQFacet.class); 42 private static Logger log = Logger.getLogger(MainValuesQFacet.class);
40 43
41 /** Do we want MainValues at Gauge (not interpolated)? */
42 protected boolean isAtGauge;
43
44
45 /** Trivial Constructor. */ 44 /** Trivial Constructor. */
46 public MainValuesQFacet(String name, String description, boolean atGauge) { 45 public MainValuesQFacet(String name, String description) {
47 this.description = description; 46 this.description = description;
48 this.name = name; 47 this.name = name;
49 this.index = 0; 48 this.index = 0;
50 this.isAtGauge = atGauge;
51 } 49 }
52 50
53 /** 51 /**
54 * Set the hit-point in Q where a line drawn from the axis would hit the 52 * Set the hit-point in Q where a line drawn from the axis would hit the
55 * curve in WQDay (if hit). 53 * curve in WQDay (if hit).
80 */ 78 */
81 @Override 79 @Override
82 public Object getData(Artifact artifact, CallContext context) { 80 public Object getData(Artifact artifact, CallContext context) {
83 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact; 81 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact;
84 82
85 List<NamedDouble> qs = mvArtifact.getMainValuesQ(isAtGauge); 83 List<NamedDouble> qs = mvArtifact.getMainValuesQ(
84 context.getContextValue(PNP));
86 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); 85 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>();
87 86
87 // Find whether a duration curve is on the blackboard.
88 WQDay wqdays = null; 88 WQDay wqdays = null;
89 List<DataProvider> providers = context. 89 List<DataProvider> providers = context.
90 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE); 90 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE);
91 if (providers.size() < 1) { 91 if (providers.size() < 1) {
92 log.warn("Could not find durationcurve data provider.");
93 // Do we have a current km in context? 92 // Do we have a current km in context?
94 // If so, we are likely fetching data for a navigable 93 // If so, we are likely fetching data for a navigable
95 // diagram (i.e. in fixation branch). 94 // diagram (i.e. in fixation branch).
96 Object xkm = context.getContextValue(FixChartGenerator.CURRENT_KM); 95 Object xkm = context.getContextValue(FixChartGenerator.CURRENT_KM);
97 if (xkm != null) { 96 if (xkm != null) {
98 Double ckm = (Double)xkm; 97 Double ckm = (Double)xkm;
99 // Return linearly interpolated values, in m if not at gauge, 98 qs = mvArtifact.getMainValuesQ(
100 // in cm if at gauge. 99 new double[] {ckm},
101 qs = mvArtifact.getMainValuesQ(new double[] {ckm}); 100 context.getContextValue(PNP));
102 } 101 }
103 } 102 }
104 else { 103 else {
105 wqdays = (WQDay) providers.get(0).provideData( 104 wqdays = (WQDay) providers.get(0).provideData(
106 DurationCurveFacet.BB_DURATIONCURVE, 105 DurationCurveFacet.BB_DURATIONCURVE,
108 context); 107 context);
109 } 108 }
110 109
111 // Rather specific case, Q-Annotations at a maybe second yaxis. 110 // Rather specific case, Q-Annotations at a maybe second yaxis.
112 StickyAxisAnnotation annotation = null; 111 StickyAxisAnnotation annotation = null;
113 if (this.name.equals(DURATION_MAINVALUES_Q)) { 112
114 for (NamedDouble q: qs) { 113 // defaults if not drawing a duration curve
115 if (Double.isNaN(q.getValue())) { 114 SimpleAxis axis = SimpleAxis.X_AXIS;
116 log.warn("NaN MainValue " + q.getName()); 115 int axisSymbol = 0;
117 continue; 116
118 } 117 if (providers.size() >= 1) {
119 annotation = 118 // for duration curve, overwrite previously given default
120 new StickyAxisAnnotation( 119 axis = SimpleAxis.Y_AXIS;
121 q.getName(), 120 axisSymbol = DurationCurveGenerator.YAXIS.Q.idx;
122 (float) q.getValue(), 121 }
123 StickyAxisAnnotation.SimpleAxis.Y_AXIS, 122
124 DurationCurveGenerator.YAXIS.Q.idx); 123 for (NamedDouble q: qs) {
125 xy.add(annotation); 124 if (Double.isNaN(q.getValue())) {
126 if (wqdays != null) { 125 log.warn("NaN MainValue " + q.getName());
127 setHitPoint(wqdays, annotation); 126 continue;
128 }
129 } 127 }
130 } 128 annotation =
131 else { 129 new StickyAxisAnnotation(
132 for (NamedDouble q: qs) { 130 q.getName(),
133 if (Double.isNaN(q.getValue())) { 131 (float) q.getValue(),
134 log.warn("NaN MainValue " + q.getName()); 132 axis,
135 continue; 133 axisSymbol);
136 } 134 xy.add(annotation);
137 annotation = 135 if (wqdays != null) {
138 new StickyAxisAnnotation( 136 setHitPoint(wqdays, annotation);
139 q.getName(),
140 (float) q.getValue(),
141 StickyAxisAnnotation.SimpleAxis.X_AXIS);
142 xy.add(annotation);
143 if (wqdays != null) {
144 setHitPoint(wqdays, annotation);
145 }
146 } 137 }
147 } 138 }
148 139
149 return new RiverAnnotation(description, xy); 140 return new RiverAnnotation(description, xy);
150 } 141 }
155 * @return a deep copy. 146 * @return a deep copy.
156 */ 147 */
157 @Override 148 @Override
158 public MainValuesQFacet deepCopy() { 149 public MainValuesQFacet deepCopy() {
159 MainValuesQFacet copy = new MainValuesQFacet(this.name, 150 MainValuesQFacet copy = new MainValuesQFacet(this.name,
160 description, this.isAtGauge); 151 description);
161 copy.set(this); 152 copy.set(this);
162 return copy; 153 return copy;
163 } 154 }
164 } 155 }
165 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 156 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org