Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveFacet.java @ 9266:465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
author | mschaefer |
---|---|
date | Wed, 18 Jul 2018 12:20:01 +0200 |
parents | e5367900dd6d |
children | ae9dee74e43e |
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; | |
9266
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9265
diff
changeset
|
20 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
9252 | 21 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; |
22 | |
23 | |
24 /** | |
25 * Data of a duration curve. | |
26 */ | |
27 public class FloodDurationCurveFacet extends DefaultFacet { | |
28 | |
29 private static Logger log = Logger.getLogger(FloodDurationCurveFacet.class); | |
30 | |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
31 // /** 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
|
32 // 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
|
33 // |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
34 // /** 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
|
35 // public static String BB_DURATIONCURVE_KM = "durationcurve.km"; |
9252 | 36 |
37 public FloodDurationCurveFacet() { | |
38 } | |
39 | |
40 public FloodDurationCurveFacet(final String name, final String description) { | |
41 super(0, name, description); | |
42 } | |
43 | |
44 | |
45 /** | |
46 * Expose state computation from SINFOArtifact. | |
47 */ | |
48 @Override | |
49 public Object getData(final Artifact artifact, final CallContext context) { | |
50 | |
51 log.debug("Get data for flood duration curve data"); | |
52 | |
53 final D4EArtifact flys = (D4EArtifact) artifact; | |
54 | |
55 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); | |
56 | |
57 final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData(); | |
58 | |
9265 | 59 final double currentKm = getCurrentKm(context); |
60 // TODO: entweder in data.getDurationCurve() reingeben, oder bei FloodDurationCalculationResults auswerten... | |
61 // TODO: was ist aus perfromanz/speicher-sicht besser? | |
62 | |
9266
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9265
diff
changeset
|
63 // return data.getDurationCurve(); |
465347d12990
Station specific calculation of flood duration curve and infrastructure annotations
mschaefer
parents:
9265
diff
changeset
|
64 return new FloodDurationCalculation(context).calcStationCurve(currentKm, (SINFOArtifact) flys); |
9265 | 65 } |
66 | |
67 /** | |
68 * Returns the current km from the context. | |
69 * If the context is null or doesn't contain a currentKm | |
70 * then a double value of -1 will be returned. | |
71 * | |
72 * @param context | |
73 * The CallContext instance | |
74 * @return the current km as double | |
75 */ | |
76 // FIXME: copied from org.dive4elements.river.artifacts.model.fixings.FixingsFacet | |
77 private double getCurrentKm(final CallContext context) { | |
78 if (context == null) | |
79 return Double.NaN; | |
80 | |
81 final Double dkm = (Double) context.getContextValue(CURRENT_KM); | |
82 if (dkm == null) | |
83 return Double.NaN; | |
84 | |
85 return dkm.doubleValue(); | |
9252 | 86 } |
87 | |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
88 // private WQDay getTestData() { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
89 // 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
|
90 // 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
|
91 // 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
|
92 // 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
|
93 // days[i] = i; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
94 // 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
|
95 // 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
|
96 // 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
|
97 // } |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
98 // 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
|
99 // } |
9252 | 100 |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
101 // @Override |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
102 // 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
|
103 // final List list = new ArrayList(); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
104 // list.add(BB_DURATIONCURVE); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
105 // list.add(BB_DURATIONCURVE_KM); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
106 // return list; |
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 |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
110 // /** |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
111 // * 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
|
112 // * @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
|
113 // * @param param ignored |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
114 // * @param context ignored |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
115 // * @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
|
116 // */ |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
117 // @Override |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
118 // 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
|
119 // final Object key, |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
120 // final Object param, |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
121 // final CallContext context |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
122 // ) { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
123 // if (key.equals(BB_DURATIONCURVE)) { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
124 // return getData(artifact, context); |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
125 // } |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
126 // 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
|
127 // 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
|
128 // } |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
129 // else { |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
130 // return null; |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
131 // } |
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
132 // } |
9252 | 133 |
134 | |
135 /** Create a deep copy. */ | |
136 @Override | |
137 public Facet deepCopy() { | |
138 final FloodDurationCurveFacet copy = new FloodDurationCurveFacet(); | |
139 copy.set(this); | |
140 return copy; | |
141 } | |
142 } | |
143 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |