annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/RelativePointFacet.java @ 7300:83bb52fa0c32

(issue1529) Be more tolerant in the fitting. The invalid value warning is removed because invalid data is expected there when datapoints are not valid for this KM
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 11 Oct 2013 18:40:33 +0200
parents af13ceeba52a
children e4606eae8ea5
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5797
diff changeset
9 package org.dive4elements.river.artifacts.model;
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
11 import java.util.List;
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
12 import java.awt.geom.Point2D;
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
13
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
14 import org.apache.log4j.Logger;
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
15
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5797
diff changeset
16 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5797
diff changeset
17 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5797
diff changeset
18 import org.dive4elements.artifacts.DataProvider;
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
19
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5797
diff changeset
20 import org.dive4elements.river.artifacts.StaticWKmsArtifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5797
diff changeset
21 import org.dive4elements.river.artifacts.StaticWQKmsArtifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5797
diff changeset
22 import org.dive4elements.river.artifacts.math.Linear;
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
24 /**
2747
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
25 * Facet to access a point.
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26 */
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
27 public class RelativePointFacet
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28 extends BlackboardDataFacet
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29 implements FacetTypes {
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
30
2999
703be13ffa74 Cosmetics and ommitted fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2760
diff changeset
31 /** Own logger. */
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32 private static Logger logger = Logger.getLogger(RelativePointFacet.class);
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
33
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
34 /** Trivial Constructor. */
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
35 public RelativePointFacet(String description) {
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36 this(RELATIVE_POINT, description);
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
37 }
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
38
2747
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
39
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
40 public RelativePointFacet(String name, String description) {
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
41 this.name = name;
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
42 this.description = description;
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43 this.index = 0;
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44 }
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
45
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
47 protected Point2D calculateDurationCurvePoint(CallContext context,
5797
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
48 WKms wKms)
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
49 {
2760
23b4ff116015 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2758
diff changeset
50 // TODO here and in reference curve calc: Do warn if more than 1
23b4ff116015 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2758
diff changeset
51 // provider found or (way better) handle it.
2747
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
52 Object wqdays = null;
3442
cd5eb8f5f6f1 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
53 double km = 0d;
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
54 List<DataProvider> providers = context.
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
55 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE);
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
56 if (providers.size() < 1) {
2747
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
57 logger.warn("Could not find durationcurve data provider.");
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
58 }
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
59 else {
2747
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
60 wqdays = providers.get(0).provideData(
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
61 DurationCurveFacet.BB_DURATIONCURVE,
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
62 null,
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
63 context);
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
64 }
2747
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
65 List<DataProvider> kmproviders = context.
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
66 getDataProvider(DurationCurveFacet.BB_DURATIONCURVE_KM);
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
67 if (kmproviders.size() < 1) {
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
68 logger.warn("Could not find durationcurve.km data provider.");
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
69 }
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
70 else {
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
71 logger.debug("Found durationcurve.km data provider.");
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
72 String dckm = providers.get(0).provideData(
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
73 DurationCurveFacet.BB_DURATIONCURVE_KM,
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
74 null,
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
75 context).toString();
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
76 km = Double.valueOf(dckm);
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
77 }
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
78
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
79 if (wqdays != null) {
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
80 // Which W at this km?
5797
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
81 double w = StaticWKmsArtifact.getWAtKmLin(wKms, km);
2747
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
82 if (w == -1) {
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
83 logger.warn("w is -1, already bad sign!");
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
84 }
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
85 // Where is this W passed by in the wq-curve?
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
86 WQDay wqday = (WQDay) wqdays;
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
87 // Doing a linear Day Of KM.
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
88 int idx = 0;
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
89 boolean wIncreases = wqday.getW(0) < wqday.getW(wqday.size()-1);
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
90 if (wIncreases) {
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
91 while (idx < wqday.size() && wqday.getW(idx) < w) {
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
92 idx++;
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
93 }
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
94 }
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
95 else {
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
96 idx = wqday.size() -1;
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
97 while (idx > 0 && wqday.getW(idx) > w) {
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
98 idx--;
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
99 }
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
100 }
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
101
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
102 double day = 0d;
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
103 int mod = (wIncreases) ? -1 : +1;
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
104 if (idx != 0 && idx <= wqday.size()-1) {
3442
cd5eb8f5f6f1 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
105 day = Linear.linear(w, wqday.getW(idx+mod), wqday.getW(idx),
2747
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
106 wqday.getDay(idx+mod), wqday.getDay(idx));
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
107 }
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
108
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
109 return new Point2D.Double((double) day, w);
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
110 }
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
111 logger.warn("not wqkms / w / day found");
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
112 // TODO better signal failure.
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
113 return new Point2D.Double(0d, 0d);
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
114 }
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
115
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
116
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
117 /**
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
118 * Calculate a reference curve point, that is, a point made of
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
119 * the Ws from start and end km param of the reference curve.
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
120 */
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
121 public Point2D calculateReferenceCurvePoint(CallContext context,
5797
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
122 WKms wKms) {
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
123
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
124 List<DataProvider> providers = context.
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
125 getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM);
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
126 if (providers.size() < 1) {
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
127 logger.warn("Could not find reference curve startkm data provider.");
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
128 }
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
129
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
130 Double start = (Double) providers.get(0).
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
131 provideData(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM, null, context);
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
132
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
133 providers = context.
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
134 getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS);
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
135 if (providers.size() < 1) {
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
136 logger.warn("Could not find reference curve endkms data provider.");
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
137 }
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
138 double[] ends = (double[]) providers.get(0).
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
139 provideData(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS, null, context);
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
140
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
141 logger.debug("Got s " + start + " e " + ends);
5797
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
142
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
143 double startW = StaticWKmsArtifact.getWAtKmLin(wKms, start.doubleValue());
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
144 // TODO handle multiple ends.
5797
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
145 double endW = StaticWKmsArtifact.getWAtKmLin(wKms, ends[0]);
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
146 logger.debug("Gotw s " + startW + " e " + endW);
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
147 return new Point2D.Double(startW, endW);
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
148 }
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
149
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
150
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
151 /**
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
152 * Returns the data this facet requires.
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
153 *
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
154 * @param artifact the owner artifact.
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
155 * @param context the CallContext (ignored).
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
156 *
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
157 * @return the data.
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
158 */
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
159 @Override
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
160 public Object getData(Artifact artifact, CallContext context) {
5797
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
161 WKms wKms = null;
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
162 if (artifact instanceof StaticWKmsArtifact) {
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
163 wKms = ((StaticWKmsArtifact) artifact).getWKms(0);
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
164 }
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
165 else if (artifact instanceof StaticWQKmsArtifact) {
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
166 wKms = ((StaticWQKmsArtifact) artifact).getWQKms();
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
167 }
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
168 else {
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
169 logger.error("Cannot handle Artifact to create relative point.");
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
170 return null;
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
171 }
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
172
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
173 // Find out whether we live in a duration curve context, there we would
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
174 // provide only a single point.
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
175
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
176 if (context.getDataProvider(
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
177 DurationCurveFacet.BB_DURATIONCURVE_KM).size() > 0) {
5797
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
178 return calculateDurationCurvePoint(context, wKms);
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
179 }
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
180 else if (context.getDataProvider(
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
181 ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM).size() > 0) {
5797
cce12c06466f RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3442
diff changeset
182 return calculateReferenceCurvePoint(context, wKms);
2758
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
183 }
b05faaa9099b Create points for ref.curve in facet, handle these in generator.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2747
diff changeset
184
2747
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
185 // TODO better signal failure.
94c6f4ad9b98 Handle case of points in wqday (durationcurve) scenarios.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2743
diff changeset
186 return new Point2D.Double(0d, 0d);
2743
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
187 }
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
188
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
189
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
190 /**
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
191 * Create a deep copy of this Facet.
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
192 * @return a deep copy.
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
193 */
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
194 @Override
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
195 public RelativePointFacet deepCopy() {
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
196 RelativePointFacet copy = new RelativePointFacet(description);
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
197 copy.set(this);
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
198 return copy;
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
199 }
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
200 }
10e6400d4166 Added (dummy-) implementation of relative point facet in staticwkms case.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
201 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org