comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SQRelationCalculation.java @ 3222:116b342893e3

SQ: Connect calculation with artifact parameter access. flys-artifacts/trunk@4845 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 01 Jul 2012 18:00:04 +0000
parents 6fb211753674
children ec9aab93f292
comparison
equal deleted inserted replaced
3221:06ae0258269b 3222:116b342893e3
1 package de.intevation.flys.artifacts.model.sq; 1 package de.intevation.flys.artifacts.model.sq;
2 2
3 import java.util.ArrayList; 3 import de.intevation.flys.artifacts.access.SQRelationAccess;
4 import java.util.List; 4
5 import de.intevation.flys.artifacts.model.Calculation;
6 import de.intevation.flys.artifacts.model.CalculationResult;
7 import de.intevation.flys.artifacts.model.DateRange;
5 8
6 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
7 10
8 import de.intevation.flys.artifacts.model.Calculation;
9 import de.intevation.flys.artifacts.model.CalculationResult;
10 import de.intevation.flys.artifacts.model.Parameters;
11
12 import de.intevation.flys.artifacts.MINFOArtifact;
13
14
15 public class SQRelationCalculation extends Calculation { 11 public class SQRelationCalculation extends Calculation {
16 12
17 private static final Logger logger = 13 private static final Logger log =
18 Logger.getLogger(SQRelationCalculation.class); 14 Logger.getLogger(SQRelationCalculation.class);
19 15
16 protected String river;
17 protected double location;
18 protected DateRange [] periods;
19 protected double outliers;
20 20
21 public CalculationResult calculate(MINFOArtifact artifact) { 21 public SQRelationCalculation() {
22 logger.info("SQRelationCalculation.calculate"); 22 }
23 23
24 // TODO Collect input params and use them for buildCalculationResult() 24 public SQRelationCalculation(SQRelationAccess access) {
25 25
26 return buildCalculationResult(); 26 String river = access.getRiver();
27 Double location = access.getLocation();
28 DateRange [] periods = access.getPeriods();
29 Double outliers = access.getOutliers();
30
31 if (river == null) {
32 // TODO: i18n
33 addProblem("sq.missing.river");
34 }
35
36 if (location == null) {
37 // TODO: i18n
38 addProblem("sq.missing.location");
39 }
40
41 if (periods == null) {
42 // TODO: i18n
43 addProblem("sq.missing.periods");
44 }
45
46 if (outliers == null) {
47 // TODO: i18n
48 addProblem("sq.missing.outliers");
49 }
50
51 if (!hasProblems()) {
52 this.river = river;
53 this.location = location;
54 this.periods = periods;
55 this.outliers = outliers;
56 }
27 } 57 }
28 58
29 59
30 protected CalculationResult buildCalculationResult( 60 public CalculationResult calculate() {
31 // TODO Insert input params here 61 log.debug("SQRelationCalculation.calculate");
32 ) {
33 logger.info("SQRelationCalculation.buildCalculationResult");
34 logger.error("Not implemented!");
35 62
36 SQResult[] result = getFakeResult(); 63 if (hasProblems()) {
64 return new CalculationResult(this);
65 }
66
67 SQResult [] result = null;
68
69 // TODO: Implement me!
37 70
38 return new CalculationResult(result, this); 71 return new CalculationResult(result, this);
39 } 72 }
40
41
42 protected SQResult[] getFakeResult() {
43
44 Parameters params = getFakeParameters();
45 SQ[] measurements = getFakeMeasurements();
46 SQ[] fOutliers = getFakeOutliers(10);
47 SQ[] tOutliers = getFakeOutliers(20);
48
49 List<SQ[]> outliers = new ArrayList<SQ[]>();
50 outliers.add(fOutliers);
51 outliers.add(tOutliers);
52
53 SQResult res = new SQResult();
54
55 res.setFraction(
56 SQResult.FRACTION_A,
57 new SQFractionResult(params, measurements, outliers));
58
59 res.setFraction(
60 SQResult.FRACTION_B,
61 new SQFractionResult(params, measurements, outliers));
62
63 res.setFraction(
64 SQResult.FRACTION_C,
65 new SQFractionResult(params, measurements, outliers));
66
67 return new SQResult[] { res };
68 }
69
70
71 protected Parameters getFakeParameters() {
72 Parameters params = new Parameters(new String[] {
73 "a",
74 "b"
75 });
76
77 params.set(0, 0, 0.0082);
78 params.set(0, 1, 1.09);
79
80 return params;
81 }
82
83
84 protected SQ[] getFakeMeasurements() {
85 List<SQ> a = new ArrayList<SQ>();
86
87 a.add(new SQ(11.172500000000001, 1250.0));
88 a.add(new SQ(13.407000000000002, 1500.0));
89 a.add(new SQ(15.641500000000002, 1750.0));
90 a.add(new SQ(17.876000000000005, 2000.0));
91 a.add(new SQ(20.110500000000005, 2250.0));
92 a.add(new SQ(22.345000000000002, 2500.0));
93 a.add(new SQ(24.579500000000003, 2750.0));
94 a.add(new SQ(26.814000000000004, 3000.0));
95 a.add(new SQ(29.048500000000004, 3250.0));
96 a.add(new SQ(31.283000000000005, 3500.0));
97 a.add(new SQ(33.517500000000005, 3750.0));
98 a.add(new SQ(35.75200000000001, 4000.0));
99 a.add(new SQ(37.98650000000001, 4250.0));
100 a.add(new SQ(40.22100000000001, 4500.0));
101 a.add(new SQ(42.45550000000001, 4750.0));
102
103 return (SQ[]) a.toArray(new SQ[a.size()]);
104 }
105
106
107 protected SQ[] getFakeOutliers(int diff) {
108 List<SQ> a = new ArrayList<SQ>();
109
110 double[][] values = new double[15][2];
111
112 values[0][0] = 11.172500000000001-diff;
113 values[0][1] = 1250.0;
114 values[1][0] = 13.407000000000002+diff;
115 values[1][1] = 1500.0;
116 values[2][0] = 25.641500000000002-diff;
117 values[2][1] = 1750.0;
118 values[3][0] = 17.876000000000005+diff;
119 values[3][1] = 2000.0;
120 values[4][0] = 20.110500000000005-diff;
121 values[4][1] = 2250.0;
122 values[5][0] = 22.345000000000002+diff;
123 values[5][1] = 2500.0;
124 values[6][0] = 24.579500000000003-diff;
125 values[6][1] = 2750.0;
126 values[7][0] = 26.814000000000004+diff;
127 values[7][1] = 3000.0;
128 values[8][0] = 29.048500000000004-diff;
129 values[8][1] = 3250.0;
130 values[9][0] = 31.283000000000005+diff;
131 values[9][1] = 3500.0;
132 values[10][0] = 33.517500000000005-diff;
133 values[10][1] = 3750.0;
134 values[11][0] = 35.75200000000001-diff;
135 values[11][1] = 4000.0;
136 values[12][0] = 37.98650000000001+diff;
137 values[12][1] = 4250.0;
138 values[13][0] = 40.22100000000001+diff;
139 values[13][1] = 4500.0;
140 values[14][0] = 42.45550000000001+diff;
141 values[14][1] = 4750.0;
142
143 for (double[] value: values) {
144 double s = value[0];
145 double q = value[1];
146
147 s = s > 0 ? s : s * -1;
148 q = q > 0 ? q : q * -1;
149
150 a.add(new SQ(s, q));
151 }
152
153 return (SQ[]) a.toArray(new SQ[a.size()]);
154 }
155 } 73 }
156 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 74 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org