Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurement.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurement.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.artifacts.model.sq; | |
2 | |
3 import java.util.Arrays; | |
4 import java.util.List; | |
5 import java.util.Map; | |
6 | |
7 import org.apache.commons.logging.Log; | |
8 import org.apache.commons.logging.LogFactory; | |
9 | |
10 public class Measurement | |
11 { | |
12 private static final Log log = | |
13 LogFactory.getLog(Measurement.class); | |
14 | |
15 public static final double LOG_10_8 = Math.log(10) - Math.log(8); | |
16 public static final double SCALE_8 = Math.log(10) - Math.log(6.3); | |
17 | |
18 public static final double LOG_8_6 = Math.log(8) - Math.log(6.3); | |
19 public static final double SCALE_4 = Math.log(10) - Math.log(6.3); | |
20 | |
21 protected Map<String, Object> data; | |
22 | |
23 protected List<Sieve> sieves; | |
24 | |
25 protected SieveArray sieveArray; | |
26 | |
27 public Measurement() { | |
28 } | |
29 | |
30 public Measurement(Map<String, Object> data, List<Sieve> sieves) { | |
31 this.data = data; | |
32 this.sieves = sieves; | |
33 } | |
34 | |
35 protected double get(String name) { | |
36 Number value = (Number)data.get(name); | |
37 return value != null ? value.doubleValue() : Double.NaN; | |
38 } | |
39 | |
40 protected void set(String name, double value) { | |
41 data.put(name, Double.valueOf(value)); | |
42 } | |
43 | |
44 public Object getData(String name) { | |
45 return data.get(name); | |
46 } | |
47 | |
48 public Map<String, Object> getData() { | |
49 return data; | |
50 } | |
51 | |
52 protected void putData(String name, Object value) { | |
53 data.put(name, value); | |
54 } | |
55 | |
56 public double S_SS() { | |
57 return get("TSAND"); | |
58 } | |
59 | |
60 public double S_SF() { | |
61 return get("TSCHWEB") - get("TSAND"); | |
62 } | |
63 | |
64 public double Q() { | |
65 return get("Q_BPEGEL"); | |
66 } | |
67 | |
68 public double TOTAL_BL() { | |
69 return get("TGESCHIEBE"); | |
70 } | |
71 | |
72 public double BL_G() { | |
73 return get("BL_G"); | |
74 } | |
75 | |
76 public double BL_C() { | |
77 return get("BL_C"); | |
78 } | |
79 | |
80 public double BL_S() { | |
81 return get("BL_S"); | |
82 } | |
83 | |
84 public double S_BL_S() { | |
85 return TOTAL_BL() * BL_S(); | |
86 } | |
87 | |
88 public double S_BL_FG() { | |
89 return TOTAL_BL() * BL_G(); | |
90 } | |
91 | |
92 public double S_BL_CG() { | |
93 return TOTAL_BL() * BL_C(); | |
94 } | |
95 | |
96 public double S_BL_1() { | |
97 return S_BL_S() + S_BL_FG() + S_BL_CG(); | |
98 } | |
99 | |
100 public double S_BL_2() { | |
101 return S_SS() + S_BL_S() + S_BL_FG() + S_BL_CG(); | |
102 } | |
103 | |
104 @Override | |
105 public String toString() { | |
106 return "Measurement: " + data; | |
107 } | |
108 | |
109 /** | |
110 * Gets the sieves for this instance. | |
111 * | |
112 * @return The sieves. | |
113 */ | |
114 public List<Sieve> getSieves() { | |
115 return this.sieves; | |
116 } | |
117 | |
118 /** | |
119 * Gets the sieveArray for this instance. | |
120 * | |
121 * @return The sieveArray. | |
122 */ | |
123 public SieveArray getSieveArray() { | |
124 if (sieveArray == null) { | |
125 sieveArray = calculateSieveArray(); | |
126 } | |
127 adjustSieves(); | |
128 return sieveArray; | |
129 } | |
130 | |
131 protected Sieve findSieve(double diameter) { | |
132 for (Sieve s: sieves) { | |
133 if (s.matchesDiameter(diameter)) { | |
134 return s; | |
135 } | |
136 } | |
137 return null; | |
138 } | |
139 | |
140 protected void deleteSieve(double diameter) { | |
141 for (int i = sieves.size()-1; i >= 0; --i) { | |
142 if (sieves.get(i).matchesDiameter(diameter)) { | |
143 sieves.remove(i); | |
144 break; | |
145 } | |
146 } | |
147 } | |
148 | |
149 public void adjustSieves() { | |
150 | |
151 // If we already have an 8mm diameter sieve | |
152 // we dont need to 'invent' it. | |
153 if (findSieve(8d) != null) { | |
154 return; | |
155 } | |
156 | |
157 // create a new 8mm sieve. | |
158 // delete 6.3mm sieve. | |
159 // modify 4mm sieve. | |
160 | |
161 Sieve six = findSieve(6.3d); | |
162 Sieve ten = findSieve(10d); | |
163 Sieve four = findSieve(4d); | |
164 | |
165 if (six == null || ten == null || four == null) { | |
166 log.warn("missing diameter"); | |
167 return; | |
168 } | |
169 | |
170 double sixValue = six.getLoad(); | |
171 double tenValue = ten.getLoad(); | |
172 double fourValue = four.getLoad(); | |
173 | |
174 deleteSieve(6.3); | |
175 | |
176 double eightValue = ((LOG_10_8 / SCALE_8*sixValue) + tenValue); | |
177 double newFourValue = ((LOG_8_6 / SCALE_4*sixValue) + fourValue); | |
178 | |
179 deleteSieve(4.0); | |
180 sieves.add(new Sieve(8d, eightValue)); | |
181 sieves.add(new Sieve(4d, newFourValue)); | |
182 sieveArray.adjust( | |
183 eightValue/sieveArray.totalLoad(), | |
184 newFourValue/sieveArray.totalLoad()); | |
185 log.debug("Adjusted loads: " + Arrays.toString(sieveArray.getLoads())); | |
186 log.debug("Adjusted norm loads:" + Arrays.toString(sieveArray.getNormLoads())); | |
187 } | |
188 | |
189 protected SieveArray calculateSieveArray() { | |
190 | |
191 SieveArray sa = new SieveArray(); | |
192 | |
193 for (Sieve s: sieves) { | |
194 sa.doSieving(s); | |
195 } | |
196 | |
197 sa.calculateNormLoads(); | |
198 | |
199 return sa; | |
200 } | |
201 } | |
202 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |