Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | 0f7abd95c6e2 |
children | 1df6984628c3 |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import de.intevation.artifactdatabase.state.Facet; | |
4 | |
5 import de.intevation.artifacts.CallContext; | |
6 import de.intevation.artifacts.CallMeta; | |
7 | |
8 import de.intevation.flys.artifacts.FLYSArtifact; | |
9 | |
10 import de.intevation.flys.artifacts.access.SQRelationAccess; | |
11 | |
12 import de.intevation.flys.artifacts.model.CalculationResult; | |
13 import de.intevation.flys.artifacts.model.DataFacet; | |
14 import de.intevation.flys.artifacts.model.FacetTypes; | |
15 | |
16 import de.intevation.flys.artifacts.model.sq.SQCurveFacet; | |
17 import de.intevation.flys.artifacts.model.sq.SQFractionResult; | |
18 import de.intevation.flys.artifacts.model.sq.SQMeasurementFacet; | |
19 import de.intevation.flys.artifacts.model.sq.SQOutlierFacet; | |
20 import de.intevation.flys.artifacts.model.sq.SQRelationCalculation; | |
21 import de.intevation.flys.artifacts.model.sq.SQResult; | |
22 import de.intevation.flys.artifacts.model.sq.SQOverviewFacet; | |
23 | |
24 import de.intevation.flys.artifacts.resources.Resources; | |
25 | |
26 import java.util.List; | |
27 | |
28 import org.apache.log4j.Logger; | |
29 | |
30 /** | |
31 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
32 */ | |
33 public class SQRelation extends DefaultState implements FacetTypes { | |
34 | |
35 private static Logger log = Logger.getLogger(SQRelation.class); | |
36 | |
37 | |
38 public static final String I18N_FACET_CURVE = | |
39 "facet.sq_relation.curve"; | |
40 | |
41 public static final String I18N_FACET_MEASUREMENTS = | |
42 "facet.sq_relation.measurements"; | |
43 | |
44 public static final String I18N_FACET_OUTLIERS = | |
45 "facet.sq_relation.outliers"; | |
46 | |
47 | |
48 public SQRelation() { | |
49 } | |
50 | |
51 | |
52 @Override | |
53 public Object computeAdvance( | |
54 FLYSArtifact artifact, | |
55 String hash, | |
56 CallContext context, | |
57 List<Facet> facets, | |
58 Object old | |
59 ) { | |
60 log.debug("SQRelation.computeAdvance"); | |
61 | |
62 CalculationResult res = old instanceof CalculationResult | |
63 ? (CalculationResult)old | |
64 : new SQRelationCalculation( | |
65 new SQRelationAccess(artifact)).calculate(); | |
66 | |
67 if (facets == null) { | |
68 return res; | |
69 } | |
70 | |
71 SQResult [] sqr = (SQResult [])res.getData(); | |
72 if (sqr == null) { | |
73 return res; | |
74 } | |
75 | |
76 createFacets(context, facets, sqr, hash); | |
77 | |
78 Facet csv = new DataFacet( | |
79 CSV, "CSV data", ComputeType.ADVANCE, hash, id); | |
80 | |
81 Facet pdf = new DataFacet( | |
82 PDF, "PDF data", ComputeType.ADVANCE, hash, id); | |
83 | |
84 facets.add(csv); | |
85 facets.add(pdf); | |
86 | |
87 return res; | |
88 } | |
89 | |
90 | |
91 protected void createFacets( | |
92 CallContext context, | |
93 List<Facet> container, | |
94 SQResult[] sqr, | |
95 String hash | |
96 ) { | |
97 CallMeta meta = context.getMeta(); | |
98 String stateId = getID(); | |
99 for (int i = 0; i < 6; i++) { | |
100 container.add(new SQOverviewFacet( | |
101 i, | |
102 i, | |
103 "sq_chart_overview", | |
104 Resources.getMsg( | |
105 context.getMeta(), | |
106 I18N_FACET_CURVE, | |
107 I18N_FACET_CURVE | |
108 ), | |
109 hash, | |
110 getID() | |
111 )); | |
112 } | |
113 for (int res = 0, n = sqr.length; res < n; res++) { | |
114 | |
115 for (int i = 0; i < 6; i++) { | |
116 SQFractionResult result = sqr[res].getFraction(i); | |
117 | |
118 if (result == null) { | |
119 log.warn("Fraction at index " + i + " is empty!"); | |
120 continue; | |
121 } | |
122 | |
123 container.add(new SQMeasurementFacet( | |
124 res, | |
125 i, | |
126 getFractionFacetname(1, i), | |
127 Resources.getMsg( | |
128 meta, | |
129 I18N_FACET_MEASUREMENTS, | |
130 I18N_FACET_MEASUREMENTS | |
131 ), | |
132 hash, | |
133 stateId | |
134 )); | |
135 | |
136 container.add(new SQCurveFacet( | |
137 res, | |
138 i, | |
139 getFractionFacetname(0, i), | |
140 Resources.getMsg( | |
141 meta, | |
142 I18N_FACET_CURVE, | |
143 I18N_FACET_CURVE | |
144 ), | |
145 hash, | |
146 stateId | |
147 )); | |
148 | |
149 for (int j = 0, C = result.getOutliersCount(); j < C; j++) { | |
150 int index = res; | |
151 index = index << 16; | |
152 index = index + j; | |
153 | |
154 if (log.isDebugEnabled()) { | |
155 log.debug("new outliers facet (index=" +index+ ")"); | |
156 log.debug(" result index = " + res); | |
157 log.debug(" fraction idx = " + i); | |
158 log.debug(" iteration = " + j); | |
159 } | |
160 | |
161 container.add(new SQOutlierFacet( | |
162 index, | |
163 i, | |
164 getFractionFacetname(2, i), | |
165 Resources.getMsg( | |
166 meta, | |
167 I18N_FACET_OUTLIERS, | |
168 I18N_FACET_OUTLIERS, | |
169 new Object[] { j } | |
170 ), | |
171 hash, | |
172 stateId | |
173 )); | |
174 } | |
175 } | |
176 } | |
177 } | |
178 | |
179 | |
180 protected String getFractionFacetname(int type, int fractionIdx) { | |
181 log.debug("getFractionFacetname(): " + type + " | " + fractionIdx); | |
182 | |
183 switch (type) { | |
184 case 0: | |
185 switch (fractionIdx) { | |
186 case 0: return SQ_A_CURVE; | |
187 case 1: return SQ_B_CURVE; | |
188 case 2: return SQ_C_CURVE; | |
189 case 3: return SQ_D_CURVE; | |
190 case 4: return SQ_E_CURVE; | |
191 case 5: return SQ_F_CURVE; | |
192 } | |
193 case 1: | |
194 switch (fractionIdx) { | |
195 case 0: return SQ_A_MEASUREMENT; | |
196 case 1: return SQ_B_MEASUREMENT; | |
197 case 2: return SQ_C_MEASUREMENT; | |
198 case 3: return SQ_D_MEASUREMENT; | |
199 case 4: return SQ_E_MEASUREMENT; | |
200 case 5: return SQ_F_MEASUREMENT; | |
201 } | |
202 case 2: | |
203 switch (fractionIdx) { | |
204 case 0: return SQ_A_OUTLIER; | |
205 case 1: return SQ_B_OUTLIER; | |
206 case 2: return SQ_C_OUTLIER; | |
207 case 3: return SQ_D_OUTLIER; | |
208 case 4: return SQ_E_OUTLIER; | |
209 case 5: return SQ_F_OUTLIER; | |
210 } | |
211 } | |
212 | |
213 return null; | |
214 } | |
215 } | |
216 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |