Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java @ 4357:11cf29eb002c
FacetTypes: New type: exreme_wq_curve_base (for the Stuetz-Q-Poits).
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 02 Nov 2012 11:58:11 +0100 |
parents | ba2f0bff0697 |
children | aaf810d4ec82 |
rev | line source |
---|---|
3072
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model.sq; |
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
3 import de.intevation.flys.artifacts.access.SQRelationAccess; |
3072
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
5 import de.intevation.flys.artifacts.math.fitting.Function; |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
6 import de.intevation.flys.artifacts.math.fitting.FunctionFactory; |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
7 |
3072
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import de.intevation.flys.artifacts.model.Calculation; |
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.flys.artifacts.model.CalculationResult; |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
10 import de.intevation.flys.artifacts.model.DateRange; |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
11 import de.intevation.flys.artifacts.model.Parameters; |
3072
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
3289
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
13 import de.intevation.flys.backend.SedDBSessionHolder; |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
14 |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
15 import java.util.ArrayList; |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
16 import java.util.List; |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
17 |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
18 import org.apache.log4j.Logger; |
3072
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 |
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 public class SQRelationCalculation extends Calculation { |
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
22 private static final Logger log = |
3072
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 Logger.getLogger(SQRelationCalculation.class); |
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
25 public static final String SQ_FUNCTION_NAME = "sq-pow"; |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
26 |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
27 protected String river; |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
28 protected double location; |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
29 protected DateRange period; |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
30 protected double outliers; |
3305
b24920235944
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3304
diff
changeset
|
31 |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
32 public SQRelationCalculation() { |
3079
8ad8a227d983
Added model classes for SQ calculation; generate fake results and improved the SQRelationGenerator which now draws the outliers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3072
diff
changeset
|
33 } |
8ad8a227d983
Added model classes for SQ calculation; generate fake results and improved the SQRelationGenerator which now draws the outliers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3072
diff
changeset
|
34 |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
35 public SQRelationCalculation(SQRelationAccess access) { |
3079
8ad8a227d983
Added model classes for SQ calculation; generate fake results and improved the SQRelationGenerator which now draws the outliers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3072
diff
changeset
|
36 |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
37 String river = access.getRiver(); |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
38 Double location = access.getLocation(); |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
39 DateRange period = access.getPeriod(); |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
40 Double outliers = access.getOutliers(); |
3101
b31397addf2f
Create Facets for each SQResult and SQFractionResult.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3079
diff
changeset
|
41 |
3390
1c9aaef89f51
SQ relation: Out commented debug output which caused OOM errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3389
diff
changeset
|
42 //river = "Rhein"; |
1c9aaef89f51
SQ relation: Out commented debug output which caused OOM errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3389
diff
changeset
|
43 |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
44 if (river == null) { |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
45 // TODO: i18n |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
46 addProblem("sq.missing.river"); |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
47 } |
3101
b31397addf2f
Create Facets for each SQResult and SQFractionResult.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3079
diff
changeset
|
48 |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
49 if (location == null) { |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
50 // TODO: i18n |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
51 addProblem("sq.missing.location"); |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
52 } |
3101
b31397addf2f
Create Facets for each SQResult and SQFractionResult.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3079
diff
changeset
|
53 |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
54 if (period == null) { |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
55 // TODO: i18n |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
56 addProblem("sq.missing.periods"); |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
57 } |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
58 |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
59 if (outliers == null) { |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
60 // TODO: i18n |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
61 addProblem("sq.missing.outliers"); |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
62 } |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
63 |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
64 if (!hasProblems()) { |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
65 this.river = river; |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
66 this.location = location; |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
67 this.period = period; |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
68 this.outliers = outliers; |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
69 } |
3079
8ad8a227d983
Added model classes for SQ calculation; generate fake results and improved the SQRelationGenerator which now draws the outliers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3072
diff
changeset
|
70 } |
8ad8a227d983
Added model classes for SQ calculation; generate fake results and improved the SQRelationGenerator which now draws the outliers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3072
diff
changeset
|
71 |
3105
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3101
diff
changeset
|
72 |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
73 public CalculationResult calculate() { |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
74 log.debug("SQRelationCalculation.calculate"); |
3079
8ad8a227d983
Added model classes for SQ calculation; generate fake results and improved the SQRelationGenerator which now draws the outliers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3072
diff
changeset
|
75 |
3222
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
76 if (hasProblems()) { |
116b342893e3
SQ: Connect calculation with artifact parameter access.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
77 return new CalculationResult(this); |
3118
6fb211753674
The fake calculation for SQ relation now creates only values bigger than 0.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3105
diff
changeset
|
78 } |
3079
8ad8a227d983
Added model classes for SQ calculation; generate fake results and improved the SQRelationGenerator which now draws the outliers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3072
diff
changeset
|
79 |
3289
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
80 SedDBSessionHolder.acquire(); |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
81 try { |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
82 return internalCalculate(); |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
83 } |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
84 finally { |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
85 SedDBSessionHolder.release(); |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
86 } |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
87 } |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
88 |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
89 protected CalculationResult internalCalculate() { |
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
90 |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
91 Function function = FunctionFactory |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
92 .getInstance() |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
93 .getFunction(SQ_FUNCTION_NAME); |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
94 |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
95 if (function == null) { |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
96 log.error("No '" + SQ_FUNCTION_NAME + "' function found."); |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
97 // TODO: i18n |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
98 addProblem("sq.missing.sq.function"); |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
99 } |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
100 |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
101 Measurements measurements = |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
102 MeasurementFactory.getMeasurements(river, location, period); |
3310
8af1111af180
SQ relation: More fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3305
diff
changeset
|
103 |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
104 SQFractionResult [] fractionResults = |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
105 new SQFractionResult[SQResult.NUMBER_FRACTIONS]; |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
106 |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
107 for (int i = 0; i < fractionResults.length; ++i) { |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
108 List<SQ> sqs = measurements.getSQs(i); |
3310
8af1111af180
SQ relation: More fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3305
diff
changeset
|
109 |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
110 SQFractionResult fractionResult; |
3310
8af1111af180
SQ relation: More fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3305
diff
changeset
|
111 |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
112 List<SQFractionResult.Iteration> iterations = |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
113 doFitting(function, sqs); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
114 |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
115 if (iterations == null) { |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
116 // TODO: i18n |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
117 addProblem("sq.fitting.failed." + i); |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
118 fractionResult = new SQFractionResult(); |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
119 } |
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
120 else { |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
121 fractionResult = new SQFractionResult( |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
122 sqs.toArray(new SQ[sqs.size()]), |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
123 iterations); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
124 } |
3310
8af1111af180
SQ relation: More fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3305
diff
changeset
|
125 |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
126 fractionResults[i] = fractionResult; |
3297
79c8e0d9fdea
SQ relation: Use only first time period.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3290
diff
changeset
|
127 } |
3289
ec9aab93f292
SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3222
diff
changeset
|
128 |
3310
8af1111af180
SQ relation: More fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3305
diff
changeset
|
129 return new CalculationResult( |
3426
e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3392
diff
changeset
|
130 new SQResult[] { new SQResult(location, fractionResults) }, |
3310
8af1111af180
SQ relation: More fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3305
diff
changeset
|
131 this); |
3072
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 } |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
133 |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
134 protected List<SQFractionResult.Iteration> doFitting( |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
135 final Function function, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
136 List<SQ> sqs |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
137 ) { |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
138 final List<SQFractionResult.Iteration> iterations = |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
139 new ArrayList<SQFractionResult.Iteration>(); |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
140 |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
141 boolean success = new Fitting(function, outliers).fit( |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
142 sqs, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
143 new Fitting.Callback() { |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
144 @Override |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
145 public void afterIteration( |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
146 double [] coeffs, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
147 SQ [] measurements, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
148 SQ [] outliers, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
149 double standardDeviation, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
150 double chiSqr |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
151 ) { |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
152 Parameters parameters = createParameters( |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
153 function.getParameterNames(), |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
154 coeffs, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
155 standardDeviation, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
156 chiSqr); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
157 iterations.add(new SQFractionResult.Iteration( |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
158 parameters, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
159 measurements, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
160 outliers)); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
161 } |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
162 }); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
163 |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
164 return success ? iterations : null; |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
165 } |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
166 |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
167 public static final Parameters createParameters( |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
168 String [] names, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
169 double [] values, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
170 double standardDeviation, |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
171 double chiSqr |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
172 ) { |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
173 String [] columns = new String[names.length + 2]; |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
174 columns[0] = "chi_sqr"; |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
175 columns[1] = "std_dev"; |
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
176 System.arraycopy(names, 0, columns, 2, names.length); |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
177 Parameters parameters = new Parameters(columns); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
178 int row = parameters.newRow(); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
179 parameters.set(row, names, values); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
180 parameters.set(row, "chi_sqr", chiSqr); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
181 parameters.set(row, "std_dev", standardDeviation); |
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3426
diff
changeset
|
182 return parameters; |
3304
02d5731b43a2
SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3297
diff
changeset
|
183 } |
3072
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
184 } |
0d3dd8230064
Added component stubs for SQ relation calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
185 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |