Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java @ 8987:5ff8ce9a2e06
Modification of the range adding fixed
author | mschaefer |
---|---|
date | Sun, 08 Apr 2018 18:08:35 +0200 |
parents | e541938dd3ab |
children |
comparison
equal
deleted
inserted
replaced
8986:392bbcd8a88b | 8987:5ff8ce9a2e06 |
---|---|
61 public static final BigDecimal INTERVAL_GAP = new BigDecimal("0.00001"); | 61 public static final BigDecimal INTERVAL_GAP = new BigDecimal("0.00001"); |
62 | 62 |
63 protected ImportWst wst; | 63 protected ImportWst wst; |
64 | 64 |
65 protected ImportRange lastRange; | 65 protected ImportRange lastRange; |
66 protected Double lastA; | |
67 protected Double lastB; | |
66 | 68 |
67 public WstParser() { | 69 public WstParser() { |
68 } | 70 } |
69 | 71 |
70 public WstParser(final ImportWst wst) { | 72 public WstParser(final ImportWst wst) { |
448 return NF.format(value); | 450 return NF.format(value); |
449 } | 451 } |
450 | 452 |
451 protected void addInterval( | 453 protected void addInterval( |
452 final BigDecimal from, | 454 final BigDecimal from, |
453 final BigDecimal to, | 455 BigDecimal to, |
454 final BigDecimal[] values | 456 final BigDecimal[] values) { |
455 ) { | |
456 log.debug("addInterval: " + from + " " + to); | 457 log.debug("addInterval: " + from + " " + to); |
457 | 458 |
458 if (values == null || from == MAX_RANGE || from == MIN_RANGE) { | 459 if (values == null || from == MAX_RANGE || from == MIN_RANGE) { |
459 return; | 460 return; |
460 } | 461 } |
461 | 462 |
462 // expand single-line i.e. 0-lenght Q-range to minimal length | 463 // expand single-line i.e. 0-lenght Q-range to minimal length |
464 if (from == to) { | |
465 if (this.lastRange != null && this.lastA > this.lastB) { | |
466 to = from.subtract(INTERVAL_GAP); | |
467 } | |
468 else { | |
469 to = from.add(INTERVAL_GAP); | |
470 } | |
471 } | |
472 | |
463 final ImportRange range = new ImportRange(from, to); | 473 final ImportRange range = new ImportRange(from, to); |
464 if (from == to) { | |
465 if ((this.lastRange != null) && (this.lastRange.difference() < 0.0)) | |
466 range.setB(from.subtract(INTERVAL_GAP)); | |
467 else | |
468 range.setB(from.add(INTERVAL_GAP)); | |
469 } | |
470 | 474 |
471 // little workaround to make the q ranges tightly fit. | 475 // little workaround to make the q ranges tightly fit. |
472 // Leave a very small gap to ensure that the range queries | 476 // Leave a very small gap to ensure that the range queries |
473 // still work. | 477 // still work. |
474 | 478 |
475 if (this.lastRange != null) { | 479 if (this.lastRange != null) { |
476 if (this.lastRange.difference() > 0.0) | 480 if (this.lastA < this.lastB) { |
477 this.lastRange.setB(range.getA().subtract(INTERVAL_GAP)); | 481 this.lastRange.setB(range.getA().subtract(INTERVAL_GAP)); |
478 else // lastA >= lastB | 482 } |
483 else { // lastA >= lastB | |
479 this.lastRange.setA(range.getB().add(INTERVAL_GAP)); | 484 this.lastRange.setA(range.getB().add(INTERVAL_GAP)); |
480 } | 485 } |
481 | 486 } |
482 for (int i = 0; i < values.length; ++i) | 487 |
483 this.wst.getColumn(i).addColumnQRange(new ImportWstQRange(range, values[i])); | 488 for (int i = 0; i < values.length; ++i) { |
484 | 489 final ImportWstColumn column = this.wst.getColumn(i); |
490 final ImportWstQRange wstQRange = new ImportWstQRange(range, values[i]); | |
491 column.addColumnQRange(wstQRange); | |
492 } | |
493 | |
494 this.lastA = from.doubleValue(); | |
495 this.lastB = to.doubleValue(); | |
485 this.lastRange = range; | 496 this.lastRange = range; |
486 } | 497 } |
487 | 498 |
488 private static final BigDecimal [] parseLineAsDouble( | 499 private static final BigDecimal [] parseLineAsDouble( |
489 final String line, | 500 final String line, |