Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/river/MainWstValuesCalculator.java @ 9506:8b7bf26b8782
Predefined artifact for standard vegetation zones.
Some minor adaptions.
author | gernotbelger |
---|---|
date | Fri, 28 Sep 2018 13:44:12 +0200 |
parents | 853f2dafc16e |
children |
rev | line source |
---|---|
9499 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.model.river; | |
11 | |
12 import java.util.HashMap; | |
13 import java.util.Map; | |
14 | |
15 import org.apache.commons.lang.math.DoubleRange; | |
16 import org.dive4elements.artifacts.CallContext; | |
17 import org.dive4elements.river.artifacts.model.WstValueTable; | |
18 import org.dive4elements.river.artifacts.model.WstValueTable.QPosition; | |
19 import org.dive4elements.river.artifacts.model.WstValueTableFactory; | |
20 import org.dive4elements.river.model.Gauge; | |
21 import org.dive4elements.river.model.MainValue; | |
22 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; | |
23 import org.dive4elements.river.model.River; | |
24 | |
25 /** | |
26 * @author Domenico Nardi Tironi | |
27 */ | |
28 public final class MainWstValuesCalculator { | |
29 | |
30 private final WstValueTable wst; | |
31 | |
32 private final Map<String, MainValueQPosition> positions; | |
33 | |
9506
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
34 static class MainValueQPosition { |
9499 | 35 |
9506
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
36 public final Map<Gauge, QPosition> gaugePositions = new HashMap<>(); |
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
37 |
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
38 public QPosition refGaugePositions = null; |
9499 | 39 } |
40 | |
41 public static MainWstValuesCalculator forRiver(final CallContext context, final River river, final DoubleRange calcRange, final String... mainValueNames) { | |
42 | |
43 final RiverInfoProvider info = RiverInfoProvider.forRange(context, river, calcRange); | |
44 | |
45 return forRiverInfo(info, mainValueNames); | |
46 } | |
47 | |
48 public static MainWstValuesCalculator forRiverInfo(final RiverInfoProvider info, final String... mainValueNames) { | |
49 | |
50 final WstValueTable wst = WstValueTableFactory.getTable(info.getRiver()); | |
51 | |
52 final Map<String, MainValueQPosition> positions = calculatePositions(info, wst, mainValueNames); | |
53 | |
54 return new MainWstValuesCalculator(wst, positions); | |
55 } | |
56 | |
57 private static Map<String, MainValueQPosition> calculatePositions(final RiverInfoProvider info, final WstValueTable wst, final String[] mainValueNames) { | |
58 | |
59 boolean isFirstGauge = true; | |
60 | |
61 final Map<String, MainValueQPosition> positions = new HashMap<>(); | |
62 | |
63 for (final String mainValue : mainValueNames) | |
64 positions.put(mainValue.toUpperCase(), new MainValueQPosition()); | |
65 | |
66 for (final Gauge gauge : info.getGauges()) { | |
67 | |
68 for (final MainValueQPosition position : positions.values()) | |
69 position.gaugePositions.put(gauge, null); | |
70 | |
71 final double gaugeKm = gauge.getStation().doubleValue(); | |
72 for (final MainValue mv : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.Q)) { | |
73 | |
74 final MainValueQPosition position = positions.get(mv.getMainValue().getName().toUpperCase()); | |
75 if (position != null) { | |
76 final QPosition qPosition = wst.getQPosition(gaugeKm, mv.getValue().doubleValue()); | |
77 position.gaugePositions.put(gauge, qPosition); | |
78 | |
79 if (isFirstGauge) | |
80 position.refGaugePositions = qPosition; | |
81 } | |
82 } | |
83 | |
84 isFirstGauge = false; | |
85 } | |
86 | |
87 return positions; | |
88 } | |
89 | |
90 private MainWstValuesCalculator(final WstValueTable wst, final Map<String, MainValueQPosition> positions) { | |
91 this.wst = wst; | |
92 this.positions = positions; | |
93 } | |
94 | |
95 public boolean hasPosition(final String mainValueName) { | |
96 | |
9506
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
97 final MainValueQPosition position = this.positions.get(mainValueName.toUpperCase()); |
9499 | 98 if (position == null) |
99 throw new IllegalArgumentException(); | |
100 | |
101 return position.refGaugePositions != null; | |
102 } | |
103 | |
104 /** | |
105 * Interpolates the W for a station with a fixed (virtual) wst column position | |
106 */ | |
107 public double interpolateW(final double station, final String mainValueName) { | |
108 | |
109 final MainValueQPosition mainValuePosition = this.positions.get(mainValueName.toUpperCase()); | |
110 | |
111 if (mainValuePosition.refGaugePositions == null) | |
112 return Double.NaN; | |
113 | |
114 return this.wst.interpolateW(station, mainValuePosition.refGaugePositions); | |
115 } | |
116 } |