comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java @ 2758:b05faaa9099b

Create points for ref.curve in facet, handle these in generator. flys-artifacts/trunk@4493 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 24 May 2012 04:41:57 +0000
parents 94c6f4ad9b98
children 23b4ff116015
comparison
equal deleted inserted replaced
2757:6e89147f5ca3 2758:b05faaa9099b
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.math.Linear;
14 import de.intevation.flys.artifacts.model.FacetTypes; 14 import de.intevation.flys.artifacts.model.FacetTypes;
15 import de.intevation.flys.artifacts.model.RelativePointFacet; 15 import de.intevation.flys.artifacts.model.DurationCurveFacet;
16 import de.intevation.flys.artifacts.model.ReferenceCurveFacet;
16 import de.intevation.flys.artifacts.model.WQDay; 17 import de.intevation.flys.artifacts.model.WQDay;
17 18
18 /** 19 /**
19 * Facet to access a point. 20 * Facet to access a point.
20 */ 21 */
35 this.description = description; 36 this.description = description;
36 this.index = 0; 37 this.index = 0;
37 } 38 }
38 39
39 40
40 /** 41 protected Point2D calculateDurationCurvePoint(CallContext context,
41 * Returns the data this facet requires. 42 StaticWKmsArtifact artifact)
42 * 43 {
43 * @param artifact the owner artifact.
44 * @param context the CallContext (ignored).
45 *
46 * @return the data.
47 */
48 @Override
49 public Object getData(Artifact artifact, CallContext context) {
50 // Find out whether we live in a duration curve context, there we would
51 // provide only a single point.
52 Object wqdays = null; 44 Object wqdays = null;
53 double km = 0d; 45 double km = 0d;
54 List<DataProvider> providers = context. 46 List<DataProvider> providers = context.
55 getDataProvider("durationcurve"); 47 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE);
56 if (providers.size() < 1) { 48 if (providers.size() < 1) {
57 logger.warn("Could not find durationcurve data provider."); 49 logger.warn("Could not find durationcurve data provider.");
58 } 50 }
59 else { 51 else {
60 wqdays = providers.get(0).provideData( 52 wqdays = providers.get(0).provideData(
74 null, 66 null,
75 context).toString(); 67 context).toString();
76 km = Double.valueOf(dckm); 68 km = Double.valueOf(dckm);
77 } 69 }
78 70
79 StaticWKmsArtifact staticData =
80 (StaticWKmsArtifact) artifact;
81
82 if (wqdays != null) { 71 if (wqdays != null) {
83 // Which W at this km? 72 // Which W at this km?
84 double w = staticData.getWAtKmLin(staticData.getWKms(0), km); 73 double w = artifact.getWAtKmLin(artifact.getWKms(0), km);
85 if (w == -1) { 74 if (w == -1) {
86 logger.warn("w is -1, already bad sign!"); 75 logger.warn("w is -1, already bad sign!");
87 } 76 }
88 // Where is this W passed by in the wq-curve? 77 // Where is this W passed by in the wq-curve?
89 WQDay wqday = (WQDay) wqdays; 78 WQDay wqday = (WQDay) wqdays;
110 } 99 }
111 100
112 return new Point2D.Double((double) day, w); 101 return new Point2D.Double((double) day, w);
113 } 102 }
114 logger.warn("not wqkms / w / day found"); 103 logger.warn("not wqkms / w / day found");
115 104 // TODO better signal failure.
105 return new Point2D.Double(0d, 0d);
106 //return null;
107 }
108
109
110 /**
111 * Calculate a reference curve point, that is, a point made of
112 * the Ws from start and end km param of the reference curve.
113 */
114 public Point2D calculateReferenceCurvePoint(CallContext context,
115 StaticWKmsArtifact artifact) {
116 List<DataProvider> providers = context.
117 getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM);
118 if (providers.size() < 1) {
119 logger.warn("Could not find reference curve startkm data provider.");
120 }
121
122 Double start = (Double) providers.get(0).
123 provideData(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM, null, context);
124
125 providers = context.
126 getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS);
127 if (providers.size() < 1) {
128 logger.warn("Could not find reference curve endkms data provider.");
129 }
130 double[] ends = (double[]) providers.get(0).
131 provideData(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS, null, context);
132
133 logger.debug("Got s " + start + " e " + ends);
134 double startW = artifact.getWAtKmLin(artifact.getWKms(0), start.doubleValue());
135 // TODO handle multiple ends.
136 double endW = artifact.getWAtKmLin(artifact.getWKms(0), ends[0]);
137 logger.debug("Gotw s " + startW + " e " + endW);
138 return new Point2D.Double(startW, endW);
139 }
140
141
142 /**
143 * Returns the data this facet requires.
144 *
145 * @param artifact the owner artifact.
146 * @param context the CallContext (ignored).
147 *
148 * @return the data.
149 */
150 @Override
151 public Object getData(Artifact artifact, CallContext context) {
152 StaticWKmsArtifact staticData = (StaticWKmsArtifact) artifact;
153 // Find out whether we live in a duration curve context, there we would
154 // provide only a single point.
155
156 if (context.getDataProvider(
157 DurationCurveFacet.BB_DURATIONCURVE_KM).size() > 0) {
158 return calculateDurationCurvePoint(context, staticData);
159 }
160 else if (context.getDataProvider(
161 ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM).size() > 0) {
162 return calculateReferenceCurvePoint(context, staticData);
163 }
164
116 // TODO better signal failure. 165 // TODO better signal failure.
117 return new Point2D.Double(0d, 0d); 166 return new Point2D.Double(0d, 0d);
118 } 167 }
119 168
120 169

http://dive4elements.wald.intevation.org