Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java @ 5828:dfb26b03b179
Moved directories to org.dive4elements.river
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 11:53:11 +0200 |
parents | a16837d73130 |
children |
rev | line source |
---|---|
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model.fixings; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import de.intevation.flys.artifacts.access.FixAnalysisAccess; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import de.intevation.flys.artifacts.math.fitting.Function; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import de.intevation.flys.artifacts.model.CalculationResult; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import de.intevation.flys.artifacts.model.DateRange; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.flys.artifacts.model.FixingsOverview.AndFilter; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.flys.artifacts.model.FixingsOverview.DateRangeFilter; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing.Filter; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.flys.artifacts.model.FixingsOverview.IdsFilter; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.flys.artifacts.model.FixingsOverview.KmFilter; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.flys.artifacts.model.FixingsOverview.SectorFilter; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.flys.artifacts.model.FixingsOverview; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.flys.artifacts.model.Parameters; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.artifacts.model.Range; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.flys.utils.DateAverager; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 import de.intevation.flys.utils.KMIndex; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
3609
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
27 import gnu.trove.TIntIntHashMap; |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
28 |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 import java.util.ArrayList; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 import java.util.Date; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 import java.util.List; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 import org.apache.log4j.Logger; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 public class FixAnalysisCalculation |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3415
diff
changeset
|
38 extends FixCalculation |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 private static Logger log = Logger.getLogger(FixAnalysisCalculation.class); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 protected DateRange referencePeriod; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 protected DateRange [] analysisPeriods; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 public FixAnalysisCalculation() { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 public FixAnalysisCalculation(FixAnalysisAccess access) { |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3415
diff
changeset
|
49 super(access); |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 DateRange referencePeriod = access.getReferencePeriod(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 DateRange [] analysisPeriods = access.getAnalysisPeriods(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 if (referencePeriod == null) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 addProblem("fix.missing.reference.period"); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 if (analysisPeriods == null || analysisPeriods.length < 1) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 addProblem("fix.missing.analysis.periods"); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 if (!hasProblems()) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 this.referencePeriod = referencePeriod; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 this.analysisPeriods = analysisPeriods; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
3437
e111902834d3
FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3435
diff
changeset
|
68 @Override |
e111902834d3
FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3435
diff
changeset
|
69 public CalculationResult innerCalculate( |
e111902834d3
FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3435
diff
changeset
|
70 FixingsOverview overview, |
e111902834d3
FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3435
diff
changeset
|
71 Function func |
e111902834d3
FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3435
diff
changeset
|
72 ) { |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
73 ColumnCache cc = new ColumnCache(); |
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
74 |
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
75 FitResult fitResult = doFitting(overview, cc, func); |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
77 if (fitResult == null) { |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 return new CalculationResult(this); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
81 KMIndex<AnalysisPeriod []> analysisPeriods = |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
82 calculateAnalysisPeriods( |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
83 func, |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
84 fitResult.getParameters(), |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
85 overview, |
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
86 cc); |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 analysisPeriods.sort(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
90 FixAnalysisResult far = new FixAnalysisResult( |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
91 fitResult.getParameters(), |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
92 fitResult.getReferenced(), |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
93 fitResult.getOutliers(), |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 analysisPeriods); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
96 return new CalculationResult(far, this); |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3420
diff
changeset
|
99 @Override |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3420
diff
changeset
|
100 protected Filter createFilter() { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3420
diff
changeset
|
101 Filter ids = super.createFilter(); |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 DateRangeFilter rdf = new DateRangeFilter( |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 referencePeriod.getFrom(), |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 referencePeriod.getTo()); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3420
diff
changeset
|
105 return new AndFilter().add(rdf).add(ids); |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 protected KMIndex<AnalysisPeriod []> calculateAnalysisPeriods( |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 Function function, |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 Parameters parameters, |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
111 FixingsOverview overview, |
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3437
diff
changeset
|
112 ColumnCache cc |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 ) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 Range range = new Range(from, to); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 int kmIndex = parameters.columnIndex("km"); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 int maxQIndex = parameters.columnIndex("max_q"); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 double [] wq = new double[2]; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 int [] parameterIndices = |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 parameters.columnIndices(function.getParameterNames()); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 double [] parameterValues = new double[parameterIndices.length]; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 DateAverager dateAverager = new DateAverager(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 KMIndex<AnalysisPeriod []> results = |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 new KMIndex<AnalysisPeriod []>(parameters.size()); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 IdsFilter idsFilter = new IdsFilter(events); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 |
3609
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
133 TIntIntHashMap [] col2indices = |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
134 new TIntIntHashMap[analysisPeriods.length]; |
3605
7196f06e0928
FixA: Made indices of analysis periods QWs zero based.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3604
diff
changeset
|
135 |
3607
e0f54fab55d3
FixA: Generate indices for each analysis periods.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3605
diff
changeset
|
136 for (int i = 0; i < analysisPeriods.length; ++i) { |
3609
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
137 col2indices[i] = new TIntIntHashMap(); |
3607
e0f54fab55d3
FixA: Generate indices for each analysis periods.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3605
diff
changeset
|
138 } |
3605
7196f06e0928
FixA: Made indices of analysis periods QWs zero based.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3604
diff
changeset
|
139 |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 for (int row = 0, R = parameters.size(); row < R; ++row) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 double km = parameters.get(row, kmIndex); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 parameters.get(row, parameterIndices, parameterValues); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 // This is the paraterized function for a given km. |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 de.intevation.flys.artifacts.math.Function instance = |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 function.instantiate(parameterValues); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 KmFilter kmFilter = new KmFilter(km); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 ArrayList<AnalysisPeriod> periodResults = |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 new ArrayList<AnalysisPeriod>(analysisPeriods.length); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 |
3607
e0f54fab55d3
FixA: Generate indices for each analysis periods.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3605
diff
changeset
|
153 for (int ap = 0; ap < analysisPeriods.length; ++ap) { |
e0f54fab55d3
FixA: Generate indices for each analysis periods.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3605
diff
changeset
|
154 DateRange analysisPeriod = analysisPeriods[ap]; |
3609
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
155 TIntIntHashMap col2index = col2indices[ap]; |
3607
e0f54fab55d3
FixA: Generate indices for each analysis periods.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3605
diff
changeset
|
156 |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 DateRangeFilter drf = new DateRangeFilter( |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 analysisPeriod.getFrom(), |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 analysisPeriod.getTo()); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 QWD [] qSectorAverages = new QWD[4]; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 double [] qSectorStdDevs = new double[4]; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 ArrayList<QWD> allQWDs = new ArrayList<QWD>(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 // for all Q sectors. |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 for (int qSector = qSectorStart; qSector < qSectorEnd; ++qSector) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 Filter filter = new AndFilter() |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 .add(kmFilter) |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 .add(new SectorFilter(qSector)) |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 .add(drf) |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 .add(idsFilter); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 List<Fixing.Column> metas = overview.filter(range, filter); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 if (metas.isEmpty()) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 // No fixings for km and analysis period |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 continue; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 double sumQ = 0.0; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 double sumW = 0.0; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 StandardDeviation stdDev = new StandardDeviation(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 List<QWD> qwds = new ArrayList<QWD>(metas.size()); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 dateAverager.clear(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 for (Fixing.Column meta: metas) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 if (meta.findQSector(km) != qSector) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 // Ignore not matching sectors. |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 continue; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 Column column = cc.getColumn(meta); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 if (column == null || !column.getQW(km, wq)) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 continue; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 double fw = instance.value(wq[1]); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 if (Double.isNaN(fw)) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 continue; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 double dw = (wq[0] - fw)*100.0; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 stdDev.increment(dw); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 Date date = column.getDate(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 String description = column.getDescription(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 QWD qwd = new QWD( |
3604
2382b26079ac
FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3603
diff
changeset
|
215 wq[1], wq[0], |
2382b26079ac
FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3603
diff
changeset
|
216 description, |
2382b26079ac
FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3603
diff
changeset
|
217 date, true, |
3609
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
218 dw, getIndex(col2index, column.getIndex())); |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 qwds.add(qwd); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 sumW += wq[0]; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 sumQ += wq[1]; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 dateAverager.add(date); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 // Calulate average per Q sector. |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 int N = qwds.size(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 if (N > 0) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 allQWDs.addAll(qwds); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 double avgW = sumW / N; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 double avgQ = sumQ / N; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 double avgFw = instance.value(avgQ); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 if (!Double.isNaN(avgFw)) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 double avgDw = (avgW - avgFw)*100.0; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 Date avgDate = dateAverager.getAverage(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 String avgDescription = "avg.deltawt." + qSector; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 QWD avgQWD = new QWD( |
3604
2382b26079ac
FixA: Store unique coulun index into QW models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3603
diff
changeset
|
243 avgQ, avgW, avgDescription, avgDate, true, avgDw, 0); |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 qSectorAverages[qSector] = avgQWD; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 qSectorStdDevs[qSector] = stdDev.getResult(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 else { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 qSectorStdDevs[qSector] = Double.NaN; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 } // for all Q sectors |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 QWD [] aqwds = allQWDs.toArray(new QWD[allQWDs.size()]); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 AnalysisPeriod periodResult = new AnalysisPeriod( |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 analysisPeriod, |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 aqwds, |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 qSectorAverages, |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 qSectorStdDevs); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 periodResults.add(periodResult); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 double maxQ = -Double.MAX_VALUE; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 for (AnalysisPeriod ap: periodResults) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 double q = ap.getMaxQ(); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 if (q > maxQ) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 maxQ = q; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 double oldMaxQ = parameters.get(row, maxQIndex); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 if (oldMaxQ < maxQ) { |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 parameters.set(row, maxQIndex, maxQ); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 results.add(km, periodResults.toArray( |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 new AnalysisPeriod[periodResults.size()])); |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 return results; |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 } |
3609
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
283 |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
284 private static final int getIndex(TIntIntHashMap map, int colIdx) { |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
285 if (map.containsKey(colIdx)) { |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
286 return map.get(colIdx); |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
287 } |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
288 int index = map.size(); |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
289 map.put(colIdx, index); |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
290 return index; |
a16837d73130
FixA: Using trove to map int->int instead of bloated generics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3607
diff
changeset
|
291 } |
3411
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
292 } |
0ef83077c93f
FixA: Renamed FixCalculation to FixAnalysisCalculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
293 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |