Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java @ 772:cd64ab8a46a7
Put time to live of an artifact into meta document which is created while wms publishing (issue197).
gnv-artifacts/trunk@829 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 26 Mar 2010 09:21:31 +0000 |
parents | d70cac2bafc0 |
children | b1f5f2a8840f |
rev | line source |
---|---|
617
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.histogram; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import de.intevation.gnv.geobackend.base.Result; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import de.intevation.gnv.geobackend.base.ResultDescriptor; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import de.intevation.gnv.state.describedata.KeyValueDescibeData; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import java.util.ArrayList; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import java.util.Collection; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import java.util.Iterator; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import java.util.List; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import org.apache.log4j.Logger; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 /** |
770
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
17 * This class supports some helper methods for histogram charts. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
18 * |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
617
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 */ |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 public class HistogramHelper { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
770
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
23 /** |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
24 * Logger used for logging with log4j. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
25 */ |
617
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 private static Logger logger = Logger.getLogger(HistogramHelper.class); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
770
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
29 /** |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
30 * Disabled HistogramHelper constructor. This is a helper class and no |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
31 * instance should be instantiated from this class. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
32 */ |
617
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 private HistogramHelper() { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 |
770
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
37 /** |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
38 * This function prepare some input data and turns it into an array which is |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
39 * taken by {@link de.intevation.gnv.chart.DefaultHistogram}. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
40 * |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
41 * @param input A collection with the data used to be displayed in a |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
42 * histogram |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
43 * @param parameters A collection with a bunch of parameters |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
44 * @param measurements A collection with a bunch of measurements |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
45 * @param dates A collection with a bunch of dates |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
46 * |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
47 * @return Object[][] containing raw data which can be used to create |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
48 * histograms |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
49 */ |
617
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 public static Object[][] prepareHistogramData( |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 Collection input, |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 Collection parameters, |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 Collection measurements, |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 Collection dates |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 ) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 List names = new ArrayList<String>(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 List data = new ArrayList<Double[]>(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 if (logger.isDebugEnabled()) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 logger.debug("############ prepare histogram data ##########"); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 logger.debug("Input data size: " + input.size()); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 if (input == null) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 return new Object[0][0]; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 String break1, break2, break3; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 int b1Idx = -1; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 int b2Idx = -1; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 int b3Idx = -1; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 int yIdx = -1; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 try { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 Iterator iter = input.iterator(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 if (iter.hasNext()) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 Result row = (Result) iter.next(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 Result previousRow = row; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 if (b1Idx == -1) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 ResultDescriptor rd = row.getResultDescriptor(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 b1Idx = rd.getColumnIndex("GROUP1"); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 b2Idx = rd.getColumnIndex("GROUP2"); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 b3Idx = rd.getColumnIndex("GROUP3"); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 yIdx = rd.getColumnIndex("YORDINATE"); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 if (b1Idx == -1 || b2Idx == -1 || b3Idx == -1 || yIdx == -1) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 return new Object[0][0]; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 break1 = row.getString(b1Idx); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 break2 = row.getString(b2Idx); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 break3 = row.getString(b3Idx); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 List values = new ArrayList<Double>(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 while (iter.hasNext()) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 // found new series |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 if (!break1.equals(row.getString(b1Idx)) |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 || !break2.equals(row.getString(b2Idx)) |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 || !break3.equals(row.getString(b3Idx)) |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 ) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 // get parameter name |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 String name = generateName( |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 break1, break2, break3, |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 parameters, measurements, dates |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 ); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 // add values and parameter name |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 data.add((Double[]) values.toArray(new Double[values.size()])); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 names.add(name); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 if (logger.isDebugEnabled()) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 logger.debug(" --- series name: " + name); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 logger.debug(" --- series items: " + values.size()); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 values.clear(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 Double yValue = row.getDouble(yIdx); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
122 if (yValue != null) |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 values.add(yValue); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
124 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 // set new conditions to find new series |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
126 break1 = row.getString(b1Idx); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
127 break2 = row.getString(b2Idx); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
128 break3 = row.getString(b3Idx); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
130 previousRow = row; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
131 row = (Result) iter.next(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 } else { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
134 Double value = row.getDouble(yIdx); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
135 if (value != null) |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 values.add(value); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 row = (Result) iter.next(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 Double yValue = row.getDouble(yIdx); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
143 if (yValue != null) |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
144 values.add(yValue); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
145 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
146 String name = generateName( |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
147 break1, break2, break3, parameters, measurements, dates); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
149 if (logger.isDebugEnabled()) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
150 logger.debug(" --- series name: " + name); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 logger.debug(" --- series items: " + values.size()); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
153 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
154 data.add((Double[]) values.toArray(new Double[values.size()])); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
155 names.add(name); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
156 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
157 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
158 catch (Exception e) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
159 logger.error(e.getMessage(), e); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
160 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
161 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
162 int series = data.size(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
163 logger.debug(" === Found total: " + series); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
164 Object[][] obj = new Object[series][2]; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
165 for (int i = 0; i < series; i++) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
166 obj[i][0] = names.get(i); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
167 obj[i][1] = (Double[]) data.get(i); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
168 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
169 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
170 return obj; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
172 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 |
770
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
174 /** |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
175 * This method generates a string made up of parameter name and a |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
176 * measurement. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
177 * |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
178 * @param break1 Id of a parameter. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
179 * @param break2 Id of a measurement. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
180 * @param break3 Id of a date. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
181 * @param parameters A collection with a bunch of parameters. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
182 * @param measurements A collection with a bunch of measurements. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
183 * @param dates A collection with a bunch of dates. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
184 * |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
185 * @return Concatenated string (${parametername} + ${measurement} + m). |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
186 */ |
617
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 protected static String generateName( |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
188 String break1, String break2, String break3, |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
189 Collection parameters, Collection measurements, Collection dates) |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
190 { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
191 return findValueTitle(parameters,break1) + " " + |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
192 findValueTitle(measurements,break2) + "m"; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
193 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
194 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
195 |
770
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
196 /** |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
197 * Find a value with the given <code>id</code> and return its description. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
198 * |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
199 * @param values A collection which contains the value we are searching for |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
200 * @param id Id of the value |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
201 * |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
202 * @return String representation of the value. An empty string is returned |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
203 * if no value have been found with the given id. |
d70cac2bafc0
Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
617
diff
changeset
|
204 */ |
617
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
205 protected static String findValueTitle(Collection values, String id) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
206 if (values != null) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
207 Iterator it = values.iterator(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
208 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
209 while (it.hasNext()) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
210 KeyValueDescibeData data = (KeyValueDescibeData) it.next(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
211 |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
212 if (id.equals(data.getKey())) { |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
213 return data.getValue(); |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
214 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
215 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
216 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
217 return ""; |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
218 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
219 } |
3d13fa281a7e
Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
220 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |