Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeRange.java @ 3403:04d090d06d3f
FixA: KM chart service: Use only blue as point color.
flys-artifacts/trunk@5045 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 18 Jul 2012 16:37:41 +0000 |
parents | 08230c76cd92 |
children | c44ff50f4970 |
rev | line source |
---|---|
3141
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.io.Serializable; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.util.ArrayList; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import java.util.HashMap; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.util.List; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import java.util.Map; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import org.apache.log4j.Logger; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 public class GaugeRange |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 extends Range |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 private static Logger log = Logger.getLogger(GaugeRange.class); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 private static final class Sector implements Serializable { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 int sector; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 double value; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 Sector(int sector, double value) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 this.sector = sector; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 this.value = value; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 } // class Sector |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 protected int gaugeId; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 protected Map<String, Double> mainValues; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 protected List<Sector> sectors; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 public GaugeRange() { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 public GaugeRange(double start, double end, int gaugeId) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 super(start, end); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 this.gaugeId = gaugeId; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 mainValues = new HashMap<String, Double>(); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 sectors = new ArrayList<Sector>(3); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public void addMainValue(String label, Double value) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 int idx = label.indexOf('('); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 if (idx >= 0) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 label = label.substring(0, idx); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 mainValues.put(label, value); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 protected Double getMainValue(String label) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 Double v = mainValues.get(label); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 if (v == null) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 log.warn("Missing main value '" |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 + label + "' for gauge " + gaugeId); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 return v; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 public void buildClasses() { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 Double mnq = getMainValue("MNQ"); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 Double mq = getMainValue("MQ"); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 Double mhq = getMainValue("MHQ"); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 Double hq5 = getMainValue("HQ5"); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 Double [][] pairs = { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 { mnq, mq }, |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 { mq, mhq }, |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 { hq5, hq5 } }; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 for (int c = 0; c < pairs.length; ++c) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 Double [] pair = pairs[c]; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 if (pair[0] != null && pair[1] != null) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 double value = 0.5*(pair[0] + pair[1]); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 sectors.add(new Sector(c, value)); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 |
3144
05a7298c4f20
Fix: add method to find discharge sector border for given river and km.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3141
diff
changeset
|
80 public double getSectorBorder(int sector) { |
05a7298c4f20
Fix: add method to find discharge sector border for given river and km.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3141
diff
changeset
|
81 for (Sector s: sectors) { |
05a7298c4f20
Fix: add method to find discharge sector border for given river and km.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3141
diff
changeset
|
82 if (s.sector == sector) { |
05a7298c4f20
Fix: add method to find discharge sector border for given river and km.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3141
diff
changeset
|
83 return s.value; |
05a7298c4f20
Fix: add method to find discharge sector border for given river and km.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3141
diff
changeset
|
84 } |
05a7298c4f20
Fix: add method to find discharge sector border for given river and km.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3141
diff
changeset
|
85 } |
05a7298c4f20
Fix: add method to find discharge sector border for given river and km.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3141
diff
changeset
|
86 return Double.NaN; |
05a7298c4f20
Fix: add method to find discharge sector border for given river and km.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3141
diff
changeset
|
87 } |
05a7298c4f20
Fix: add method to find discharge sector border for given river and km.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3141
diff
changeset
|
88 |
3141
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 public int classify(double value) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 for (Sector sector: sectors) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 if (value < sector.value) { |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 return sector.sector; |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 return sectors.size(); |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 } |
3151
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
97 |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
98 public String toString() { |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
99 StringBuilder sb = new StringBuilder("sectors: ["); |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
100 |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
101 for (int i = 0, S = sectors.size(); i < S; ++i) { |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
102 if (i > 0) sb.append(", "); |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
103 Sector s = sectors.get(i); |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
104 sb.append(s.sector).append(": ").append(s.value);; |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
105 } |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
106 |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
107 sb.append("] mainvalues: ").append(mainValues); |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
108 |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
109 return sb.toString(); |
08230c76cd92
FixA: KM chart helper service: Added debug output when creating Q sector markers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3144
diff
changeset
|
110 } |
3141
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
3582e87e9171
FixA: Made GaugeRange a top level class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |