Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/HistoricalDischargeComputeState.java @ 4241:49cb65d5932d
Improved the historical discharge calculation.
The calculation now creates new HistoricalWQKms (new subclass of WQKms). Those WQKms are used
to create new facets from (new) type 'HistoricalDischargeCurveFacet'. The chart generator is
improved to support those facets.
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 24 Oct 2012 14:34:35 +0200 |
parents | b3aa91e45010 |
children | 2c6e571f366a |
comparison
equal
deleted
inserted
replaced
4240:4774902b0389 | 4241:49cb65d5932d |
---|---|
14 import de.intevation.flys.artifacts.access.HistoricalDischargeAccess; | 14 import de.intevation.flys.artifacts.access.HistoricalDischargeAccess; |
15 import de.intevation.flys.artifacts.access.HistoricalDischargeAccess.EvaluationMode; | 15 import de.intevation.flys.artifacts.access.HistoricalDischargeAccess.EvaluationMode; |
16 import de.intevation.flys.artifacts.model.CalculationResult; | 16 import de.intevation.flys.artifacts.model.CalculationResult; |
17 import de.intevation.flys.artifacts.model.DataFacet; | 17 import de.intevation.flys.artifacts.model.DataFacet; |
18 import de.intevation.flys.artifacts.model.FacetTypes; | 18 import de.intevation.flys.artifacts.model.FacetTypes; |
19 import de.intevation.flys.artifacts.model.HistoricalDischargeCurveFacet; | |
20 import de.intevation.flys.artifacts.model.HistoricalDischargeData; | |
19 import de.intevation.flys.artifacts.model.HistoricalDischargeDifferenceFacet; | 21 import de.intevation.flys.artifacts.model.HistoricalDischargeDifferenceFacet; |
20 import de.intevation.flys.artifacts.model.HistoricalDischargeFacet; | 22 import de.intevation.flys.artifacts.model.HistoricalDischargeFacet; |
23 import de.intevation.flys.artifacts.model.HistoricalDischargeWQFacet; | |
24 import de.intevation.flys.artifacts.model.HistoricalWQKms; | |
21 import de.intevation.flys.artifacts.model.HistoricalWQTimerange; | 25 import de.intevation.flys.artifacts.model.HistoricalWQTimerange; |
22 import de.intevation.flys.artifacts.model.ReportFacet; | 26 import de.intevation.flys.artifacts.model.ReportFacet; |
27 import de.intevation.flys.artifacts.model.WQKms; | |
23 import de.intevation.flys.artifacts.model.WQTimerange; | 28 import de.intevation.flys.artifacts.model.WQTimerange; |
29 import de.intevation.flys.artifacts.resources.Resources; | |
30 import de.intevation.flys.model.TimeInterval; | |
24 | 31 |
25 | 32 |
26 /** | 33 /** |
27 * State to calculate historical discharge curves. | 34 * State to calculate historical discharge curves. |
28 * | 35 * |
33 | 40 |
34 private static final Logger logger = Logger | 41 private static final Logger logger = Logger |
35 .getLogger(HistoricalDischargeComputeState.class); | 42 .getLogger(HistoricalDischargeComputeState.class); |
36 | 43 |
37 public static final String DEFAULT_UNIT = "cm"; | 44 public static final String DEFAULT_UNIT = "cm"; |
45 public static final String I18N_WQ_CURVE_FACET_RANGE = "historical_discharge.wq.curve_range"; | |
46 public static final String I18N_WQ_CURVE_FACET_SINCE = "historical_discharge.wq.curve_since"; | |
38 | 47 |
39 @Override | 48 @Override |
40 protected void appendItems(Artifact artifact, ElementCreator creator, | 49 protected void appendItems(Artifact artifact, ElementCreator creator, |
41 String name, CallContext context, Element select) { | 50 String name, CallContext context, Element select) { |
42 // TODO IMPLEMENT ME | 51 // TODO IMPLEMENT ME |
58 | 67 |
59 if (res.getReport().hasProblems()) { | 68 if (res.getReport().hasProblems()) { |
60 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); | 69 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); |
61 } | 70 } |
62 | 71 |
63 WQTimerange[] data = (WQTimerange[]) res.getData(); | 72 HistoricalDischargeData data = (HistoricalDischargeData) res.getData(); |
64 if (data == null || data.length == 0) { | 73 HistoricalDischargeAccess access = new HistoricalDischargeAccess( |
65 logger.warn("Historical Discharge calculation has no results!"); | 74 artifact); |
66 return res; | 75 |
76 WQTimerange[] wqts = (WQTimerange[]) data.getWQTimeranges(); | |
77 if (wqts != null && wqts.length > 0) { | |
78 facets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, | |
79 hash, id)); | |
80 | |
81 facets.add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, | |
82 hash, id)); | |
83 | |
84 prepareFacets(facets, wqts, access); | |
67 } | 85 } |
68 | 86 |
69 facets | 87 WQKms[] wqs = (WQKms[]) data.getWQs(); |
70 .add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | 88 if (wqs != null && wqs.length > 0) { |
71 | 89 prepareWQFacets(context, facets, wqs, access, hash); |
72 facets | 90 } |
73 .add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, id)); | |
74 | |
75 prepareFacets(facets, data, new HistoricalDischargeAccess(artifact)); | |
76 | 91 |
77 return res; | 92 return res; |
78 } | 93 } |
79 | 94 |
80 protected void prepareFacets(List<Facet> facets, WQTimerange[] wqts, | 95 protected void prepareFacets(List<Facet> facets, WQTimerange[] wqts, |
114 | 129 |
115 i++; | 130 i++; |
116 } | 131 } |
117 } | 132 } |
118 | 133 |
134 protected void prepareWQFacets(CallContext cc, List<Facet> facets, | |
135 WQKms[] wqs, HistoricalDischargeAccess access, String hash) { | |
136 double[] ws = access.getWs(); | |
137 double[] qs = access.getQs(); | |
138 | |
139 for (int k = 0; k < ws.length; k++) { | |
140 facets.add(new HistoricalDischargeWQFacet( | |
141 HISTORICAL_DISCHARGE_WQ_W, "W=" + ws[k], ws[k])); | |
142 } | |
143 | |
144 for (int k = 0; k < qs.length; k++) { | |
145 facets.add(new HistoricalDischargeWQFacet( | |
146 HISTORICAL_DISCHARGE_WQ_W, "Q=" + ws[k], qs[k])); | |
147 } | |
148 | |
149 int idx = 0; | |
150 for (WQKms wqkms : wqs) { | |
151 String title = null; | |
152 if (wqkms instanceof HistoricalWQKms) { | |
153 title = createDischargeCurveTitle(cc, (HistoricalWQKms) wqkms); | |
154 } | |
155 else { | |
156 title = wqkms.getName(); | |
157 } | |
158 | |
159 facets.add(new HistoricalDischargeCurveFacet(idx, | |
160 HISTORICAL_DISCHARGE_WQ_CURVE, title, ComputeType.ADVANCE, | |
161 getID(), hash)); | |
162 idx++; | |
163 } | |
164 } | |
165 | |
166 protected String createDischargeCurveTitle(CallContext cc, | |
167 HistoricalWQKms wqkms) { | |
168 TimeInterval timeInterval = wqkms.getTimeInterval(); | |
169 | |
170 if (timeInterval.getStopTime() != null) { | |
171 return Resources.format(cc.getMeta(), I18N_WQ_CURVE_FACET_RANGE, | |
172 I18N_WQ_CURVE_FACET_RANGE, timeInterval.getStartTime(), | |
173 timeInterval.getStopTime()); | |
174 } | |
175 else { | |
176 return Resources.format(cc.getMeta(), I18N_WQ_CURVE_FACET_SINCE, | |
177 I18N_WQ_CURVE_FACET_SINCE, timeInterval.getStartTime()); | |
178 } | |
179 } | |
180 | |
119 protected String createFacetTitle(WQTimerange wqt) { | 181 protected String createFacetTitle(WQTimerange wqt) { |
120 String name = wqt.getName(); | 182 String name = wqt.getName(); |
121 | 183 |
122 return name != null && name.indexOf("W") >= 0 ? createFacetTitleW(wqt) | 184 return name != null && name.indexOf("W") >= 0 ? createFacetTitleW(wqt) |
123 : createFacetTitleQ(wqt); | 185 : createFacetTitleQ(wqt); |