comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java @ 3217:79dd823733e2

FixA: Added parameter exporter. flys-artifacts/trunk@4840 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 30 Jun 2012 22:02:37 +0000
parents ae14f412ba10
children e0e9a2629d7d
comparison
equal deleted inserted replaced
3216:a46910e61dfb 3217:79dd823733e2
43 */ 43 */
44 public class FixationCompute 44 public class FixationCompute
45 extends DefaultState 45 extends DefaultState
46 implements FacetTypes 46 implements FacetTypes
47 { 47 {
48
49 /** The log used in this class. */ 48 /** The log used in this class. */
50 private static Logger log = Logger.getLogger(FixationCompute.class); 49 private static Logger log = Logger.getLogger(FixationCompute.class);
51 50
52 private static final String I18N_REFERENCEPERIOD = "fix.reference.period.events"; 51 private static final String I18N_REFERENCEPERIOD = "fix.reference.period.events";
53 52
61 60
62 private static final String I18N_DEVIATION = "fix.deviation"; 61 private static final String I18N_DEVIATION = "fix.deviation";
63 62
64 private static final String I18N_REFERENCEDEVIATION = "fix.reference.deviation"; 63 private static final String I18N_REFERENCEDEVIATION = "fix.reference.deviation";
65 64
65 public static final String [] SECTOR_LABELS = {
66 "[0 - (MNQ+MQ)/2)",
67 "[(MNQ+MQ)/2 - (MQ+MHQ)/2)",
68 "[(MQ+MHQ)/2 - HQ5)",
69 "[HQ5 - \u221e)"
70 };
71
66 public static class IdGenerator { 72 public static class IdGenerator {
67 private int id; 73 private int id;
68 74
69 public IdGenerator() { 75 public IdGenerator() {
70 } 76 }
71 77
72 public IdGenerator(int id) { 78 public IdGenerator(int id) {
73 this.id = id; 79 this.id = id;
74 } 80 }
75 81
76 public int next() { 82 public int next() {
77 return id++; 83 return id++;
78 } 84 }
79 85 } // class IdGenerator
80 public int next(int s) {
81 return id += s;
82 }
83 }
84 86
85 /** 87 /**
86 * The default constructor that initializes an empty State object. 88 * The default constructor that initializes an empty State object.
87 */ 89 */
88 public FixationCompute() { 90 public FixationCompute() {
96 List<Facet> facets, 98 List<Facet> facets,
97 Object old 99 Object old
98 ) { 100 ) {
99 log.debug("FixationCompute.computeAdvance"); 101 log.debug("FixationCompute.computeAdvance");
100 102
101
102 CalculationResult res; 103 CalculationResult res;
103 104
104 FixationArtifactAccess access = 105 FixationArtifactAccess access =
105 new FixationArtifactAccess(artifact); 106 new FixationArtifactAccess(artifact);
106 107
126 return res; 127 return res;
127 } 128 }
128 129
129 facets.add( 130 facets.add(
130 new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); 131 new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id));
132 facets.add(
133 new DataFacet(
134 FIX_PARAMETERS, "parameters", ComputeType.ADVANCE, hash, id));
131 135
132 int maxId = -100; 136 int maxId = -100;
133 137
134 int count = access.getAnalysisPeriods().length;
135
136 int sectorMask = fr.getUsedSectorsInAnalysisPeriods(); 138 int sectorMask = fr.getUsedSectorsInAnalysisPeriods();
137 139
138 for (int i = 0; i < count; i++) { 140 int qsS = access.getQSectorStart();
139 DateRange period = access.getAnalysisPeriods()[i]; 141 int qsE = access.getQSectorEnd();
140 DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); 142
143 // TODO: i18n
144 DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
145
146 DateRange [] periods = access.getAnalysisPeriods();
147
148 for (int i = 0; i < periods.length; i++) {
149 DateRange period = periods[i];
141 String startDate = df.format(period.getFrom()); 150 String startDate = df.format(period.getFrom());
142 String endDate = df.format(period.getTo()); 151 String endDate = df.format(period.getTo());
143 152
144 for (int j = access.getQSectorStart().intValue(); 153 for (int j = qsS; j <= qsE; j++) {
145 j <= access.getQSectorEnd().intValue(); 154
146 j++) { 155 // Only emit facets for sectors that really have data.
147
148 // Only emit facet for sectors that really have data.
149 if ((sectorMask & (1 << j)) == 0) { 156 if ((sectorMask & (1 << j)) == 0) {
150 continue; 157 continue;
151 } 158 }
152 159
153 String sector = ""; 160 String sector = SECTOR_LABELS[j];
154 switch (j) {
155 case 0: sector = "[0 - (MNQ+MQ)/2)"; break;
156 case 1: sector = "[(MNQ+MQ)/2 - (MQ+MHQ)/2)"; break;
157 case 2: sector = "[(MQ+MHQ)/2 - HQ5)"; break;
158 case 3: sector = "[HQ5 - \u221e)"; break;
159 }
160 String description = sector + ": " + 161 String description = sector + ": " +
161 startDate + " - " + 162 startDate + " - " +
162 endDate; 163 endDate;
163 164
164 int sectorNdx = j - access.getQSectorStart().intValue(); 165 int sectorNdx = j - qsS;
165 int facetNdx = i << 2; 166 int facetNdx = i << 2;
166 facetNdx = facetNdx | j; 167 facetNdx = facetNdx | j;
167 168
168 if (facetNdx > maxId) 169 if (facetNdx > maxId) {
169 maxId = facetNdx; 170 maxId = facetNdx;
170 171 }
171 facets.add( 172
172 new FixAvSectorFacet(facetNdx, 173 facets.add(
173 FIX_SECTOR_AVERAGE_DWT + "_" + sectorNdx, 174 new FixAvSectorFacet(
174 description)); 175 facetNdx,
175 facets.add( 176 FIX_SECTOR_AVERAGE_DWT + "_" + sectorNdx,
176 new FixLongitudinalAnalysisFacet(facetNdx, 177 description));
177 FIX_SECTOR_AVERAGE_LS + "_" + sectorNdx, 178 facets.add(
178 description)); 179 new FixLongitudinalAnalysisFacet(
180 facetNdx,
181 FIX_SECTOR_AVERAGE_LS + "_" + sectorNdx,
182 description));
179 // TODO: i18n 183 // TODO: i18n
180 String dev = "Abweichung: " + description; 184 String dev = "Abweichung: " + description;
181 facets.add( 185 facets.add(
182 new FixLongitudinalAnalysisFacet(facetNdx, 186 new FixLongitudinalAnalysisFacet(
183 FIX_SECTOR_AVERAGE_LS_DEVIATION + "_" + sectorNdx, 187 facetNdx,
184 dev)); 188 FIX_SECTOR_AVERAGE_LS_DEVIATION + "_" + sectorNdx,
185 facets.add( 189 dev));
186 new FixAvSectorFacet(facetNdx, 190 facets.add(
187 FIX_SECTOR_AVERAGE_WQ + "_" + sectorNdx, 191 new FixAvSectorFacet(
188 description)); 192 facetNdx,
193 FIX_SECTOR_AVERAGE_WQ + "_" + sectorNdx,
194 description));
189 195
190 } 196 }
191 197
192 String eventDesc = 198 String eventDesc =
193 Resources.getMsg(context.getMeta(), 199 Resources.getMsg(context.getMeta(),
203 facets.add(new FixAnalysisEventsFacet(i, 209 facets.add(new FixAnalysisEventsFacet(i,
204 FIX_ANALYSIS_EVENTS_WQ, 210 FIX_ANALYSIS_EVENTS_WQ,
205 eventDesc)); 211 eventDesc));
206 } 212 }
207 213
208 IdGenerator idg = new IdGenerator(maxId + 1); 214 IdGenerator idg = new IdGenerator(maxId + 1);
209 215
210 String i18n_ref = Resources.getMsg(context.getMeta(), 216 String i18n_ref = Resources.getMsg(context.getMeta(),
211 I18N_REFERENCEPERIOD, 217 I18N_REFERENCEPERIOD,
212 I18N_REFERENCEPERIOD); 218 I18N_REFERENCEPERIOD);
213 String i18n_dev = Resources.getMsg(context.getMeta(), 219 String i18n_dev = Resources.getMsg(context.getMeta(),
246 facets.add(new FixWQCurveFacet(idg.next(), "W/Q")); 252 facets.add(new FixWQCurveFacet(idg.next(), "W/Q"));
247 253
248 Boolean preprocessing = access.getPreprocessing(); 254 Boolean preprocessing = access.getPreprocessing();
249 255
250 if (preprocessing != null && preprocessing) { 256 if (preprocessing != null && preprocessing) {
251 facets.add(new FixOutlierFacet(idg.next(), FIX_OUTLIER, 257 facets.add(new FixOutlierFacet(
252 Resources.getMsg(context.getMeta(), I18N_OUTLIER, I18N_OUTLIER))); 258 idg.next(),
259 FIX_OUTLIER,
260 Resources.getMsg(
261 context.getMeta(), I18N_OUTLIER, I18N_OUTLIER)));
253 } 262 }
254 263
255 facets.add(new FixDerivateFacet( 264 facets.add(new FixDerivateFacet(
256 idg.next(), 265 idg.next(),
257 FIX_DERIVATE, 266 FIX_DERIVATE,
258 Resources.getMsg(context.getMeta(), 267 Resources.getMsg(
268 context.getMeta(),
259 I18N_DERIVATIVE, 269 I18N_DERIVATIVE,
260 I18N_DERIVATIVE))); 270 I18N_DERIVATIVE)));
261 271
262 facets.add(new FixDeviationFacet( 272 facets.add(new FixDeviationFacet(
263 idg.next(), 273 idg.next(),
264 FIX_DEVIATION_DWT, 274 FIX_DEVIATION_DWT,
265 Resources.getMsg(context.getMeta(), 275 Resources.getMsg(context.getMeta(),
266 I18N_DEVIATION, 276 I18N_DEVIATION,
267 I18N_DEVIATION))); 277 I18N_DEVIATION)));
268 return res; 278 return res;
269 } 279 }

http://dive4elements.wald.intevation.org