comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java @ 3121:0b86b005bb9a

FixA: Respect the selected events and reference period correctly. flys-artifacts/trunk@4722 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 20 Jun 2012 11:25:21 +0000
parents cbf308f5c41b
children 3b6ab6fac843
comparison
equal deleted inserted replaced
3120:e52a3b62fc20 3121:0b86b005bb9a
10 import de.intevation.flys.artifacts.model.FixingsColumn; 10 import de.intevation.flys.artifacts.model.FixingsColumn;
11 import de.intevation.flys.artifacts.model.FixingsColumnFactory; 11 import de.intevation.flys.artifacts.model.FixingsColumnFactory;
12 12
13 import de.intevation.flys.artifacts.model.FixingsOverview.AndFilter; 13 import de.intevation.flys.artifacts.model.FixingsOverview.AndFilter;
14 import de.intevation.flys.artifacts.model.FixingsOverview.DateRangeFilter; 14 import de.intevation.flys.artifacts.model.FixingsOverview.DateRangeFilter;
15
16 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing.Filter;
17
15 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing; 18 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing;
16 import de.intevation.flys.artifacts.model.FixingsOverview.IdFilter; 19 import de.intevation.flys.artifacts.model.FixingsOverview.IdsFilter;
17 import de.intevation.flys.artifacts.model.FixingsOverview.KmFilter; 20 import de.intevation.flys.artifacts.model.FixingsOverview.KmFilter;
18 import de.intevation.flys.artifacts.model.FixingsOverview.Range; 21 import de.intevation.flys.artifacts.model.FixingsOverview.Range;
22 import de.intevation.flys.artifacts.model.FixingsOverview.SectorFilter;
19 import de.intevation.flys.artifacts.model.FixingsOverview.SectorRangeFilter; 23 import de.intevation.flys.artifacts.model.FixingsOverview.SectorRangeFilter;
20 import de.intevation.flys.artifacts.model.FixingsOverview.SectorFilter;
21 24
22 import de.intevation.flys.artifacts.model.FixingsOverview; 25 import de.intevation.flys.artifacts.model.FixingsOverview;
23 import de.intevation.flys.artifacts.model.FixingsOverviewFactory; 26 import de.intevation.flys.artifacts.model.FixingsOverviewFactory;
24 import de.intevation.flys.artifacts.model.Parameters; 27 import de.intevation.flys.artifacts.model.Parameters;
25 28
47 protected double to; 50 protected double to;
48 protected double step; 51 protected double step;
49 protected boolean preprocessing; 52 protected boolean preprocessing;
50 protected String function; 53 protected String function;
51 protected int [] events; 54 protected int [] events;
55 protected DateRange referencePeriod;
52 protected DateRange [] analysisPeriods; 56 protected DateRange [] analysisPeriods;
53 protected int qSectorStart; 57 protected int qSectorStart;
54 protected int qSectorEnd; 58 protected int qSectorEnd;
55 59
56 public FixCalculation() { 60 public FixCalculation() {
57 } 61 }
58 62
59 public FixCalculation(FixationArtifactAccess access) { 63 public FixCalculation(FixationArtifactAccess access) {
60 64
61 String river = access.getRiver(); 65 String river = access.getRiver();
62 Double from = access.getFrom(); 66 Double from = access.getFrom();
63 Double to = access.getTo(); 67 Double to = access.getTo();
64 Double step = access.getStep(); 68 Double step = access.getStep();
65 String function = access.getFunction(); 69 String function = access.getFunction();
66 int [] events = access.getEvents(); 70 int [] events = access.getEvents();
71 DateRange referencePeriod = access.getReferencePeriod();
67 DateRange [] analysisPeriods = access.getAnalysisPeriods(); 72 DateRange [] analysisPeriods = access.getAnalysisPeriods();
68 Integer qSectorStart = access.getQSectorStart(); 73 Integer qSectorStart = access.getQSectorStart();
69 Integer qSectorEnd = access.getQSectorEnd(); 74 Integer qSectorEnd = access.getQSectorEnd();
70 Boolean preprocessing = access.getPreprocessing(); 75 Boolean preprocessing = access.getPreprocessing();
71 76
72 if (river == null) { 77 if (river == null) {
73 // TODO: i18n 78 // TODO: i18n
74 addProblem("fix.missing.river"); 79 addProblem("fix.missing.river");
75 } 80 }
95 } 100 }
96 101
97 if (events == null || events.length < 1) { 102 if (events == null || events.length < 1) {
98 // TODO: i18n 103 // TODO: i18n
99 addProblem("fix.missing.events"); 104 addProblem("fix.missing.events");
105 }
106
107 if (referencePeriod == null) {
108 // TODO: i18n
109 addProblem("fix.missing.reference.period");
100 } 110 }
101 111
102 if (analysisPeriods == null || analysisPeriods.length < 1) { 112 if (analysisPeriods == null || analysisPeriods.length < 1) {
103 // TODO: i18n 113 // TODO: i18n
104 addProblem("fix.missing.analysis.periods"); 114 addProblem("fix.missing.analysis.periods");
124 this.from = from; 134 this.from = from;
125 this.to = to; 135 this.to = to;
126 this.step = step; 136 this.step = step;
127 this.function = function; 137 this.function = function;
128 this.events = events; 138 this.events = events;
139 this.referencePeriod = referencePeriod;
129 this.analysisPeriods = analysisPeriods; 140 this.analysisPeriods = analysisPeriods;
130 this.qSectorStart = qSectorStart; 141 this.qSectorStart = qSectorStart;
131 this.qSectorEnd = qSectorEnd; 142 this.qSectorEnd = qSectorEnd;
132 this.preprocessing = preprocessing; 143 this.preprocessing = preprocessing;
133 } 144 }
220 double km = kms[i]; 231 double km = kms[i];
221 232
222 // Fill Qs and Ws from event columns. 233 // Fill Qs and Ws from event columns.
223 for (int j = 0; j < ws.length; ++j) { 234 for (int j = 0; j < ws.length; ++j) {
224 interpolated[j] = eventColumns.get(j).getQW(km, qs, ws, j); 235 interpolated[j] = eventColumns.get(j).getQW(km, qs, ws, j);
225 // TODO: mark as interpolated.
226 } 236 }
227 237
228 fitting.reset(); 238 fitting.reset();
229 239
230 if (!fitting.fit(qs, ws)) { 240 if (!fitting.fit(qs, ws)) {
279 289
280 protected List<Column> getEventColumns(FixingsOverview overview) { 290 protected List<Column> getEventColumns(FixingsOverview overview) {
281 291
282 FixingsColumnFactory fcf = FixingsColumnFactory.getInstance(); 292 FixingsColumnFactory fcf = FixingsColumnFactory.getInstance();
283 293
284 List<Column> columns = new ArrayList<Column>(events.length); 294 IdsFilter ids = new IdsFilter(events);
285 295 DateRangeFilter rdf = new DateRangeFilter(
286 for (int eventId: events) { 296 referencePeriod.getFrom(),
287 IdFilter idFilter = new IdFilter(eventId); 297 referencePeriod.getTo());
288 298 Filter filter = new AndFilter().add(rdf).add(ids);
289 List<Fixing.Column> metas = overview.filter(null, idFilter); 299
290 300 List<Fixing.Column> metas = overview.filter(null, filter);
291 if (metas.isEmpty()) { 301
292 // TODO: i18n 302 List<Column> columns = new ArrayList<Column>(metas.size());
293 addProblem("fix.missing.column", eventId); 303
294 continue; 304 for (Fixing.Column meta: metas) {
295 } 305
296 306 FixingsColumn data = fcf.getColumnData(meta);
297 FixingsColumn data = fcf.getColumnData(metas.get(0));
298 if (data == null) { 307 if (data == null) {
299 // TODO: i18n 308 // TODO: i18n
300 addProblem("fix.cannot.load.data", eventId); 309 addProblem("fix.cannot.load.data");
301 continue; 310 }
302 } 311 else {
303 312 columns.add(new Column(metas.get(0), data));
304 columns.add(new Column(metas.get(0), data)); 313 }
305 } 314 }
306 315
307 return columns; 316 return columns;
308 } 317 }
318
309 319
310 protected KMIndex<AnalysisPeriod []> calculateAnalysisPeriods( 320 protected KMIndex<AnalysisPeriod []> calculateAnalysisPeriods(
311 Function function, 321 Function function,
312 Parameters parameters, 322 Parameters parameters,
313 FixingsOverview overview 323 FixingsOverview overview
329 DateAverager dateAverager = new DateAverager(); 339 DateAverager dateAverager = new DateAverager();
330 340
331 KMIndex<AnalysisPeriod []> results = 341 KMIndex<AnalysisPeriod []> results =
332 new KMIndex<AnalysisPeriod []>(parameters.size()); 342 new KMIndex<AnalysisPeriod []>(parameters.size());
333 343
344 IdsFilter idsFilter = new IdsFilter(events);
345
334 for (int row = 0, R = parameters.size(); row < R; ++row) { 346 for (int row = 0, R = parameters.size(); row < R; ++row) {
335 double km = parameters.get(row, kmIndex); 347 double km = parameters.get(row, kmIndex);
336 parameters.get(row, parameterIndices, parameterValues); 348 parameters.get(row, parameterIndices, parameterValues);
337 349
338 // This is the paraterized function for a given km. 350 // This is the paraterized function for a given km.
353 ArrayList<QWD> allQWDs = new ArrayList<QWD>(); 365 ArrayList<QWD> allQWDs = new ArrayList<QWD>();
354 366
355 // for all Q sectors. 367 // for all Q sectors.
356 for (int qSector = qSectorStart; qSector < qSectorEnd; ++qSector) { 368 for (int qSector = qSectorStart; qSector < qSectorEnd; ++qSector) {
357 369
358 AndFilter filter = new AndFilter(); 370 Filter filter = new AndFilter()
359 filter.add(kmFilter); 371 .add(kmFilter)
360 filter.add(new SectorFilter(qSector)); 372 .add(new SectorFilter(qSector))
361 filter.add(drf); 373 .add(drf)
374 .add(idsFilter);
362 375
363 List<Fixing.Column> metas = overview.filter(range, filter); 376 List<Fixing.Column> metas = overview.filter(range, filter);
364 377
365 if (metas.isEmpty()) { 378 if (metas.isEmpty()) {
366 // No fixings for km and analysis period 379 // No fixings for km and analysis period

http://dive4elements.wald.intevation.org