Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveFacet.java @ 9265:e5367900dd6d
Small cleanup concerning getPoints
Adding validStations as dataItem to flood duration calculation
Flood duration now km aware
author | gernotbelger |
---|---|
date | Tue, 17 Jul 2018 19:48:28 +0200 |
parents | ef7b65576d4b |
children | 465347d12990 |
rev | line source |
---|---|
9252 | 1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts.sinfo.flood_duration; | |
10 | |
9265 | 11 import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; |
9252 | 12 |
13 import org.apache.log4j.Logger; | |
14 import org.dive4elements.artifactdatabase.state.DefaultFacet; | |
15 import org.dive4elements.artifactdatabase.state.Facet; | |
16 import org.dive4elements.artifacts.Artifact; | |
17 import org.dive4elements.artifacts.CallContext; | |
18 import org.dive4elements.river.artifacts.D4EArtifact; | |
19 import org.dive4elements.river.artifacts.model.CalculationResult; | |
20 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | |
21 | |
22 | |
23 /** | |
24 * Data of a duration curve. | |
25 */ | |
26 public class FloodDurationCurveFacet extends DefaultFacet { | |
27 | |
28 private static Logger log = Logger.getLogger(FloodDurationCurveFacet.class); | |
29 | |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
30 // /** Blackboard data provider key for durationcurve (wqday) data. */ |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
31 // public static String BB_DURATIONCURVE = "durationcurve"; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
32 // |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
33 // /** Blackboard data provider key for km of durationcurve. */ |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
34 // public static String BB_DURATIONCURVE_KM = "durationcurve.km"; |
9252 | 35 |
36 public FloodDurationCurveFacet() { | |
37 } | |
38 | |
39 public FloodDurationCurveFacet(final String name, final String description) { | |
40 super(0, name, description); | |
41 } | |
42 | |
43 | |
44 /** | |
45 * Expose state computation from SINFOArtifact. | |
46 */ | |
47 @Override | |
48 public Object getData(final Artifact artifact, final CallContext context) { | |
49 | |
50 log.debug("Get data for flood duration curve data"); | |
51 | |
52 final D4EArtifact flys = (D4EArtifact) artifact; | |
53 | |
54 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); | |
55 | |
56 final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData(); | |
57 | |
9265 | 58 final double currentKm = getCurrentKm(context); |
59 // TODO: entweder in data.getDurationCurve() reingeben, oder bei FloodDurationCalculationResults auswerten... | |
60 // TODO: was ist aus perfromanz/speicher-sicht besser? | |
61 | |
9252 | 62 return data.getDurationCurve(); |
9265 | 63 } |
64 | |
65 /** | |
66 * Returns the current km from the context. | |
67 * If the context is null or doesn't contain a currentKm | |
68 * then a double value of -1 will be returned. | |
69 * | |
70 * @param context | |
71 * The CallContext instance | |
72 * @return the current km as double | |
73 */ | |
74 // FIXME: copied from org.dive4elements.river.artifacts.model.fixings.FixingsFacet | |
75 private double getCurrentKm(final CallContext context) { | |
76 if (context == null) | |
77 return Double.NaN; | |
78 | |
79 final Double dkm = (Double) context.getContextValue(CURRENT_KM); | |
80 if (dkm == null) | |
81 return Double.NaN; | |
82 | |
83 return dkm.doubleValue(); | |
9252 | 84 } |
85 | |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
86 // private WQDay getTestData() { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
87 // final int[] days = new int[366]; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
88 // final double[] ws = new double[366]; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
89 // final double[] qs = new double[366]; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
90 // for (int i = 0; i <= 365; i++) { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
91 // days[i] = i; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
92 // final double x = (i - 182.5) / 182.5; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
93 // ws[i] = 102.0 - (Math.pow(x, 5) + x); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
94 // qs[i] = 1600.0 - 800 * (Math.pow(x, 9) + x); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
95 // } |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
96 // return new WQDay(days, ws, qs); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
97 // } |
9252 | 98 |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
99 // @Override |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
100 // public List getStaticDataProviderKeys(final Artifact art) { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
101 // final List list = new ArrayList(); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
102 // list.add(BB_DURATIONCURVE); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
103 // list.add(BB_DURATIONCURVE_KM); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
104 // return list; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
105 // } |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
106 |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
107 |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
108 // /** |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
109 // * Can provide whatever getData returns and additionally the location. |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
110 // * @param key will respond on BB_DURATIONCURVE +KM |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
111 // * @param param ignored |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
112 // * @param context ignored |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
113 // * @return whatever getData delivers or location. |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
114 // */ |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
115 // @Override |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
116 // public Object provideBlackboardData(final Artifact artifact, |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
117 // final Object key, |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
118 // final Object param, |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
119 // final CallContext context |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
120 // ) { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
121 // if (key.equals(BB_DURATIONCURVE)) { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
122 // return getData(artifact, context); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
123 // } |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
124 // else if (key.equals(BB_DURATIONCURVE_KM)) { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
125 // return ((D4EArtifact)artifact).getDataAsString("ld_locations"); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
126 // } |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
127 // else { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
128 // return null; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
129 // } |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
130 // } |
9252 | 131 |
132 | |
133 /** Create a deep copy. */ | |
134 @Override | |
135 public Facet deepCopy() { | |
136 final FloodDurationCurveFacet copy = new FloodDurationCurveFacet(); | |
137 copy.set(this); | |
138 return copy; | |
139 } | |
140 } | |
141 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |