Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstState.java @ 9313:6ffcbb4f35d5
bundu.bezugswst first result stump
author | gernotbelger |
---|---|
date | Thu, 26 Jul 2018 15:58:08 +0200 |
parents | 1c8eeaf6031f |
children | 7b2b086e45f0 |
comparison
equal
deleted
inserted
replaced
9312:740d65e4aa14 | 9313:6ffcbb4f35d5 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.bundu.bezugswst; | 9 package org.dive4elements.river.artifacts.bundu.bezugswst; |
10 | 10 |
11 import java.text.DateFormat; | |
12 import java.util.Collection; | |
13 import java.util.Date; | |
14 import java.util.List; | 11 import java.util.List; |
15 | 12 |
16 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
17 import org.dive4elements.artifactdatabase.state.Facet; | 14 import org.dive4elements.artifactdatabase.state.Facet; |
18 import org.dive4elements.artifacts.CallContext; | 15 import org.dive4elements.artifacts.CallContext; |
19 import org.dive4elements.artifacts.CallMeta; | |
20 import org.dive4elements.river.artifacts.D4EArtifact; | 16 import org.dive4elements.river.artifacts.D4EArtifact; |
21 import org.dive4elements.river.artifacts.access.FixRealizingAccess; | 17 import org.dive4elements.river.artifacts.bundu.BUNDUArtifact; |
22 import org.dive4elements.river.artifacts.model.CalculationResult; | 18 import org.dive4elements.river.artifacts.model.CalculationResult; |
23 import org.dive4elements.river.artifacts.model.CrossSectionWaterLineFacet; | |
24 import org.dive4elements.river.artifacts.model.DataFacet; | 19 import org.dive4elements.river.artifacts.model.DataFacet; |
25 import org.dive4elements.river.artifacts.model.FacetTypes; | 20 import org.dive4elements.river.artifacts.model.FacetTypes; |
26 import org.dive4elements.river.artifacts.model.ReportFacet; | |
27 import org.dive4elements.river.artifacts.model.WQCKms; | |
28 import org.dive4elements.river.artifacts.model.WQKms; | |
29 import org.dive4elements.river.artifacts.model.fixings.FixOutlierFacet; | |
30 import org.dive4elements.river.artifacts.model.fixings.FixRealizingCalculation; | |
31 import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult; | |
32 import org.dive4elements.river.artifacts.model.fixings.FixReferenceEventsFacet; | |
33 import org.dive4elements.river.artifacts.model.fixings.FixWQCurveFacet; | |
34 import org.dive4elements.river.artifacts.model.fixings.FixWaterlevelFacet; | |
35 import org.dive4elements.river.artifacts.resources.Resources; | |
36 import org.dive4elements.river.artifacts.states.DefaultState; | 21 import org.dive4elements.river.artifacts.states.DefaultState; |
37 import org.dive4elements.river.utils.Formatter; | |
38 import org.dive4elements.river.utils.UniqueDateFormatter; | |
39 | 22 |
40 /** | 23 /** |
41 * State to compute the fixation realizing (vollmer) results. | 24 * State to compute the fixation realizing (vollmer) results. |
42 * | 25 * |
43 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
75 | 58 |
76 @Override | 59 @Override |
77 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | 60 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
78 log.debug("BezugswstState.computeAdvance"); | 61 log.debug("BezugswstState.computeAdvance"); |
79 | 62 |
80 CalculationResult res; | 63 // final CalculationResult res; |
64 // | |
65 // final FixRealizingAccess access = new FixRealizingAccess(artifact); | |
66 // | |
67 // if (old instanceof CalculationResult) { | |
68 // res = (CalculationResult) old; | |
69 // } else { | |
70 // | |
71 // final FixRealizingCalculation calc = new FixRealizingCalculation(access); | |
72 // res = calc.calculate(); | |
73 // } | |
74 // | |
75 // if (facets == null) { | |
76 // return res; | |
77 // } | |
78 // | |
79 // if (res.getReport().hasProblems()) { | |
80 // facets.add(new ReportFacet()); | |
81 // } | |
82 // | |
83 // final String id = getID(); | |
84 // final CallMeta meta = context.getMeta(); | |
85 // | |
86 // final FixRealizingResult fixRes = (FixRealizingResult) res.getData(); | |
87 // final WQKms[] wqkms = fixRes != null ? fixRes.getWQKms() : new WQKms[0]; | |
88 // | |
89 // for (int i = 0; i < wqkms.length; i++) { | |
90 // String nameW = null; | |
91 // String nameQ = null; | |
92 // | |
93 // if (access.isQ()) { | |
94 // nameQ = wqkms[i].getName(); | |
95 // nameW = "W(" + nameQ + ")"; | |
96 // } else { | |
97 // nameW = wqkms[i].getName(); | |
98 // nameQ = "Q(" + nameW + ")"; | |
99 // } | |
100 // | |
101 // final Facet wq = new FixWaterlevelFacet(i, FIX_WQ_LS, nameW, ComputeType.ADVANCE, hash, id); | |
102 // | |
103 // final Facet w = new FixWaterlevelFacet(i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, hash, id); | |
104 // | |
105 // final Facet q = new FixWaterlevelFacet(i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, hash, id); | |
106 // final Facet csFacet = new CrossSectionWaterLineFacet(i, nameW); | |
107 // | |
108 // facets.add(wq); | |
109 // facets.add(w); | |
110 // facets.add(q); | |
111 // facets.add(csFacet); | |
112 // | |
113 // // XXX: THIS CAN NOT HAPPEN! REMOVE IT! | |
114 // if (wqkms[i] instanceof WQCKms) { | |
115 // final String nameC = nameW.replace("benutzerdefiniert", "benutzerdefiniert [korrigiert]"); | |
116 // | |
117 // final Facet c = new FixWaterlevelFacet(i, DISCHARGE_LONGITUDINAL_C, nameC); | |
118 // | |
119 // facets.add(c); | |
120 // } | |
121 // } | |
122 // | |
123 // if (wqkms.length > 0) { | |
124 // final DateFormat df = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy"); | |
125 // final DateFormat lf = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy'T'HH:mm"); | |
126 // | |
127 // final Collection<Date> reds = fixRes.getReferenceEventsDates(); | |
128 // final UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, reds); | |
129 // | |
130 // int i = 0; | |
131 // for (final Date d : reds) { | |
132 // facets.add(new FixReferenceEventsFacet((1 << 9) | i, FIX_EVENTS, cf.format(d))); | |
133 // i++; | |
134 // } | |
135 // | |
136 // facets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | |
137 // | |
138 // facets.add(new DataFacet(WST, "WST data", ComputeType.ADVANCE, hash, id)); | |
139 // | |
140 // facets.add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, id)); | |
141 // } | |
142 // | |
143 // facets.add(new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, id)); | |
144 // | |
145 // facets.add(new FixWQCurveFacet(0, Resources.getMsg(meta, I18N_WQ_CURVE, I18N_WQ_CURVE) + " (" + access.getFunction() | |
146 // + ")")); | |
147 // | |
148 // if (access.getPreprocessing()) { | |
149 // facets.add(new FixOutlierFacet(0, FIX_OUTLIER, Resources.getMsg(meta, I18N_WQ_OUTLIER, I18N_WQ_OUTLIER))); | |
150 // } | |
151 return compute((BUNDUArtifact) artifact, context, hash, facets, old); | |
152 } | |
81 | 153 |
82 final FixRealizingAccess access = new FixRealizingAccess(artifact); | 154 @Override |
155 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
83 | 156 |
84 if (old instanceof CalculationResult) { | 157 return compute((BUNDUArtifact) artifact, context, hash, facets, old); |
85 res = (CalculationResult) old; | 158 } |
86 } else { | |
87 final FixRealizingCalculation calc = new FixRealizingCalculation(access); | |
88 res = calc.calculate(); | |
89 } | |
90 | 159 |
91 if (facets == null) { | 160 private Object compute(final BUNDUArtifact artifact, final CallContext context, final String hash, final List<Facet> facets, final Object old) { |
161 | |
162 final BezugswstCalculation s = new BezugswstCalculation(context); | |
163 final CalculationResult res = s.calculate(artifact); | |
164 | |
165 if (facets == null) | |
92 return res; | 166 return res; |
93 } | |
94 | 167 |
95 if (res.getReport().hasProblems()) { | 168 // if (!((List<Facet>) res).isEmpty()) { |
96 facets.add(new ReportFacet()); | 169 final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); |
97 } | 170 final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); |
98 | 171 |
99 final String id = getID(); | 172 facets.add(csv); |
100 final CallMeta meta = context.getMeta(); | 173 facets.add(pdf); |
101 | 174 // } |
102 final FixRealizingResult fixRes = (FixRealizingResult) res.getData(); | |
103 final WQKms[] wqkms = fixRes != null ? fixRes.getWQKms() : new WQKms[0]; | |
104 | |
105 for (int i = 0; i < wqkms.length; i++) { | |
106 String nameW = null; | |
107 String nameQ = null; | |
108 | |
109 if (access.isQ()) { | |
110 nameQ = wqkms[i].getName(); | |
111 nameW = "W(" + nameQ + ")"; | |
112 } else { | |
113 nameW = wqkms[i].getName(); | |
114 nameQ = "Q(" + nameW + ")"; | |
115 } | |
116 | |
117 final Facet wq = new FixWaterlevelFacet(i, FIX_WQ_LS, nameW, ComputeType.ADVANCE, hash, id); | |
118 | |
119 final Facet w = new FixWaterlevelFacet(i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, hash, id); | |
120 | |
121 final Facet q = new FixWaterlevelFacet(i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, hash, id); | |
122 final Facet csFacet = new CrossSectionWaterLineFacet(i, nameW); | |
123 | |
124 facets.add(wq); | |
125 facets.add(w); | |
126 facets.add(q); | |
127 facets.add(csFacet); | |
128 | |
129 // XXX: THIS CAN NOT HAPPEN! REMOVE IT! | |
130 if (wqkms[i] instanceof WQCKms) { | |
131 final String nameC = nameW.replace("benutzerdefiniert", "benutzerdefiniert [korrigiert]"); | |
132 | |
133 final Facet c = new FixWaterlevelFacet(i, DISCHARGE_LONGITUDINAL_C, nameC); | |
134 | |
135 facets.add(c); | |
136 } | |
137 } | |
138 | |
139 if (wqkms.length > 0) { | |
140 final DateFormat df = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy"); | |
141 final DateFormat lf = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy'T'HH:mm"); | |
142 | |
143 final Collection<Date> reds = fixRes.getReferenceEventsDates(); | |
144 final UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, reds); | |
145 | |
146 int i = 0; | |
147 for (final Date d : reds) { | |
148 facets.add(new FixReferenceEventsFacet((1 << 9) | i, FIX_EVENTS, cf.format(d))); | |
149 i++; | |
150 } | |
151 | |
152 facets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | |
153 | |
154 facets.add(new DataFacet(WST, "WST data", ComputeType.ADVANCE, hash, id)); | |
155 | |
156 facets.add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, id)); | |
157 } | |
158 | |
159 facets.add(new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, id)); | |
160 | |
161 facets.add(new FixWQCurveFacet(0, Resources.getMsg(meta, I18N_WQ_CURVE, I18N_WQ_CURVE) + " (" + access.getFunction() + ")")); | |
162 | |
163 if (access.getPreprocessing()) { | |
164 facets.add(new FixOutlierFacet(0, FIX_OUTLIER, Resources.getMsg(meta, I18N_WQ_OUTLIER, I18N_WQ_OUTLIER))); | |
165 } | |
166 | 175 |
167 return res; | 176 return res; |
168 } | 177 } |
178 | |
169 } | 179 } |