Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java @ 3222:116b342893e3
SQ: Connect calculation with artifact parameter access.
flys-artifacts/trunk@4845 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 01 Jul 2012 18:00:04 +0000 |
parents | 238803b2cb8b |
children | 45af081061e7 |
comparison
equal
deleted
inserted
replaced
3221:06ae0258269b | 3222:116b342893e3 |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | 2 |
3 import java.util.ArrayList; | 3 import de.intevation.artifactdatabase.state.Facet; |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | 4 |
8 import de.intevation.artifacts.CallContext; | 5 import de.intevation.artifacts.CallContext; |
9 import de.intevation.artifacts.CallMeta; | 6 import de.intevation.artifacts.CallMeta; |
10 | 7 |
11 import de.intevation.artifactdatabase.state.Facet; | |
12 | |
13 import de.intevation.flys.artifacts.FLYSArtifact; | 8 import de.intevation.flys.artifacts.FLYSArtifact; |
14 import de.intevation.flys.artifacts.MINFOArtifact; | 9 |
10 import de.intevation.flys.artifacts.access.SQRelationAccess; | |
11 | |
12 import de.intevation.flys.artifacts.model.CalculationResult; | |
15 import de.intevation.flys.artifacts.model.DataFacet; | 13 import de.intevation.flys.artifacts.model.DataFacet; |
16 import de.intevation.flys.artifacts.model.FacetTypes; | 14 import de.intevation.flys.artifacts.model.FacetTypes; |
17 import de.intevation.flys.artifacts.model.CalculationResult; | 15 |
18 import de.intevation.flys.artifacts.model.sq.SQCurveFacet; | 16 import de.intevation.flys.artifacts.model.sq.SQCurveFacet; |
19 import de.intevation.flys.artifacts.model.sq.SQFractionResult; | 17 import de.intevation.flys.artifacts.model.sq.SQFractionResult; |
20 import de.intevation.flys.artifacts.model.sq.SQMeasurementFacet; | 18 import de.intevation.flys.artifacts.model.sq.SQMeasurementFacet; |
21 import de.intevation.flys.artifacts.model.sq.SQOutlierFacet; | 19 import de.intevation.flys.artifacts.model.sq.SQOutlierFacet; |
22 import de.intevation.flys.artifacts.model.sq.SQRelationCalculation; | 20 import de.intevation.flys.artifacts.model.sq.SQRelationCalculation; |
23 import de.intevation.flys.artifacts.model.sq.SQResult; | 21 import de.intevation.flys.artifacts.model.sq.SQResult; |
22 | |
24 import de.intevation.flys.artifacts.resources.Resources; | 23 import de.intevation.flys.artifacts.resources.Resources; |
24 | |
25 import de.intevation.flys.artifacts.states.DefaultState; | 25 import de.intevation.flys.artifacts.states.DefaultState; |
26 | |
27 import java.util.List; | |
28 | |
29 import org.apache.log4j.Logger; | |
26 | 30 |
27 /** | 31 /** |
28 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 32 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
29 */ | 33 */ |
30 public class SQRelation extends DefaultState implements FacetTypes { | 34 public class SQRelation extends DefaultState implements FacetTypes { |
31 | 35 |
32 private static Logger logger = Logger.getLogger(SQRelation.class); | 36 private static Logger log = Logger.getLogger(SQRelation.class); |
33 | 37 |
34 | 38 |
35 public static final String I18N_FACET_CURVE = | 39 public static final String I18N_FACET_CURVE = |
36 "facet.sq_relation.curve"; | 40 "facet.sq_relation.curve"; |
37 | 41 |
52 String hash, | 56 String hash, |
53 CallContext context, | 57 CallContext context, |
54 List<Facet> facets, | 58 List<Facet> facets, |
55 Object old | 59 Object old |
56 ) { | 60 ) { |
57 logger.debug("SQRelation.computeAdvance"); | 61 log.debug("SQRelation.computeAdvance"); |
58 | |
59 List<Facet> newFacets = new ArrayList<Facet>(); | |
60 | 62 |
61 CalculationResult res = old instanceof CalculationResult | 63 CalculationResult res = old instanceof CalculationResult |
62 ? (CalculationResult) old | 64 ? (CalculationResult)old |
63 : new SQRelationCalculation().calculate((MINFOArtifact) artifact); | 65 : new SQRelationCalculation( |
64 | 66 new SQRelationAccess(artifact)).calculate(); |
65 if (facets == null || res == null) { | 67 |
68 if (facets == null) { | |
66 return res; | 69 return res; |
67 } | 70 } |
68 | 71 |
69 SQResult[] sqr = (SQResult[]) res.getData(); | 72 SQResult [] sqr = (SQResult [])res.getData(); |
70 logger.info("Calculation computed " + sqr.length + " SQResult objects"); | 73 if (sqr == null) { |
71 | 74 return res; |
72 createFacets(context, newFacets, sqr, hash); | 75 } |
76 | |
77 createFacets(context, facets, sqr, hash); | |
73 | 78 |
74 Facet csv = new DataFacet( | 79 Facet csv = new DataFacet( |
75 CSV, "CSV data", ComputeType.ADVANCE, hash, id); | 80 CSV, "CSV data", ComputeType.ADVANCE, hash, id); |
76 | 81 |
77 Facet pdf = new DataFacet( | 82 Facet pdf = new DataFacet( |
78 PDF, "PDF data", ComputeType.ADVANCE, hash, id); | 83 PDF, "PDF data", ComputeType.ADVANCE, hash, id); |
79 | 84 |
80 newFacets.add(csv); | 85 facets.add(csv); |
81 newFacets.add(pdf); | 86 facets.add(pdf); |
82 | |
83 logger.debug("Created " + newFacets.size() + " new Facets."); | |
84 | |
85 facets.addAll(newFacets); | |
86 | 87 |
87 return res; | 88 return res; |
88 } | 89 } |
89 | 90 |
90 | 91 |
101 | 102 |
102 for (int i = 0; i < 6; i++) { | 103 for (int i = 0; i < 6; i++) { |
103 SQFractionResult result = sqr[res].getFraction(i); | 104 SQFractionResult result = sqr[res].getFraction(i); |
104 | 105 |
105 if (result == null) { | 106 if (result == null) { |
106 logger.warn("Fraction at index " + i + " is empty!"); | 107 log.warn("Fraction at index " + i + " is empty!"); |
107 continue; | 108 continue; |
108 } | 109 } |
109 | 110 |
110 container.add(new SQMeasurementFacet( | 111 container.add(new SQMeasurementFacet( |
111 res, | 112 res, |
136 for (int j = 0, C = result.getOutliersCount(); j < C; j++) { | 137 for (int j = 0, C = result.getOutliersCount(); j < C; j++) { |
137 int index = res; | 138 int index = res; |
138 index = index << 16; | 139 index = index << 16; |
139 index = index + j; | 140 index = index + j; |
140 | 141 |
141 if (logger.isDebugEnabled()) { | 142 if (log.isDebugEnabled()) { |
142 logger.debug("new outliers facet (index=" +index+ ")"); | 143 log.debug("new outliers facet (index=" +index+ ")"); |
143 logger.debug(" result index = " + res); | 144 log.debug(" result index = " + res); |
144 logger.debug(" fraction idx = " + i); | 145 log.debug(" fraction idx = " + i); |
145 logger.debug(" iteration = " + j); | 146 log.debug(" iteration = " + j); |
146 } | 147 } |
147 | 148 |
148 container.add(new SQOutlierFacet( | 149 container.add(new SQOutlierFacet( |
149 index, | 150 index, |
150 i, | 151 i, |
163 } | 164 } |
164 } | 165 } |
165 | 166 |
166 | 167 |
167 protected String getFractionFacetname(int type, int fractionIdx) { | 168 protected String getFractionFacetname(int type, int fractionIdx) { |
168 logger.debug("getFractionFacetname(): " + type + " | " + fractionIdx); | 169 log.debug("getFractionFacetname(): " + type + " | " + fractionIdx); |
169 | 170 |
170 switch (type) { | 171 switch (type) { |
171 case 0: | 172 case 0: |
172 switch (fractionIdx) { | 173 switch (fractionIdx) { |
173 case 0: return SQ_A_CURVE; | 174 case 0: return SQ_A_CURVE; |