comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCalculation.java @ 3877:00abcd3737f9

Some more little steps towards "Auslagerung extremer Wasserspiegellagen". flys-artifacts/trunk@5512 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 18 Sep 2012 18:36:52 +0000
parents d52c4ca93ffb
children 363445873737
comparison
equal deleted inserted replaced
3876:c0a15547ad76 3877:00abcd3737f9
1 package de.intevation.flys.artifacts.model.extreme; 1 package de.intevation.flys.artifacts.model.extreme;
2 2
3 import de.intevation.flys.artifacts.access.ExtremeAccess; 3 import de.intevation.flys.artifacts.access.ExtremeAccess;
4 4
5 import de.intevation.flys.artifacts.math.fitting.Function;
6 import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
7
5 import de.intevation.flys.artifacts.model.Calculation; 8 import de.intevation.flys.artifacts.model.Calculation;
6 import de.intevation.flys.artifacts.model.CalculationResult; 9 import de.intevation.flys.artifacts.model.CalculationResult;
10 import de.intevation.flys.artifacts.model.RangeWithValues;
11 import de.intevation.flys.artifacts.model.RiverFactory;
12 import de.intevation.flys.artifacts.model.WstValueTable;
13 import de.intevation.flys.artifacts.model.WstValueTableFactory;
14
15 import de.intevation.flys.model.River;
16
17 import de.intevation.flys.utils.DoubleUtil;
18
19 import java.util.List;
7 20
8 public class ExtremeCalculation 21 public class ExtremeCalculation
9 extends Calculation 22 extends Calculation
10 { 23 {
24 protected String river;
25 protected String function;
26 protected double from;
27 protected double to;
28 protected double step;
29 protected double percent;
30 protected List<RangeWithValues> ranges;
31
11 public ExtremeCalculation() { 32 public ExtremeCalculation() {
12 } 33 }
13 34
14 public ExtremeCalculation(ExtremeAccess access) { 35 public ExtremeCalculation(ExtremeAccess access) {
15 // TODO: Implement me! 36 String river = access.getRiver();
37 String function = access.getFunction();
38 Double from = access.getFrom();
39 Double to = access.getTo();
40 Double step = access.getStep();
41 Double percent = access.getPercent();
42 List<RangeWithValues> ranges = access.getRanges();
43
44 if (river == null) {
45 // TODO: i18n
46 addProblem("extreme.no.river");
47 }
48
49 if (function == null) {
50 // TODO: i18n
51 addProblem("extreme.no.function");
52 }
53
54 if (from == null) {
55 // TODO: i18n
56 addProblem("extreme.no.from");
57 }
58
59 if (to == null) {
60 // TODO: i18n
61 addProblem("extreme.no.to");
62 }
63
64 if (step == null) {
65 // TODO: i18n
66 addProblem("extreme.no.step");
67 }
68
69 if (percent == null) {
70 // TODO: i18n
71 addProblem("extreme.no.percent");
72 }
73
74 if (ranges == null) {
75 // TODO: i18n
76 addProblem("extreme.no.ranges");
77 }
78
79 if (!hasProblems()) {
80 this.river = river;
81 this.function = function;
82 this.from = Math.min(from, to);
83 this.to = Math.max(from, to);
84 this.step = Math.max(0.001d, Math.abs(step)/1000d);
85 this.percent = Math.max(0d, Math.min(100d, percent));
86 this.ranges = ranges;
87 }
16 } 88 }
17 89
18 public CalculationResult calculate() { 90 public CalculationResult calculate() {
19 if (hasProblems()) { 91
20 return new CalculationResult(this); 92 WstValueTable wst = null;
93
94 River river = RiverFactory.getRiver(this.river);
95 if (river == null) {
96 // TODO: i18n
97 addProblem("extreme.no.such.river", this.river);
21 } 98 }
22 // TODO: Implement me! 99 else {
100 wst = WstValueTableFactory.getTable(river);
101 if (wst == null) {
102 // TODO: i18n
103 addProblem("extreme.no.wst.table");
104 }
105 }
106
107 Function function =
108 FunctionFactory.getInstance().getFunction(this.function);
109 if (function == null) {
110 // TODO: i18n
111 addProblem("extreme.no.such.function", this.function);
112 }
113
114 return hasProblems()
115 ? new CalculationResult(this)
116 : innerCalculate(wst, function);
117 }
118
119 protected CalculationResult innerCalculate(
120 WstValueTable wst,
121 Function function
122 ) {
123 RangeWithValues range = null;
124
125 KMs: for (double km = from; km <= to; km += step) {
126 double currentKm = DoubleUtil.round(km);
127
128 if (range == null || !range.inside(currentKm)) {
129 for (RangeWithValues r: ranges) {
130 if (r.inside(currentKm)) {
131 range = r;
132 break;
133 }
134 }
135 // TODO: i18n
136 addProblem(currentKm, "extreme.no.range");
137 continue KMs;
138 }
139
140 double [][] wqs = wst.interpolateTabulated(currentKm);
141 if (wqs == null) {
142 // TODO: i18n
143 addProblem(currentKm, "extreme.no.raw.data");
144 continue;
145 }
146
147 // XXX: This should not be necessary for model data.
148 if (!DoubleUtil.isValid(wqs)) {
149 // TODO: i18n
150 addProblem(currentKm, "extreme.invalid.data");
151 continue;
152 }
153 // TODO: Implement extraction of points for curve fitting.
154 // TODO: Implement curve fitting.
155 // TODO: Implement generating Curve object per km.
156 }
157
23 ExtremeResult result = new ExtremeResult(); 158 ExtremeResult result = new ExtremeResult();
24
25 return new CalculationResult(result, this); 159 return new CalculationResult(result, this);
26 } 160 }
27 } 161 }
28 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 162 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org