Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java @ 3426:e7a67407dea1
Limited the input of time periods in SQ relation calculation to 1.
flys-artifacts/trunk@5082 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 20 Jul 2012 09:34:47 +0000 |
parents | 56f62b5209f5 |
children | 1df6984628c3 |
comparison
equal
deleted
inserted
replaced
3425:7babd4e92c8b | 3426:e7a67407dea1 |
---|---|
10 import de.intevation.flys.artifacts.model.DateRange; | 10 import de.intevation.flys.artifacts.model.DateRange; |
11 import de.intevation.flys.artifacts.model.Parameters; | 11 import de.intevation.flys.artifacts.model.Parameters; |
12 | 12 |
13 import de.intevation.flys.backend.SedDBSessionHolder; | 13 import de.intevation.flys.backend.SedDBSessionHolder; |
14 | 14 |
15 import java.util.ArrayList; | |
16 import java.util.List; | 15 import java.util.List; |
17 | 16 |
18 import org.apache.log4j.Logger; | 17 import org.apache.log4j.Logger; |
19 | 18 |
20 public class SQRelationCalculation extends Calculation { | 19 public class SQRelationCalculation extends Calculation { |
22 private static final Logger log = | 21 private static final Logger log = |
23 Logger.getLogger(SQRelationCalculation.class); | 22 Logger.getLogger(SQRelationCalculation.class); |
24 | 23 |
25 public static final String SQ_FUNCTION_NAME = "sq-pow"; | 24 public static final String SQ_FUNCTION_NAME = "sq-pow"; |
26 | 25 |
27 protected String river; | 26 protected String river; |
28 protected double location; | 27 protected double location; |
29 protected DateRange [] periods; | 28 protected DateRange period; |
30 protected double outliers; | 29 protected double outliers; |
31 | 30 |
32 public SQRelationCalculation() { | 31 public SQRelationCalculation() { |
33 } | 32 } |
34 | 33 |
35 public SQRelationCalculation(SQRelationAccess access) { | 34 public SQRelationCalculation(SQRelationAccess access) { |
36 | 35 |
37 String river = access.getRiver(); | 36 String river = access.getRiver(); |
38 Double location = access.getLocation(); | 37 Double location = access.getLocation(); |
39 DateRange [] periods = access.getPeriods(); | 38 DateRange period = access.getPeriod(); |
40 Double outliers = access.getOutliers(); | 39 Double outliers = access.getOutliers(); |
41 | 40 |
42 //river = "Rhein"; | 41 //river = "Rhein"; |
43 | 42 |
44 if (river == null) { | 43 if (river == null) { |
45 // TODO: i18n | 44 // TODO: i18n |
49 if (location == null) { | 48 if (location == null) { |
50 // TODO: i18n | 49 // TODO: i18n |
51 addProblem("sq.missing.location"); | 50 addProblem("sq.missing.location"); |
52 } | 51 } |
53 | 52 |
54 if (periods == null || periods.length == 0) { | 53 if (period == null) { |
55 // TODO: i18n | 54 // TODO: i18n |
56 addProblem("sq.missing.periods"); | 55 addProblem("sq.missing.periods"); |
57 } | 56 } |
58 | 57 |
59 if (outliers == null) { | 58 if (outliers == null) { |
62 } | 61 } |
63 | 62 |
64 if (!hasProblems()) { | 63 if (!hasProblems()) { |
65 this.river = river; | 64 this.river = river; |
66 this.location = location; | 65 this.location = location; |
67 this.periods = periods; | 66 this.period = period; |
68 this.outliers = outliers; | 67 this.outliers = outliers; |
69 } | 68 } |
70 } | 69 } |
71 | 70 |
72 | 71 |
101 } | 100 } |
102 | 101 |
103 | 102 |
104 String [] parameterNames = function.getParameterNames(); | 103 String [] parameterNames = function.getParameterNames(); |
105 | 104 |
106 List<SQResult> results = new ArrayList<SQResult>(periods.length); | |
107 | |
108 Fitting fitting = new Fitting(function, outliers); | 105 Fitting fitting = new Fitting(function, outliers); |
109 | 106 |
110 for (DateRange period: periods) { | |
111 Measurements measurements = | 107 Measurements measurements = |
112 MeasurementFactory.getMeasurements(river, location, period); | 108 MeasurementFactory.getMeasurements(river, location, period); |
113 | 109 |
114 /* | 110 SQFractionResult [] fractionResults = |
115 if (debug) { | 111 new SQFractionResult[SQResult.NUMBER_FRACTIONS]; |
116 log.debug(measurements.toString()); | 112 |
113 for (int i = 0; i < fractionResults.length; ++i) { | |
114 List<SQ> sqs = measurements.getSQs(i); | |
115 | |
116 SQFractionResult fractionResult; | |
117 | |
118 if (!fitting.fit(sqs)) { | |
119 // TODO: i18n | |
120 addProblem("sq.fitting.failed." + i); | |
121 fractionResult = new SQFractionResult(); | |
117 } | 122 } |
118 */ | 123 else { |
124 Parameters parameters = createParameters(parameterNames); | |
125 int row = parameters.newRow(); | |
126 double [] coeffs = fitting.getParameters(); | |
127 for (int j = 0; j < parameterNames.length; ++j) { | |
128 parameters.set(row, parameterNames[j], coeffs[j]); | |
129 } | |
130 parameters.set(row, "chi_sqr", fitting.getChiSqr()); | |
131 parameters.set(row, "std_dev", fitting.getStandardDeviation()); | |
119 | 132 |
120 SQFractionResult [] fractionResults = | 133 fractionResult = new SQFractionResult( |
121 new SQFractionResult[SQResult.NUMBER_FRACTIONS]; | 134 parameters, |
122 | 135 fitting.getRemaining(), |
123 for (int i = 0; i < fractionResults.length; ++i) { | 136 fitting.getOutliers()); |
124 List<SQ> sqs = measurements.getSQs(i); | |
125 | |
126 SQFractionResult fractionResult; | |
127 | |
128 if (!fitting.fit(sqs)) { | |
129 // TODO: i18n | |
130 addProblem("sq.fitting.failed." + i); | |
131 fractionResult = new SQFractionResult(); | |
132 } | |
133 else { | |
134 Parameters parameters = createParameters(parameterNames); | |
135 int row = parameters.newRow(); | |
136 double [] coeffs = fitting.getParameters(); | |
137 for (int j = 0; j < parameterNames.length; ++j) { | |
138 parameters.set(row, parameterNames[j], coeffs[j]); | |
139 } | |
140 parameters.set(row, "chi_sqr", fitting.getChiSqr()); | |
141 parameters.set(row, "std_dev", fitting.getStandardDeviation()); | |
142 | |
143 fractionResult = new SQFractionResult( | |
144 parameters, | |
145 fitting.getRemaining(), | |
146 fitting.getOutliers()); | |
147 } | |
148 fitting.reset(); | |
149 fractionResults[i] = fractionResult; | |
150 } | 137 } |
151 results.add(new SQResult(location, fractionResults)); | 138 fitting.reset(); |
139 fractionResults[i] = fractionResult; | |
152 } | 140 } |
153 | 141 |
154 return new CalculationResult( | 142 return new CalculationResult( |
155 results.toArray(new SQResult[results.size()]), | 143 new SQResult[] { new SQResult(location, fractionResults) }, |
156 this); | 144 this); |
157 } | 145 } |
158 | 146 |
159 public static final Parameters createParameters(String [] names) { | 147 public static final Parameters createParameters(String [] names) { |
160 | 148 |