Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesQFacet.java @ 2778:26f2e7e500dd
Also draw lines from q mainvalues to duration curve.
flys-artifacts/trunk@4517 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 25 May 2012 13:31:40 +0000 |
parents | 105097966111 |
children | 0f7abd95c6e2 |
comparison
equal
deleted
inserted
replaced
2777:5543492f2da4 | 2778:26f2e7e500dd |
---|---|
1 package de.intevation.flys.artifacts.model; | 1 package de.intevation.flys.artifacts.model; |
2 | 2 |
3 import java.util.ArrayList; | 3 import java.util.ArrayList; |
4 import java.util.List; | 4 import java.util.List; |
5 | 5 |
6 import org.apache.log4j.Logger; | |
7 | |
6 import de.intevation.artifacts.Artifact; | 8 import de.intevation.artifacts.Artifact; |
7 import de.intevation.artifacts.CallContext; | 9 import de.intevation.artifacts.CallContext; |
10 import de.intevation.artifacts.DataProvider; | |
8 | 11 |
9 import de.intevation.artifactdatabase.state.DefaultFacet; | 12 import de.intevation.artifactdatabase.state.DefaultFacet; |
10 | 13 |
11 import de.intevation.flys.artifacts.MainValuesArtifact; | 14 import de.intevation.flys.artifacts.MainValuesArtifact; |
15 import de.intevation.flys.artifacts.math.Linear; | |
12 import de.intevation.flys.artifacts.model.FacetTypes; | 16 import de.intevation.flys.artifacts.model.FacetTypes; |
17 import de.intevation.flys.artifacts.model.WQDay; | |
13 import de.intevation.flys.jfree.FLYSAnnotation; | 18 import de.intevation.flys.jfree.FLYSAnnotation; |
14 import de.intevation.flys.jfree.StickyAxisAnnotation; | 19 import de.intevation.flys.jfree.StickyAxisAnnotation; |
15 | 20 |
16 import de.intevation.flys.exports.DurationCurveGenerator; | 21 import de.intevation.flys.exports.DurationCurveGenerator; |
22 | |
17 | 23 |
18 /** | 24 /** |
19 * Facet to show Main Q Values. | 25 * Facet to show Main Q Values. |
20 * TODO Join with W implementation. | 26 * TODO Join with W implementation. |
21 */ | 27 */ |
22 public class MainValuesQFacet | 28 public class MainValuesQFacet |
23 extends DefaultFacet | 29 extends DefaultFacet |
24 implements FacetTypes { | 30 implements FacetTypes { |
31 | |
32 /** Own logger. */ | |
33 private static Logger logger = Logger.getLogger(RelativePointFacet.class); | |
25 | 34 |
26 /** Do we want MainValues at Gauge (not interpolated)? */ | 35 /** Do we want MainValues at Gauge (not interpolated)? */ |
27 protected boolean isAtGauge; | 36 protected boolean isAtGauge; |
28 | 37 |
29 /** Trivial Constructor. */ | 38 /** Trivial Constructor. */ |
30 public MainValuesQFacet(String name, String description, boolean atGauge) { | 39 public MainValuesQFacet(String name, String description, boolean atGauge) { |
31 this.description = description; | 40 this.description = description; |
32 this.name = name; | 41 this.name = name; |
33 this.index = 0; | 42 this.index = 0; |
34 this.isAtGauge = atGauge; | 43 this.isAtGauge = atGauge; |
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 } | |
35 } | 77 } |
36 | 78 |
37 | 79 |
38 /** | 80 /** |
39 * Returns the data this facet requires. | 81 * Returns the data this facet requires. |
48 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact; | 90 MainValuesArtifact mvArtifact = (MainValuesArtifact) artifact; |
49 | 91 |
50 List<NamedDouble> qs = mvArtifact.getMainValuesQ(isAtGauge); | 92 List<NamedDouble> qs = mvArtifact.getMainValuesQ(isAtGauge); |
51 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); | 93 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); |
52 | 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 | |
53 // Rather specific case, Q-Annotations at a maybe second yaxis. | 108 // Rather specific case, Q-Annotations at a maybe second yaxis. |
109 StickyAxisAnnotation annotation = null; | |
54 if (this.name.equals(DURATION_MAINVALUES_Q)) { | 110 if (this.name.equals(DURATION_MAINVALUES_Q)) { |
55 for (NamedDouble q: qs) { | 111 for (NamedDouble q: qs) { |
56 xy.add(new StickyAxisAnnotation( | 112 annotation = |
57 q.getName(), | 113 new StickyAxisAnnotation( |
58 (float) q.getValue(), | 114 q.getName(), |
59 StickyAxisAnnotation.SimpleAxis.Y_AXIS, | 115 (float) q.getValue(), |
60 DurationCurveGenerator.YAXIS.Q.idx)); | 116 StickyAxisAnnotation.SimpleAxis.Y_AXIS, |
117 DurationCurveGenerator.YAXIS.Q.idx); | |
118 xy.add(annotation); | |
119 if (wqdays != null) { | |
120 setHitPoint(wqdays, annotation); | |
121 } | |
61 } | 122 } |
62 } | 123 } |
63 else { | 124 else { |
64 for (NamedDouble q: qs) { | 125 for (NamedDouble q: qs) { |
65 xy.add(new StickyAxisAnnotation( | 126 annotation = |
66 q.getName(), | 127 new StickyAxisAnnotation( |
67 (float) q.getValue(), | 128 q.getName(), |
68 StickyAxisAnnotation.SimpleAxis.X_AXIS)); | 129 (float) q.getValue(), |
130 StickyAxisAnnotation.SimpleAxis.X_AXIS); | |
131 xy.add(annotation); | |
132 if (wqdays != null) { | |
133 setHitPoint(wqdays, annotation); | |
134 } | |
69 } | 135 } |
70 } | 136 } |
71 | 137 |
72 return new FLYSAnnotation(description, xy); | 138 return new FLYSAnnotation(description, xy); |
73 } | 139 } |