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 |
|
11 import java.util.ArrayList; |
|
12 import java.util.List; |
|
13 |
|
14 import org.apache.log4j.Logger; |
|
15 import org.dive4elements.artifactdatabase.state.DefaultFacet; |
|
16 import org.dive4elements.artifactdatabase.state.Facet; |
|
17 import org.dive4elements.artifacts.Artifact; |
|
18 import org.dive4elements.artifacts.CallContext; |
|
19 import org.dive4elements.river.artifacts.D4EArtifact; |
|
20 import org.dive4elements.river.artifacts.model.CalculationResult; |
|
21 import org.dive4elements.river.artifacts.model.WQDay; |
|
22 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; |
|
23 |
|
24 |
|
25 /** |
|
26 * Data of a duration curve. |
|
27 */ |
|
28 public class FloodDurationCurveFacet extends DefaultFacet { |
|
29 |
|
30 private static Logger log = Logger.getLogger(FloodDurationCurveFacet.class); |
|
31 |
|
32 /** Blackboard data provider key for durationcurve (wqday) data. */ |
|
33 public static String BB_DURATIONCURVE = "durationcurve"; |
|
34 |
|
35 /** Blackboard data provider key for km of durationcurve. */ |
|
36 public static String BB_DURATIONCURVE_KM = "durationcurve.km"; |
|
37 |
|
38 public FloodDurationCurveFacet() { |
|
39 } |
|
40 |
|
41 public FloodDurationCurveFacet(final String name, final String description) { |
|
42 super(0, name, description); |
|
43 } |
|
44 |
|
45 |
|
46 /** |
|
47 * Expose state computation from SINFOArtifact. |
|
48 */ |
|
49 @Override |
|
50 public Object getData(final Artifact artifact, final CallContext context) { |
|
51 |
|
52 log.debug("Get data for flood duration curve data"); |
|
53 |
|
54 final D4EArtifact flys = (D4EArtifact) artifact; |
|
55 |
|
56 final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); |
|
57 |
|
58 final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData(); |
|
59 |
|
60 return data.getDurationCurve(); |
|
61 // return getTestData(); |
|
62 } |
|
63 |
|
64 private WQDay getTestData() { |
|
65 final int[] days = new int[366]; |
|
66 final double[] ws = new double[366]; |
|
67 final double[] qs = new double[366]; |
|
68 for (int i = 0; i <= 365; i++) { |
|
69 days[i] = i; |
|
70 final double x = (i - 182.5) / 182.5; |
|
71 ws[i] = 102.0 - (Math.pow(x, 5) + x); |
|
72 qs[i] = 1600.0 - 800 * (Math.pow(x, 9) + x); |
|
73 } |
|
74 return new WQDay(days, ws, qs); |
|
75 } |
|
76 |
|
77 |
|
78 @Override |
|
79 public List getStaticDataProviderKeys(final Artifact art) { |
|
80 final List list = new ArrayList(); |
|
81 list.add(BB_DURATIONCURVE); |
|
82 list.add(BB_DURATIONCURVE_KM); |
|
83 return list; |
|
84 } |
|
85 |
|
86 |
|
87 /** |
|
88 * Can provide whatever getData returns and additionally the location. |
|
89 * @param key will respond on BB_DURATIONCURVE +KM |
|
90 * @param param ignored |
|
91 * @param context ignored |
|
92 * @return whatever getData delivers or location. |
|
93 */ |
|
94 @Override |
|
95 public Object provideBlackboardData(final Artifact artifact, |
|
96 final Object key, |
|
97 final Object param, |
|
98 final CallContext context |
|
99 ) { |
|
100 if (key.equals(BB_DURATIONCURVE)) { |
|
101 return getData(artifact, context); |
|
102 } |
|
103 else if (key.equals(BB_DURATIONCURVE_KM)) { |
|
104 return ((D4EArtifact)artifact).getDataAsString("ld_locations"); |
|
105 } |
|
106 else { |
|
107 return null; |
|
108 } |
|
109 } |
|
110 |
|
111 |
|
112 /** Create a deep copy. */ |
|
113 @Override |
|
114 public Facet deepCopy() { |
|
115 final FloodDurationCurveFacet copy = new FloodDurationCurveFacet(); |
|
116 copy.set(this); |
|
117 return copy; |
|
118 } |
|
119 } |
|
120 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |