Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java @ 2747:94c6f4ad9b98
Handle case of points in wqday (durationcurve) scenarios.
flys-artifacts/trunk@4482 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 23 May 2012 20:39:18 +0000 |
parents | 10e6400d4166 |
children | b05faaa9099b |
comparison
equal
deleted
inserted
replaced
2746:4634cf5574f7 | 2747:94c6f4ad9b98 |
---|---|
8 import de.intevation.artifacts.Artifact; | 8 import de.intevation.artifacts.Artifact; |
9 import de.intevation.artifacts.CallContext; | 9 import de.intevation.artifacts.CallContext; |
10 import de.intevation.artifacts.DataProvider; | 10 import de.intevation.artifacts.DataProvider; |
11 | 11 |
12 import de.intevation.flys.artifacts.StaticWKmsArtifact; | 12 import de.intevation.flys.artifacts.StaticWKmsArtifact; |
13 import de.intevation.flys.artifacts.math.Linear; | |
13 import de.intevation.flys.artifacts.model.FacetTypes; | 14 import de.intevation.flys.artifacts.model.FacetTypes; |
15 import de.intevation.flys.artifacts.model.RelativePointFacet; | |
16 import de.intevation.flys.artifacts.model.WQDay; | |
14 | 17 |
15 /** | 18 /** |
16 * Facet to access a point | 19 * Facet to access a point. |
17 */ | 20 */ |
18 public class RelativePointFacet | 21 public class RelativePointFacet |
19 extends BlackboardDataFacet | 22 extends BlackboardDataFacet |
20 implements FacetTypes { | 23 implements FacetTypes { |
21 | 24 |
23 | 26 |
24 /** Trivial Constructor. */ | 27 /** Trivial Constructor. */ |
25 public RelativePointFacet(String description) { | 28 public RelativePointFacet(String description) { |
26 this(RELATIVE_POINT, description); | 29 this(RELATIVE_POINT, description); |
27 } | 30 } |
31 | |
28 | 32 |
29 public RelativePointFacet(String name, String description) { | 33 public RelativePointFacet(String name, String description) { |
30 this.name = name; | 34 this.name = name; |
31 this.description = description; | 35 this.description = description; |
32 this.index = 0; | 36 this.index = 0; |
41 * | 45 * |
42 * @return the data. | 46 * @return the data. |
43 */ | 47 */ |
44 @Override | 48 @Override |
45 public Object getData(Artifact artifact, CallContext context) { | 49 public Object getData(Artifact artifact, CallContext context) { |
46 /* CrossSectionWaterLineFacet: | |
47 List<DataProvider> providers = context. | |
48 getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); | |
49 if (providers.size() < 1) { | |
50 logger.warn("Could not find Cross-Section data provider."); | |
51 return new Lines.LineData(new double[][] {}, 0d, 0d); | |
52 } | |
53 | |
54 Object crossSection = providers.get(0) | |
55 .provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, null, context); | |
56 | |
57 WaterLineArtifact winfo = (WaterLineArtifact)artifact; | |
58 */ | |
59 // Find out whether we live in a duration curve context, there we would | 50 // Find out whether we live in a duration curve context, there we would |
60 // provide only a single point. | 51 // provide only a single point. |
52 Object wqdays = null; | |
53 double km = 0d; | |
61 List<DataProvider> providers = context. | 54 List<DataProvider> providers = context. |
62 getDataProvider("durationcurve"); | 55 getDataProvider("durationcurve"); |
63 if (providers.size() < 1) { | 56 if (providers.size() < 1) { |
64 logger.debug("Could not find durationcurve data provider."); | 57 logger.warn("Could not find durationcurve data provider."); |
65 //return new Lines.LineData(new double[][] {}, 0d, 0d); | |
66 } | 58 } |
67 else { | 59 else { |
68 Object crossSection = providers.get(0) | 60 wqdays = providers.get(0).provideData( |
69 .provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, null, context); | 61 DurationCurveFacet.BB_DURATIONCURVE, |
70 | 62 null, |
63 context); | |
71 } | 64 } |
72 | 65 List<DataProvider> kmproviders = context. |
66 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE_KM); | |
67 if (kmproviders.size() < 1) { | |
68 logger.warn("Could not find durationcurve.km data provider."); | |
69 } | |
70 else { | |
71 logger.debug("Found durationcurve.km data provider."); | |
72 String dckm = providers.get(0).provideData( | |
73 DurationCurveFacet.BB_DURATIONCURVE_KM, | |
74 null, | |
75 context).toString(); | |
76 km = Double.valueOf(dckm); | |
77 } | |
78 | |
73 StaticWKmsArtifact staticData = | 79 StaticWKmsArtifact staticData = |
74 (StaticWKmsArtifact) artifact; | 80 (StaticWKmsArtifact) artifact; |
75 //return staticData.getWKms(0); | 81 |
76 return new Point2D.Double(10d,180d); | 82 if (wqdays != null) { |
83 // Which W at this km? | |
84 double w = staticData.getWAtKmLin(staticData.getWKms(0), km); | |
85 if (w == -1) { | |
86 logger.warn("w is -1, already bad sign!"); | |
87 } | |
88 // Where is this W passed by in the wq-curve? | |
89 WQDay wqday = (WQDay) wqdays; | |
90 // Doing a linear Day Of KM. | |
91 int idx = 0; | |
92 boolean wIncreases = wqday.getW(0) < wqday.getW(wqday.size()-1); | |
93 if (wIncreases) { | |
94 while (idx < wqday.size() && wqday.getW(idx) < w) { | |
95 idx++; | |
96 } | |
97 } | |
98 else { | |
99 idx = wqday.size() -1; | |
100 while (idx > 0 && wqday.getW(idx) > w) { | |
101 idx--; | |
102 } | |
103 } | |
104 | |
105 double day = 0d; | |
106 int mod = (wIncreases) ? -1 : +1; | |
107 if (idx != 0 && idx <= wqday.size()-1) { | |
108 day = Linear.linear(w, wqday.getW(idx +mod), wqday.getW(idx), | |
109 wqday.getDay(idx+mod), wqday.getDay(idx)); | |
110 } | |
111 | |
112 return new Point2D.Double((double) day, w); | |
113 } | |
114 logger.warn("not wqkms / w / day found"); | |
115 | |
116 // TODO better signal failure. | |
117 return new Point2D.Double(0d, 0d); | |
77 } | 118 } |
78 | 119 |
79 | 120 |
80 /** | 121 /** |
81 * Create a deep copy of this Facet. | 122 * Create a deep copy of this Facet. |