Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/DischargeTables.java @ 6301:20a32dbdbb59
Remove discharge table scaling but add reference system to W
- Discharge_Tables are now always W[cm] Q[m³] no need for
special case handling depending on historical / master tables
- W now has a referenceSystem value that can be CENTIMETER_AT_GAUGE or
METER_OVER_REFPOINT. The default is METER_OVER_REFPOINT as this is
the case for everything except the objects created from discharge tables
Known issue: WINFO input validation is currently broken as it still scales
the user input.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 12 Jun 2013 10:54:27 +0200 |
parents | af13ceeba52a |
children | e4606eae8ea5 |
comparison
equal
deleted
inserted
replaced
6300:0711ce5ca701 | 6301:20a32dbdbb59 |
---|---|
32 implements Serializable | 32 implements Serializable |
33 { | 33 { |
34 /** Private logger. */ | 34 /** Private logger. */ |
35 private static Logger log = Logger.getLogger(DischargeTables.class); | 35 private static Logger log = Logger.getLogger(DischargeTables.class); |
36 | 36 |
37 /** Scale to convert discharge table values of master table into [cm]. */ | |
38 public static final double MASTER_SCALE = 100d; | |
39 | |
40 /** Scale to convert discharge table values of historical tables into [cm]. */ | |
41 public static final double HISTORICAL_SCALE = 1d; | |
42 | |
43 public static final int MASTER = 0; | 37 public static final int MASTER = 0; |
44 | 38 |
45 protected List<String> gaugeNames; | 39 protected List<String> gaugeNames; |
46 | 40 |
47 protected String riverName; | 41 protected String riverName; |
48 | |
49 protected double scale; | |
50 | 42 |
51 protected int kind; | 43 protected int kind; |
52 | 44 |
53 protected Map<String, double [][]> values; | 45 protected Map<String, double [][]> values; |
54 | 46 |
74 public DischargeTables( | 66 public DischargeTables( |
75 String riverName, | 67 String riverName, |
76 List<String> gaugeNames, | 68 List<String> gaugeNames, |
77 int kind | 69 int kind |
78 ) { | 70 ) { |
79 scale = Double.NaN; | |
80 this.kind = kind; | 71 this.kind = kind; |
81 this.riverName = riverName; | 72 this.riverName = riverName; |
82 this.gaugeNames = gaugeNames; | 73 this.gaugeNames = gaugeNames; |
83 } | 74 } |
84 | 75 |
85 public double [][] getFirstTable() { | 76 public double [][] getFirstTable() { |
86 return getFirstTable(MASTER_SCALE); | 77 Map<String, double [][]> values = getValues(); |
87 } | |
88 | |
89 public double [][] getFirstTable(double scale) { | |
90 Map<String, double [][]> values = getValues(scale); | |
91 for (double [][] table: values.values()) { | 78 for (double [][] table: values.values()) { |
92 return table; | 79 return table; |
93 } | 80 } |
94 return null; | 81 return null; |
95 } | 82 } |
96 | 83 |
97 public Map<String, double [][]> getValues() { | 84 public Map<String, double [][]> getValues() { |
98 return getValues(MASTER_SCALE); | 85 if (values == null) { |
99 } | 86 values = loadValues(); |
100 | |
101 public Map<String, double [][]> getValues(double scale) { | |
102 if (values == null || scale != this.scale) { | |
103 values = loadValues(scale); | |
104 this.scale = scale; | |
105 } | 87 } |
106 return values; | 88 return values; |
107 } | 89 } |
108 | 90 |
109 /** | 91 /** |
110 * Returns mapping of gauge name to values. | 92 * Returns mapping of gauge name to values. |
111 */ | 93 */ |
112 protected Map<String, double [][]> loadValues(double scale) { | 94 protected Map<String, double [][]> loadValues() { |
113 Map<String, double [][]> values = new HashMap<String, double [][]>(); | 95 Map<String, double [][]> values = new HashMap<String, double [][]>(); |
114 | 96 |
115 Session session = SessionHolder.HOLDER.get(); | 97 Session session = SessionHolder.HOLDER.get(); |
116 | 98 |
117 Query gaugeQuery = session.createQuery( | 99 Query gaugeQuery = session.createQuery( |
145 } | 127 } |
146 } | 128 } |
147 if (table == null) { | 129 if (table == null) { |
148 table = tables.get(0); | 130 table = tables.get(0); |
149 } | 131 } |
150 double [][] vs = loadDischargeTableValues(table, scale); | 132 double [][] vs = loadDischargeTableValues(table); |
151 | 133 |
152 values.put(gaugeName, vs); | 134 values.put(gaugeName, vs); |
153 } | 135 } |
154 | 136 |
155 return values; | 137 return values; |
156 } | 138 } |
157 | 139 |
158 | 140 |
159 /** | 141 /** |
160 * @param table The discharge table | 142 * @param table The discharge table |
161 * @param scale The scale factor to adjust W and Q values. | |
162 * | 143 * |
163 * @return the values of a discharge table. | 144 * @return the values of a discharge table. |
164 */ | 145 */ |
165 public static double[][] loadDischargeTableValues( | 146 public static double[][] loadDischargeTableValues(DischargeTable table) { |
166 DischargeTable table, | |
167 double scale | |
168 ) { | |
169 List<DischargeTableValue> dtvs = table.getDischargeTableValues(); | 147 List<DischargeTableValue> dtvs = table.getDischargeTableValues(); |
170 | 148 |
171 final double [][] vs = new double[2][dtvs.size()]; | 149 final double [][] vs = new double[2][dtvs.size()]; |
172 | 150 |
173 int idx = 0; | 151 int idx = 0; |
174 for (DischargeTableValue dtv: dtvs) { | 152 for (DischargeTableValue dtv: dtvs) { |
175 double q = dtv.getQ().doubleValue(); | 153 double q = dtv.getQ().doubleValue(); |
176 vs[0][idx] = q * scale; | 154 vs[0][idx] = q; |
177 vs[1][idx] = dtv.getW().doubleValue() * scale; | 155 vs[1][idx] = dtv.getW().doubleValue(); |
178 ++idx; | 156 ++idx; |
179 } | 157 } |
180 | 158 |
181 return vs; | 159 return vs; |
182 } | 160 } |