Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/river/RiverInfoProvider.java @ 9528:55c187a0a31e
Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
author | mschaefer |
---|---|
date | Tue, 02 Oct 2018 16:39:51 +0200 |
parents | 1722727803f7 |
children |
comparison
equal
deleted
inserted
replaced
9527:7c8d62867876 | 9528:55c187a0a31e |
---|---|
35 private final boolean showAllGauges; | 35 private final boolean showAllGauges; |
36 private final String notinrange; | 36 private final String notinrange; |
37 | 37 |
38 public static RiverInfoProvider forRange(final CallContext context, final River river, final DoubleRange calcRange) { | 38 public static RiverInfoProvider forRange(final CallContext context, final River river, final DoubleRange calcRange) { |
39 | 39 |
40 return forRange(context, river, calcRange, false); | |
41 } | |
42 | |
43 public static RiverInfoProvider forRange(final CallContext context, final River river, final DoubleRange calcRange, final boolean firstGaugeIsRefGauge) { | |
44 | |
45 final List<Gauge> gauges; | 40 final List<Gauge> gauges; |
46 if (calcRange == null) | 41 if (calcRange == null) |
47 gauges = river.getGauges(); | 42 gauges = river.getGauges(); |
48 else { | 43 else |
49 gauges = river.determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble()); | 44 gauges = river.determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble()); |
50 | |
51 // If the range starts exactly at a gauge's range end, determineGauges gets this gauge as the first in list, | |
52 // but we want the list to start with the next gauge, i.e. that one that starts with the calc range, | |
53 // therefore we remove the first one | |
54 // REMARK Bei abwärts kilometriertem Fluss den letzten Gauge in der Liste prüfen (Ende)/entfernen | |
55 if ((gauges.size() >= 2) && (Math.abs(gauges.get(0).getRange().getB().doubleValue() - calcRange.getMinimumDouble()) < 0.0001)) | |
56 gauges.remove(0); | |
57 } | |
58 | 45 |
59 final GaugeIndex gaugeIndex = new GaugeIndex(gauges); | 46 final GaugeIndex gaugeIndex = new GaugeIndex(gauges); |
60 | 47 |
61 final String notinrange = Resources.getMsg(context.getMeta(), CSV_NOT_IN_GAUGE_RANGE, CSV_NOT_IN_GAUGE_RANGE); | 48 final String notinrange = Resources.getMsg(context.getMeta(), CSV_NOT_IN_GAUGE_RANGE, CSV_NOT_IN_GAUGE_RANGE); |
62 | 49 |
63 if (firstGaugeIsRefGauge && !gauges.isEmpty()) | |
64 return new RiverInfoProvider(notinrange, river, false, gaugeIndex, gauges.get(0)); | |
65 return new RiverInfoProvider(notinrange, river, false, gaugeIndex, null); | 50 return new RiverInfoProvider(notinrange, river, false, gaugeIndex, null); |
66 } | 51 } |
67 | 52 |
68 private RiverInfoProvider(final String notinrange, final River river, final boolean showAllGauges, final GaugeIndex gaugeIndex, final Gauge refGauge) { | 53 private RiverInfoProvider(final String notinrange, final River river, final boolean showAllGauges, final GaugeIndex gaugeIndex, final Gauge refGauge) { |
69 this.notinrange = notinrange; | 54 this.notinrange = notinrange; |
71 this.showAllGauges = showAllGauges; | 56 this.showAllGauges = showAllGauges; |
72 this.gaugeIndex = gaugeIndex; | 57 this.gaugeIndex = gaugeIndex; |
73 this.refGauge = refGauge; | 58 this.refGauge = refGauge; |
74 } | 59 } |
75 | 60 |
61 /** | |
62 * Creates a new provider as a copy of this one, re-determining the reference gauge by a waterlevel | |
63 */ | |
76 public RiverInfoProvider forWaterlevel(final WaterlevelData waterlevel) { | 64 public RiverInfoProvider forWaterlevel(final WaterlevelData waterlevel) { |
77 final WKms wstKms = waterlevel.getWkms(); | 65 final WKms wstKms = waterlevel.getWkms(); |
78 final Gauge waterlevelRefGauge = findReferenceGauge(wstKms); | 66 final Gauge waterlevelRefGauge = findReferenceGauge(wstKms); |
79 final boolean waterlevelShowAllGauges = waterlevel.isShowAllGauges(); | 67 final boolean waterlevelShowAllGauges = waterlevel.isShowAllGauges(); |
80 | 68 |
81 return new RiverInfoProvider(this.notinrange, this.river, waterlevelShowAllGauges, this.gaugeIndex, waterlevelRefGauge); | 69 return new RiverInfoProvider(this.notinrange, this.river, waterlevelShowAllGauges, this.gaugeIndex, waterlevelRefGauge); |
82 } | 70 } |
83 | 71 |
84 /** | 72 /** |
85 * Re-determines the reference gauge, in the same way as the WaterlevelArtifact would do it | 73 * Create a new provider as a copy of this one, re-determining the reference gauge by the upstream side of a range |
74 */ | |
75 public RiverInfoProvider forReferenceRange(final DoubleRange range, final boolean isShowAllGauges) { | |
76 final Gauge kmRefGauge = findReferenceGauge(range); | |
77 return new RiverInfoProvider(this.notinrange, this.river, isShowAllGauges, this.gaugeIndex, kmRefGauge); | |
78 } | |
79 | |
80 /** | |
81 * Determines the reference gauge, in the same way as the WaterlevelArtifact would do it | |
86 */ | 82 */ |
87 private Gauge findReferenceGauge(final WKms wkms) { | 83 private Gauge findReferenceGauge(final WKms wkms) { |
88 | 84 |
89 final double[] wstFromTo = findWstFromTo(wkms); | 85 final double[] wstFromTo = findWstFromTo(wkms); |
86 return this.river.determineRefGauge(wstFromTo, true); | |
87 } | |
88 | |
89 /** | |
90 * Determines the reference gauge for a km range of the active river | |
91 */ | |
92 private Gauge findReferenceGauge(final DoubleRange range) { | |
93 | |
94 final double from = range.getMinimumDouble(); | |
95 final double to = range.getMaximumDouble(); | |
96 final boolean waterIncreasing = this.river.getKmUp(); | |
97 final double[] wstFromTo = waterIncreasing ? new double[] { to, from } : new double[] { from, to }; | |
90 return this.river.determineRefGauge(wstFromTo, true); | 98 return this.river.determineRefGauge(wstFromTo, true); |
91 } | 99 } |
92 | 100 |
93 private static double[] findWstFromTo(final WKms wkms) { | 101 private static double[] findWstFromTo(final WKms wkms) { |
94 | 102 |