Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java @ 201:3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
flys-backend/trunk@1549 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 23 Mar 2011 15:22:32 +0000 |
parents | 88048d4f6e4d |
children | 29a408f80a89 |
comparison
equal
deleted
inserted
replaced
200:88048d4f6e4d | 201:3169b559ca3c |
---|---|
17 import de.intevation.flys.utils.StringUtil; | 17 import de.intevation.flys.utils.StringUtil; |
18 | 18 |
19 import java.util.regex.Pattern; | 19 import java.util.regex.Pattern; |
20 import java.util.regex.Matcher; | 20 import java.util.regex.Matcher; |
21 | 21 |
22 import java.math.BigDecimal; | |
23 | |
22 public class WstParser | 24 public class WstParser |
23 { | 25 { |
24 private static Logger log = Logger.getLogger(WstParser.class); | 26 private static Logger log = Logger.getLogger(WstParser.class); |
25 | 27 |
26 public static final String COLUMN_BEZ_TEXT = "column-bez-text"; | 28 public static final String COLUMN_BEZ_TEXT = "column-bez-text"; |
36 Pattern.compile("\\*\\s*[kK][mM]\\s+(.+)"); | 38 Pattern.compile("\\*\\s*[kK][mM]\\s+(.+)"); |
37 | 39 |
38 public static final Pattern UNIT = | 40 public static final Pattern UNIT = |
39 Pattern.compile("[^\\[]*\\[([^]]+)\\].*"); | 41 Pattern.compile("[^\\[]*\\[([^]]+)\\].*"); |
40 | 42 |
43 protected ImportWst wst; | |
44 | |
41 public WstParser() { | 45 public WstParser() { |
42 } | 46 } |
43 | 47 |
48 public ImportWst getWst() { | |
49 return wst; | |
50 } | |
51 | |
52 public void setWst(ImportWst wst) { | |
53 this.wst = wst; | |
54 } | |
55 | |
44 public void parse(File file) throws IOException { | 56 public void parse(File file) throws IOException { |
45 | 57 |
46 log.info("Parsing WST file '" + file + "'"); | 58 log.info("Parsing WST file '" + file + "'"); |
59 | |
60 wst = new ImportWst(file.getName()); | |
47 | 61 |
48 LineNumberReader in = null; | 62 LineNumberReader in = null; |
49 try { | 63 try { |
50 in = | 64 in = |
51 new LineNumberReader( | 65 new LineNumberReader( |
66 double [] firstAbfluesse = null; | 80 double [] firstAbfluesse = null; |
67 | 81 |
68 double minKm = Double.MAX_VALUE; | 82 double minKm = Double.MAX_VALUE; |
69 double maxKm = -Double.MAX_VALUE; | 83 double maxKm = -Double.MAX_VALUE; |
70 | 84 |
71 boolean bFirstComment = true; | |
72 boolean columnHeaderChecked = false; | 85 boolean columnHeaderChecked = false; |
73 | 86 |
74 double lastKm = Double.MAX_VALUE; | 87 double lastKm = Double.MAX_VALUE; |
75 | 88 |
76 String einheit = "Wasserstand [NN + m]"; | 89 String einheit = "Wasserstand [NN + m]"; |
278 | 291 |
279 protected void addValue(double km, double w, String columnName) { | 292 protected void addValue(double km, double w, String columnName) { |
280 // TODO: store me! | 293 // TODO: store me! |
281 } | 294 } |
282 | 295 |
283 protected static String format(double value) { | 296 private static final NumberFormat NF = getNumberFormat(); |
297 | |
298 private static getNumberFormat() { | |
284 NumberFormat nf = NumberFormat.getInstance(); | 299 NumberFormat nf = NumberFormat.getInstance(); |
285 nf.setMinimumFractionDigits(2); | 300 nf.setMinimumFractionDigits(2); |
286 nf.setMaximumFractionDigits(2); | 301 nf.setMaximumFractionDigits(2); |
287 return nf.format(value); | 302 } |
303 | |
304 protected static String format(double value) { | |
305 return NF.format(value); | |
288 } | 306 } |
289 | 307 |
290 protected void addInterval( | 308 protected void addInterval( |
291 double from, | 309 double from, |
292 double to, | 310 double to, |
293 Map<String, Double> values | 311 Map<String, Double> values |
294 ) { | 312 ) { |
313 log.debug("addInterval: " + from + " " + to); | |
314 | |
295 if (values == null) { | 315 if (values == null) { |
296 return; | 316 return; |
297 } | 317 } |
298 if (log.isDebugEnabled()) { | 318 |
299 log.debug("addInterval: " + from + " " + to); | 319 if (from > to) { double t = from; from = to; to = t; } |
300 StringBuilder sb = new StringBuilder(); | 320 |
301 for (Map.Entry<String, Double> entry: values.entrySet()) { | 321 ImportRange range = new ImportRange( |
302 if (sb.length() > 0) { | 322 new BigDecimal(from), |
303 sb.append("; "); | 323 new BigDecimal(to)); |
304 } | 324 |
305 sb.append('"').append(entry.getKey()) | 325 for (Map.Entry<String, Double> entry: values.entrySet()) { |
306 .append("\": ") | 326 BigDecimal q = new BigDecimal(entry.getValue()); |
307 .append(entry.getValue()); | 327 ImportWstQRange wstQRange = new ImportWstQRange(range, q); |
308 } | 328 |
309 log.debug("entries: " + sb.toString()); | 329 String columnName = entry.getKey(); |
330 ImportWstColumn column = wst.getColumn(columnName); | |
331 column.addColumnQRange(wstQRange); | |
310 } | 332 } |
311 } | 333 } |
312 | 334 |
313 private static final Double [] parseLineAsDouble( | 335 private static final Double [] parseLineAsDouble( |
314 String line, | 336 String line, |