comparison backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java @ 7377:ad2fdc34910a

Importer: Avoid 0-lenght Q-ranges in WST-CSV-parsers.
author Tom Gottfried <tom@intevation.de>
date Thu, 17 Oct 2013 17:47:58 +0200
parents e032e9e6d09e
children fc8d5b5f2c99
comparison
equal deleted inserted replaced
7376:4b26fd60105f 7377:ad2fdc34910a
44 Pattern.compile("^Einheit: \\[(.*)\\].*"); 44 Pattern.compile("^Einheit: \\[(.*)\\].*");
45 45
46 public static final Pattern YEARS_IN_COLUMN = 46 public static final Pattern YEARS_IN_COLUMN =
47 Pattern.compile(".*(\\d{4})-(\\d{4})$"); 47 Pattern.compile(".*(\\d{4})-(\\d{4})$");
48 48
49 public static final double INTERVAL_GAP = 0.00001d;
50
49 /** List of parsed differences as ImportWst s. */ 51 /** List of parsed differences as ImportWst s. */
50 private List<ImportWst> differences; 52 private List<ImportWst> differences;
51 53
52 private ImportWstColumn[] columns; 54 private ImportWstColumn[] columns;
53 55
96 98
97 differences.add(current); 99 differences.add(current);
98 } 100 }
99 101
100 // For all differences columns, add a single Q-Range with 102 // For all differences columns, add a single Q-Range with
101 // 0. 103 // -1.
104 // Expand range to minimal length in case it would be 0
105 // TODO: should otherwise be extended to
106 // (first station of next range - INTERVAL_GAP),
107 // assuming always ascending stations
102 for (ImportWstColumn column: columns) { 108 for (ImportWstColumn column: columns) {
103 List<ImportWstColumnValue> cValues = column.getColumnValues(); 109 List<ImportWstColumnValue> cValues = column.getColumnValues();
110 BigDecimal a = cValues.get(0).getPosition();
111 BigDecimal b = cValues.get(cValues.size() - 1).getPosition();
112 if (a.compareTo(b) == 0) {
113 b = new BigDecimal(b.doubleValue() + INTERVAL_GAP);
114 }
104 column.addColumnQRange( 115 column.addColumnQRange(
105 new ImportWstQRange( 116 new ImportWstQRange(
106 cValues.get(0).getPosition(), 117 a,
107 cValues.get(cValues.size() - 1).getPosition(), 118 b,
108 new BigDecimal(0d)) 119 new BigDecimal(-1d))
109 ); 120 );
110 } 121 }
111 current = null; 122 current = null;
112 columns = null; 123 columns = null;
113 } 124 }

http://dive4elements.wald.intevation.org