Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java @ 8055:cd35b76f1ef8
Sediment load. More off year based calculations.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 18 Jul 2014 13:03:28 +0200 |
parents | 72760ca2fc2b |
children | 555dc5a9b282 |
comparison
equal
deleted
inserted
replaced
8054:db4e6bd367a6 | 8055:cd35b76f1ef8 |
---|---|
7 */ | 7 */ |
8 package org.dive4elements.river.artifacts.model.minfo; | 8 package org.dive4elements.river.artifacts.model.minfo; |
9 | 9 |
10 import java.util.List; | 10 import java.util.List; |
11 import java.util.Set; | 11 import java.util.Set; |
12 import java.util.TreeSet; | |
12 | 13 |
13 import org.dive4elements.river.artifacts.access.SedimentLoadAccess; | 14 import org.dive4elements.river.artifacts.access.SedimentLoadAccess; |
14 import org.dive4elements.river.artifacts.model.Calculation; | 15 import org.dive4elements.river.artifacts.model.Calculation; |
15 import org.dive4elements.river.artifacts.model.CalculationResult; | 16 import org.dive4elements.river.artifacts.model.CalculationResult; |
16 import org.dive4elements.river.artifacts.model.RiverFactory; | 17 import org.dive4elements.river.artifacts.model.RiverFactory; |
17 import org.apache.log4j.Logger; | 18 import org.apache.log4j.Logger; |
18 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData; | 19 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData; |
19 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Value; | 20 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Value; |
20 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station; | 21 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station; |
22 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.And; | |
23 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.IsEpoch; | |
24 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.Not; | |
25 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.TimeRangeIntersects; | |
21 import org.dive4elements.river.model.River; | 26 import org.dive4elements.river.model.River; |
22 import org.dive4elements.river.utils.DoubleUtil; | 27 import org.dive4elements.river.utils.DoubleUtil; |
23 | 28 |
24 public class SedimentLoadDataCalculation | 29 public class SedimentLoadDataCalculation |
25 extends Calculation | 30 extends Calculation |
81 | 86 |
82 public static final int [] SUSP_SEDIMENT_FLYS = { | 87 public static final int [] SUSP_SEDIMENT_FLYS = { |
83 SedimentLoadData.GF_SUSP_SEDIMENT | 88 SedimentLoadData.GF_SUSP_SEDIMENT |
84 }; | 89 }; |
85 | 90 |
91 public static final class GrainFraction { | |
92 private String description; | |
93 private int [] grainFractions; | |
94 | |
95 public GrainFraction(String description, int [] grainFractions) { | |
96 this.description = description; | |
97 this.grainFractions = grainFractions; | |
98 } | |
99 public static final GrainFraction make(String description, int [] grainFractions) { | |
100 return new GrainFraction(description, grainFractions); | |
101 } | |
102 | |
103 public String getDescription() { | |
104 return description; | |
105 } | |
106 | |
107 public int [] getGrainFractions() { | |
108 return grainFractions; | |
109 } | |
110 } // class GrainFraction | |
111 | |
112 public static final GrainFraction [] GRAIN_FRACTIONS = { | |
113 // TODO: i18n | |
114 GrainFraction.make("minfo.total.load.flys", TOTAL_LOAD_FLYS), | |
115 GrainFraction.make("minfo.bed.load.flys", BED_LOAD_FLYS), | |
116 GrainFraction.make("minfo.bed.load.susp.sand.flys", BED_LOAD_SUSP_SAND_FLYS), | |
117 GrainFraction.make("minfo.total.load.bfg", TOTAL_LOAD_BFG), | |
118 GrainFraction.make("minfo.bed.load.bfg", BED_LOAD_BFG), | |
119 GrainFraction.make("minfo.suspended.load.bfg", SUSPENDED_LOAD_BFG), | |
120 GrainFraction.make("minfo.coarse.flys", COARSE_FLYS), | |
121 GrainFraction.make("minfo.fine.middle.flys", FINE_MIDDLE_FLYS), | |
122 GrainFraction.make("minfo.sand.flys", SAND_FLYS) , | |
123 GrainFraction.make("minfo.susp.sand.flys", SUSP_SAND_FLYS), | |
124 GrainFraction.make("minfo.susp.sand.bed.flys", SUSP_SAND_BED_FLYS), | |
125 GrainFraction.make("minfo.susp.sediment.flys", SUSP_SEDIMENT_FLYS), | |
126 }; | |
127 | |
86 public static final class Sum implements Value.Visitor { | 128 public static final class Sum implements Value.Visitor { |
87 | 129 |
88 private int n; | 130 private int n; |
89 private double sum; | 131 private double sum; |
90 private double scale; | 132 private double scale; |
122 | 164 |
123 | 165 |
124 private String river; | 166 private String river; |
125 private String yearEpoch; | 167 private String yearEpoch; |
126 private String unit; | 168 private String unit; |
127 private int [][] epoch; | 169 private int [][] epochs; |
128 private int [] period; | 170 private int [] years; |
129 private double from; | 171 private double from; |
130 private double to; | 172 private double to; |
131 | 173 |
132 | 174 |
133 public SedimentLoadDataCalculation() { | 175 public SedimentLoadDataCalculation() { |
138 | 180 |
139 String river = access.getRiverName(); | 181 String river = access.getRiverName(); |
140 String yearEpoch = access.getYearEpoch(); | 182 String yearEpoch = access.getYearEpoch(); |
141 String unit = access.getUnit(); | 183 String unit = access.getUnit(); |
142 | 184 |
143 int [] period = null; | 185 int [] years = null; |
144 int [][] epoch = null; | 186 int [][] epochs = null; |
145 | 187 |
146 double from = access.getUpperKM(); | 188 double from = access.getUpperKM(); |
147 double to = access.getLowerKM(); | 189 double to = access.getLowerKM(); |
148 | 190 |
149 if (yearEpoch.equals("year")) { | 191 if (yearEpoch.equals("year")) { |
150 period = access.getPeriod(); | 192 years = access.getPeriod(); |
151 } | 193 } |
152 else if (yearEpoch.equals("epoch") || yearEpoch.equals("off_epoch")) { | 194 else if (yearEpoch.equals("epoch") || yearEpoch.equals("off_epoch")) { |
153 epoch = access.getEpochs(); | 195 epochs = access.getEpochs(); |
154 } | 196 } |
155 else { | 197 else { |
156 addProblem("minfo.missing.year_epoch"); | 198 addProblem("minfo.missing.year_epoch"); |
157 } | 199 } |
158 | 200 |
159 if (river == null) { | 201 if (river == null) { |
160 // TODO: i18n | 202 // TODO: i18n |
161 addProblem("minfo.missing.river"); | 203 addProblem("minfo.missing.river"); |
162 } | 204 } |
163 | 205 |
164 if (period == null && epoch == null) { | 206 if (years == null && epochs == null) { |
165 addProblem("minfo.missing.time"); | 207 addProblem("minfo.missing.time"); |
166 } | 208 } |
167 | 209 |
168 if (!hasProblems()) { | 210 if (!hasProblems()) { |
169 this.river = river; | 211 this.river = river; |
170 this.yearEpoch = yearEpoch; | 212 this.yearEpoch = yearEpoch; |
171 this.unit = unit; | 213 this.unit = unit; |
172 this.period = period; | 214 this.years = years; |
173 this.epoch = epoch; | 215 this.epochs = epochs; |
174 this.from = from; | 216 this.from = from; |
175 this.to = to; | 217 this.to = to; |
176 return internalCalculate(); | 218 return internalCalculate(); |
177 } | 219 } |
178 | 220 |
221 return error(null); | |
222 } | |
223 | |
224 private CalculationResult error(String msg) { | |
225 if (msg != null) addProblem(msg); | |
179 return new CalculationResult(this); | 226 return new CalculationResult(this); |
180 } | 227 } |
181 | 228 |
182 private CalculationResult internalCalculate() { | 229 private CalculationResult internalCalculate() { |
183 if ("year".equals(yearEpoch)) return calculateYears(); | 230 if ("year".equals(yearEpoch)) return calculateYears(); |
184 if ("epoch".equals(yearEpoch)) return calculateEpochs(); | 231 if ("epoch".equals(yearEpoch)) return calculateEpochs(); |
185 if ("off_epoch".equals(yearEpoch)) return calculateOffEpochs(); | 232 if ("off_epoch".equals(yearEpoch)) return calculateOffEpochs(); |
186 | 233 |
187 // TODO: i18n | 234 // TODO: i18n |
188 addProblem("minfo.sediment.load.unknown.calc.mode"); | 235 return error("minfo.sediment.load.unknown.calc.mode"); |
189 | |
190 return new CalculationResult(this); | |
191 } | 236 } |
192 | 237 |
193 private CalculationResult calculateYears() { | 238 private CalculationResult calculateYears() { |
194 // TODO: Implement me! | 239 boolean isKmUp = isKmUp(); |
240 SedimentLoadData sld = | |
241 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); | |
242 if (sld == null) { | |
243 // TODO: i18n | |
244 return error("minfo.sediment.load.no.data"); | |
245 } | |
246 | |
247 Set<Integer> missingFractions = new TreeSet<Integer>(); | |
248 | |
249 Not notEpochs = new Not(IsEpoch.INSTANCE); | |
250 | |
251 Sum sum = new Sum(); | |
252 | |
253 for (int year: years) { | |
254 Value.Filter filter = new And() | |
255 .add(notEpochs) | |
256 .add(new TimeRangeIntersects(year)); | |
257 | |
258 for (GrainFraction gf: GRAIN_FRACTIONS) { | |
259 double [][] result = sum( | |
260 sld, gf.getGrainFractions(), filter, sum, isKmUp, | |
261 missingFractions); | |
262 | |
263 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { | |
264 // TODO: resolve i18n | |
265 addProblem("minfo.sediment.load.no.fractions", | |
266 gf.getDescription()); | |
267 continue; | |
268 } | |
269 // TODO: Generate result data set for calculation. | |
270 } | |
271 } | |
272 // TODO: Generate messages for missing fractions. | |
273 | |
195 return null; | 274 return null; |
196 } | 275 } |
197 | 276 |
198 private CalculationResult calculateEpochs() { | 277 private CalculationResult calculateEpochs() { |
199 // TODO: Implement me! | 278 // TODO: Implement me! |