Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java @ 8914:e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
author | gernotbelger |
---|---|
date | Tue, 27 Feb 2018 18:06:52 +0100 |
parents | 9483a5bf4219 |
children | f61bc0c63188 |
comparison
equal
deleted
inserted
replaced
8913:924cd9943337 | 8914:e3519c3e7a0a |
---|---|
28 import org.dive4elements.river.model.Gauge; | 28 import org.dive4elements.river.model.Gauge; |
29 import org.dive4elements.river.model.River; | 29 import org.dive4elements.river.model.River; |
30 import org.dive4elements.river.model.Wst; | 30 import org.dive4elements.river.model.Wst; |
31 | 31 |
32 import org.dive4elements.river.artifacts.D4EArtifact; | 32 import org.dive4elements.river.artifacts.D4EArtifact; |
33 import org.dive4elements.river.artifacts.WINFOArtifact; | |
34 | 33 |
35 import org.dive4elements.river.artifacts.access.RangeAccess; | 34 import org.dive4elements.river.artifacts.access.RangeAccess; |
36 | 35 import org.dive4elements.river.artifacts.access.ComputationRangeAccess; |
37 import org.dive4elements.river.artifacts.model.WstFactory; | 36 import org.dive4elements.river.artifacts.model.WstFactory; |
38 import org.dive4elements.river.artifacts.model.WstValueTable; | 37 import org.dive4elements.river.artifacts.model.WstValueTable; |
39 import org.dive4elements.river.artifacts.model.WstValueTableFactory; | 38 import org.dive4elements.river.artifacts.model.WstValueTableFactory; |
40 import org.dive4elements.river.artifacts.resources.Resources; | 39 import org.dive4elements.river.artifacts.resources.Resources; |
41 | 40 |
102 } | 101 } |
103 | 102 |
104 Boolean isQ = flys.getDataAsBoolean(WQ_MODE); | 103 Boolean isQ = flys.getDataAsBoolean(WQ_MODE); |
105 Boolean isFree = flys.getDataAsBoolean(WQ_FREE); | 104 Boolean isFree = flys.getDataAsBoolean(WQ_FREE); |
106 | 105 |
107 WINFOArtifact winfo = (WINFOArtifact) flys; | |
108 | |
109 Element dataElement = creator.create("data"); | 106 Element dataElement = creator.create("data"); |
110 creator.addAttr(dataElement, "name", name, true); | 107 creator.addAttr(dataElement, "name", name, true); |
111 creator.addAttr(dataElement, "type", type, true); | 108 creator.addAttr(dataElement, "type", type, true); |
112 | 109 |
113 Element itemElement = creator.create("item"); | 110 Element itemElement = creator.create("item"); |
114 creator.addAttr(itemElement, "value", value, true); | 111 creator.addAttr(itemElement, "value", value, true); |
115 | 112 |
116 String label; | 113 String label; |
117 | 114 |
118 if (!isQ || isFree) { | 115 if (!isQ || isFree) { |
119 label = getLabel(winfo, cc, value); | 116 label = getLabel(flys, cc, value); |
120 } | 117 } |
121 else { | 118 else { |
122 label = getSpecialLabel(winfo, cc, value); | 119 label = getSpecialLabel(flys, cc, value); |
123 } | 120 } |
124 | 121 |
125 creator.addAttr(itemElement, "label", label, true); | 122 creator.addAttr(itemElement, "label", label, true); |
126 | 123 |
127 dataElement.appendChild(itemElement); | 124 dataElement.appendChild(itemElement); |
129 return dataElement; | 126 return dataElement; |
130 } | 127 } |
131 | 128 |
132 | 129 |
133 protected static String getLabel( | 130 protected static String getLabel( |
134 WINFOArtifact winfo, | 131 D4EArtifact winfo, |
135 CallContext cc, | 132 CallContext cc, |
136 String raw | 133 String raw |
137 ) { | 134 ) { |
138 String[] values = raw.split(" "); | 135 String[] values = raw.split(" "); |
139 | 136 |
165 return label.toString(); | 162 return label.toString(); |
166 } | 163 } |
167 | 164 |
168 | 165 |
169 protected static String getSpecialLabel( | 166 protected static String getSpecialLabel( |
170 WINFOArtifact winfo, | 167 D4EArtifact winfo, |
171 CallContext cc, | 168 CallContext cc, |
172 String raw | 169 String raw |
173 ) { | 170 ) { |
174 String[] values = raw.split(" "); | 171 String[] values = raw.split(" "); |
175 | 172 |
248 XMLUtils.ElementCreator cr, | 245 XMLUtils.ElementCreator cr, |
249 Artifact artifact, | 246 Artifact artifact, |
250 String name, | 247 String name, |
251 CallContext context | 248 CallContext context |
252 ){ | 249 ){ |
253 WINFOArtifact winfo = (WINFOArtifact) artifact; | 250 D4EArtifact flys = (D4EArtifact) artifact; |
254 | 251 |
255 double[] minmaxW = determineMinMaxW(winfo); | 252 double[] minmaxW = determineMinMaxW(flys); |
256 double[] minmaxWFree = determineMinMaxWFree(winfo); | 253 double[] minmaxWFree = determineMinMaxWFree(flys); |
257 double[] minmaxQ = determineMinMaxQAtGauge(winfo); | 254 double[] minmaxQ = determineMinMaxQAtGauge(flys); |
258 double[] minmaxQFree = determineMinMaxQ(winfo); | 255 double[] minmaxQFree = determineMinMaxQ(flys); |
259 | 256 |
260 if (name.equals("wq_from")) { | 257 if (name.equals("wq_from")) { |
261 Element minW = createItem(cr, new String[] { | 258 Element minW = createItem(cr, new String[] { |
262 "minW", | 259 "minW", |
263 String.valueOf(minmaxW[0])}); | 260 String.valueOf(minmaxW[0])}); |
398 * | 395 * |
399 * @param artifact The D4EArtifact. | 396 * @param artifact The D4EArtifact. |
400 * | 397 * |
401 * @return the min and max W values for the current gauge. | 398 * @return the min and max W values for the current gauge. |
402 */ | 399 */ |
403 protected double[] determineMinMaxW(WINFOArtifact winfo) { | 400 protected double[] determineMinMaxW(D4EArtifact winfo) { |
404 log.debug("WQSelect.determineCurrentGauge"); | 401 log.debug("WQSelect.determineCurrentGauge"); |
405 | 402 |
406 RangeAccess rangeAccess = new RangeAccess(winfo); | 403 RangeAccess rangeAccess = new RangeAccess(winfo); |
407 Gauge gauge = rangeAccess.getRiver().determineRefGauge( | 404 Gauge gauge = rangeAccess.getRiver().determineRefGauge( |
408 rangeAccess.getKmRange(), rangeAccess.isRange()); | 405 rangeAccess.getKmRange(), rangeAccess.isRange()); |
423 * | 420 * |
424 * @param artifact The D4EArtifact. | 421 * @param artifact The D4EArtifact. |
425 * | 422 * |
426 * @return the min and max W values. | 423 * @return the min and max W values. |
427 */ | 424 */ |
428 protected double[] determineMinMaxWFree(WINFOArtifact winfo) { | 425 protected double[] determineMinMaxWFree(D4EArtifact winfo) { |
429 log.debug("WQSelect.determineMinMaxWFree"); | 426 log.debug("WQSelect.determineMinMaxWFree"); |
430 | 427 |
431 WstValueTable valueTable = WstValueTableFactory.getTable( | 428 WstValueTable valueTable = WstValueTableFactory.getTable( |
432 RiverUtils.getRiver(winfo)); | 429 RiverUtils.getRiver(winfo)); |
433 | 430 |
431 ComputationRangeAccess access = new ComputationRangeAccess(winfo); | |
432 | |
434 double[] minmaxW = null; | 433 double[] minmaxW = null; |
435 if(valueTable != null) { | 434 if(valueTable != null) { |
436 double[] km = null; | 435 double[] km = null; |
437 if(new RangeAccess(winfo).isRange()) { | 436 if(access.isRange()) { |
438 km = winfo.getFromToStep(); | 437 km = access.getFromToStep(); |
439 // Use the start km to determine the min max values. | 438 // Use the start km to determine the min max values. |
440 minmaxW = valueTable.getMinMaxW(km[0]); | 439 minmaxW = valueTable.getMinMaxW(km[0]); |
441 } | 440 } |
442 else { | 441 else { |
443 km = winfo.getKms(); | 442 km = access.getKms(); |
444 minmaxW = valueTable.getMinMaxW(km[0]); | 443 minmaxW = valueTable.getMinMaxW(km[0]); |
445 } | 444 } |
446 } | 445 } |
447 return minmaxW != null | 446 return minmaxW != null |
448 ? minmaxW | 447 ? minmaxW |
457 * | 456 * |
458 * @param artifact The D4EArtifact. | 457 * @param artifact The D4EArtifact. |
459 * | 458 * |
460 * @return the min and max Q values for the current gauge. | 459 * @return the min and max Q values for the current gauge. |
461 */ | 460 */ |
462 protected double[] determineMinMaxQAtGauge(WINFOArtifact winfo) { | 461 protected double[] determineMinMaxQAtGauge(D4EArtifact winfo) { |
463 log.debug("WQSelect.determineMinMaxQAtGauge"); | 462 log.debug("WQSelect.determineMinMaxQAtGauge"); |
464 | 463 |
465 RangeAccess rangeAccess = new RangeAccess(winfo); | 464 RangeAccess rangeAccess = new RangeAccess(winfo); |
466 River river = rangeAccess.getRiver(); | 465 River river = rangeAccess.getRiver(); |
467 Gauge gauge = river.determineRefGauge( | 466 Gauge gauge = river.determineRefGauge( |
486 * | 485 * |
487 * @param artifact The D4EArtifact. | 486 * @param artifact The D4EArtifact. |
488 * | 487 * |
489 * @return the min and max Q values for the current kilometer range. | 488 * @return the min and max Q values for the current kilometer range. |
490 */ | 489 */ |
491 protected double[] determineMinMaxQ(WINFOArtifact winfo) { | 490 protected double[] determineMinMaxQ(D4EArtifact winfo) { |
492 log.debug("WQSelect.determineMinMaxQ"); | 491 log.debug("WQSelect.determineMinMaxQ"); |
493 | 492 |
494 WstValueTable valueTable = WstValueTableFactory.getTable( | 493 WstValueTable valueTable = WstValueTableFactory.getTable( |
495 RiverUtils.getRiver(winfo)); | 494 RiverUtils.getRiver(winfo)); |
496 | 495 |
496 ComputationRangeAccess access = new ComputationRangeAccess(winfo); | |
497 | |
497 double[] minmaxQ = null; | 498 double[] minmaxQ = null; |
498 if(valueTable != null) { | 499 if(valueTable != null) { |
499 double[] km = null; | 500 double[] km = null; |
500 if(new RangeAccess(winfo).isRange()) { | 501 if(access.isRange()) { |
501 km = winfo.getFromToStep(); | 502 km = new ComputationRangeAccess(winfo).getFromToStep(); |
502 minmaxQ = valueTable.getMinMaxQ(km[0], km[1], km[2]); | 503 minmaxQ = valueTable.getMinMaxQ(km[0], km[1], km[2]); |
503 } | 504 } |
504 else { | 505 else { |
505 km = winfo.getKms(); | 506 km = access.getKms(); |
506 minmaxQ = valueTable.getMinMaxQ(km[0]); | 507 minmaxQ = valueTable.getMinMaxQ(km[0]); |
507 for (int i = 1; i < km.length; i++) { | 508 for (int i = 1; i < km.length; i++) { |
508 double[] tmp = valueTable.getMinMaxQ(km[i]); | 509 double[] tmp = valueTable.getMinMaxQ(km[i]); |
509 if(tmp[0] < minmaxQ[0]) { | 510 if(tmp[0] < minmaxQ[0]) { |
510 minmaxQ[0] = tmp[0]; | 511 minmaxQ[0] = tmp[0]; |
525 public boolean validate(Artifact artifact) | 526 public boolean validate(Artifact artifact) |
526 throws IllegalArgumentException | 527 throws IllegalArgumentException |
527 { | 528 { |
528 log.debug("WQSelect.validate"); | 529 log.debug("WQSelect.validate"); |
529 | 530 |
530 WINFOArtifact flys = (WINFOArtifact) artifact; | 531 D4EArtifact flys = (D4EArtifact) artifact; |
531 | 532 |
532 StateData data = getData(flys, WQ_SELECTION); | 533 StateData data = getData(flys, WQ_SELECTION); |
533 boolean isRange = data != null | 534 boolean isRange = data != null |
534 ? Boolean.valueOf((String) data.getValue()) | 535 ? Boolean.valueOf((String) data.getValue()) |
535 : false; | 536 : false; |
565 | 566 |
566 return true; | 567 return true; |
567 } | 568 } |
568 | 569 |
569 | 570 |
570 protected boolean validateSingle(WINFOArtifact artifact) | 571 protected boolean validateSingle(D4EArtifact artifact) |
571 throws IllegalArgumentException | 572 throws IllegalArgumentException |
572 { | 573 { |
573 log.debug("WQSelect.validateSingle"); | 574 log.debug("WQSelect.validateSingle"); |
574 | 575 |
575 StateData data = getData(artifact, WQ_SINGLE); | 576 StateData data = getData(artifact, WQ_SINGLE); |
621 | 622 |
622 return validateBounds(minmax[0], minmax[1], min, max, 0d); | 623 return validateBounds(minmax[0], minmax[1], min, max, 0d); |
623 } | 624 } |
624 | 625 |
625 | 626 |
626 protected boolean validateRange(WINFOArtifact artifact) | 627 protected boolean validateRange(D4EArtifact artifact) |
627 throws IllegalArgumentException | 628 throws IllegalArgumentException |
628 { | 629 { |
629 log.debug("WQSelect.validateRange"); | 630 log.debug("WQSelect.validateRange"); |
630 | 631 |
631 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(artifact); | 632 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(artifact); |
683 * @param step The step width. | 684 * @param step The step width. |
684 * | 685 * |
685 * @return true, if everything was fine, otherwise an exception is thrown. | 686 * @return true, if everything was fine, otherwise an exception is thrown. |
686 */ | 687 */ |
687 protected boolean validateGaugeW( | 688 protected boolean validateGaugeW( |
688 WINFOArtifact artifact, | 689 D4EArtifact artifact, |
689 double from, | 690 double from, |
690 double to, | 691 double to, |
691 double step) | 692 double step) |
692 throws IllegalArgumentException | 693 throws IllegalArgumentException |
693 { | 694 { |
709 * @param step The step width. | 710 * @param step The step width. |
710 * | 711 * |
711 * @return true, if everything was fine, otherwise an exception is thrown. | 712 * @return true, if everything was fine, otherwise an exception is thrown. |
712 */ | 713 */ |
713 protected boolean validateGaugeQ( | 714 protected boolean validateGaugeQ( |
714 WINFOArtifact artifact, | 715 D4EArtifact artifact, |
715 double from, | 716 double from, |
716 double to, | 717 double to, |
717 double step) | 718 double step) |
718 throws IllegalArgumentException | 719 throws IllegalArgumentException |
719 { | 720 { |
735 * @param step The step width. | 736 * @param step The step width. |
736 * | 737 * |
737 * @return true, if everything was fine, otherwise an exception is thrown. | 738 * @return true, if everything was fine, otherwise an exception is thrown. |
738 */ | 739 */ |
739 protected boolean validateFreeQ( | 740 protected boolean validateFreeQ( |
740 WINFOArtifact artifact, | 741 D4EArtifact artifact, |
741 double from, | 742 double from, |
742 double to, | 743 double to, |
743 double step) | 744 double step) |
744 throws IllegalArgumentException | 745 throws IllegalArgumentException |
745 { | 746 { |
761 * @param step The step width. | 762 * @param step The step width. |
762 * | 763 * |
763 * @return true, if everything was fine, otherwise an exception is thrown. | 764 * @return true, if everything was fine, otherwise an exception is thrown. |
764 */ | 765 */ |
765 protected boolean validateFreeW( | 766 protected boolean validateFreeW( |
766 WINFOArtifact artifact, | 767 D4EArtifact artifact, |
767 double from, | 768 double from, |
768 double to, | 769 double to, |
769 double step) | 770 double step) |
770 throws IllegalArgumentException | 771 throws IllegalArgumentException |
771 { | 772 { |