comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/MainValuesQFacet.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesQFacet.java@35a6c9a49a76
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.model;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 import org.dive4elements.artifacts.Artifact;
9 import org.dive4elements.artifacts.CallContext;
10 import org.dive4elements.artifacts.DataProvider;
11
12 import org.dive4elements.artifactdatabase.state.DefaultFacet;
13
14 import org.dive4elements.river.artifacts.MainValuesArtifact;
15 import org.dive4elements.river.artifacts.math.Linear;
16 import org.dive4elements.river.jfree.FLYSAnnotation;
17 import org.dive4elements.river.jfree.StickyAxisAnnotation;
18
19 import org.dive4elements.river.exports.DurationCurveGenerator;
20
21
22 /**
23 * Facet to show Main Q Values.
24 * TODO Join with W implementation.
25 */
26 public class MainValuesQFacet
27 extends DefaultFacet
28 implements FacetTypes {
29
30 /** Own logger. */
31 private static Logger logger = Logger.getLogger(MainValuesQFacet.class);
32
33 /** Do we want MainValues at Gauge (not interpolated)? */
34 protected boolean isAtGauge;
35
36
37 /** Trivial Constructor. */
38 public MainValuesQFacet(String name, String description, boolean atGauge) {
39 this.description = description;
40 this.name = name;
41 this.index = 0;
42 this.isAtGauge = atGauge;
43 }
44
45
46 /**
47 * Set the hit-point in Q where a line drawn from the axis would hit the
48 * curve in WQDay (if hit).
49 * Employ linear interpolation.
50 */
51 protected static void setHitPoint(WQDay wqday, StickyAxisAnnotation annotation) {
52 int idx = 0;
53 float q = annotation.getPos();
54 boolean qIncreases = wqday.getQ(0) < wqday.getQ(wqday.size()-1);
55 if (qIncreases) {
56 while (idx < wqday.size() && wqday.getQ(idx) < q) {
57 idx++;
58 }
59 }
60 else {
61 idx = wqday.size() -1;
62 while (idx > 0 && wqday.getQ(idx) > q) {
63 idx--;
64 }
65 }
66
67 double day = 0d;
68 int mod = (qIncreases) ? -1 : +1;
69 if (idx != 0 && idx <= wqday.size()-1) {
70 day = Linear.linear(q, wqday.getQ(idx +mod), wqday.getQ(idx),
71 wqday.getDay(idx+mod), wqday.getDay(idx));
72 annotation.setHitPoint((float)day);
73 }
74 else {
75 logger.debug("StickyAnnotation does not hit wqday curve");
76 }
77 }
78
79
80 /**
81 * Returns the data this facet requires.
82 *
83 * @param artifact the owner artifact.
84 * @param context the CallContext (ignored).
85 *
86 * @return the data.
87 */
88 @Override
89 public Object getData(Artifact artifact, CallContext context) {
90 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact;
91
92 List<NamedDouble> qs = mvArtifact.getMainValuesQ(isAtGauge);
93 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>();
94
95 WQDay wqdays = null;
96 List<DataProvider> providers = context.
97 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE);
98 if (providers.size() < 1) {
99 logger.warn("Could not find durationcurve data provider.");
100 }
101 else {
102 wqdays = (WQDay) providers.get(0).provideData(
103 DurationCurveFacet.BB_DURATIONCURVE,
104 null,
105 context);
106 }
107
108 // Rather specific case, Q-Annotations at a maybe second yaxis.
109 StickyAxisAnnotation annotation = null;
110 if (this.name.equals(DURATION_MAINVALUES_Q)) {
111 for (NamedDouble q: qs) {
112 annotation =
113 new StickyAxisAnnotation(
114 q.getName(),
115 (float) q.getValue(),
116 StickyAxisAnnotation.SimpleAxis.Y_AXIS,
117 DurationCurveGenerator.YAXIS.Q.idx);
118 xy.add(annotation);
119 if (wqdays != null) {
120 setHitPoint(wqdays, annotation);
121 }
122 }
123 }
124 else {
125 for (NamedDouble q: qs) {
126 annotation =
127 new StickyAxisAnnotation(
128 q.getName(),
129 (float) q.getValue(),
130 StickyAxisAnnotation.SimpleAxis.X_AXIS);
131 xy.add(annotation);
132 if (wqdays != null) {
133 setHitPoint(wqdays, annotation);
134 }
135 }
136 }
137
138 return new FLYSAnnotation(description, xy);
139 }
140
141
142 /**
143 * Create a deep copy of this Facet.
144 * @return a deep copy.
145 */
146 @Override
147 public MainValuesQFacet deepCopy() {
148 MainValuesQFacet copy = new MainValuesQFacet(this.name,
149 description, this.isAtGauge);
150 copy.set(this);
151 return copy;
152 }
153 }
154 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org