annotate gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java @ 799:feeaf5aec552

ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries gnv-artifacts/trunk@881 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 06 Apr 2010 11:56:53 +0000
parents b1f5f2a8840f
children 01e26528bb39
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 /**
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
16 * 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
17 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
18 * @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
19 */
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 public class HistogramHelper {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
22 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
23 * 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
24 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 private static Logger logger = Logger.getLogger(HistogramHelper.class);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
28 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
29 * 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
30 * 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
31 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 private HistogramHelper() {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 }
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
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
36 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
37 * 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
38 * 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
39 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
40 * @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
41 * histogram
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
42 * @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
43 * @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
44 * @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
45 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
46 * @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
47 * histograms
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
48 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 public static Object[][] prepareHistogramData(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 Collection input,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 Collection parameters,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 Collection measurements,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 Collection dates
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 ) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 List names = new ArrayList<String>();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 List data = new ArrayList<Double[]>();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 if (logger.isDebugEnabled()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 logger.debug("############ prepare histogram data ##########");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 logger.debug("Input data size: " + input.size());
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 }
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 if (input == null) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 return new Object[0][0];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 }
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 String break1, break2, break3;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 int b1Idx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 int b2Idx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 int b3Idx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 int yIdx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 try {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 Iterator iter = input.iterator();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 if (iter.hasNext()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 Result row = (Result) iter.next();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 Result previousRow = row;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 if (b1Idx == -1) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 ResultDescriptor rd = row.getResultDescriptor();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 b1Idx = rd.getColumnIndex("GROUP1");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 b2Idx = rd.getColumnIndex("GROUP2");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 b3Idx = rd.getColumnIndex("GROUP3");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 yIdx = rd.getColumnIndex("YORDINATE");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 if (b1Idx == -1 || b2Idx == -1 || b3Idx == -1 || yIdx == -1) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 return new Object[0][0];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 }
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 break1 = row.getString(b1Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 break2 = row.getString(b2Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 break3 = row.getString(b3Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 List values = new ArrayList<Double>();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 while (iter.hasNext()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 // found new series
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 if (!break1.equals(row.getString(b1Idx))
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 || !break2.equals(row.getString(b2Idx))
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 || !break3.equals(row.getString(b3Idx))
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 ) {
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 // get parameter name
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 String name = generateName(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 break1, break2, break3,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 parameters, measurements, dates
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 );
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 // add values and parameter name
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 data.add((Double[]) values.toArray(new Double[values.size()]));
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 names.add(name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 if (logger.isDebugEnabled()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 logger.debug(" --- series name: " + name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 logger.debug(" --- series items: " + values.size());
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 }
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 values.clear();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 Double yValue = row.getDouble(yIdx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 if (yValue != null)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 values.add(yValue);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 // set new conditions to find new series
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 break1 = row.getString(b1Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 break2 = row.getString(b2Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 break3 = row.getString(b3Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 previousRow = row;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 row = (Result) iter.next();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 } else {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 Double value = row.getDouble(yIdx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 if (value != null)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 values.add(value);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 row = (Result) iter.next();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 }
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 Double yValue = row.getDouble(yIdx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 if (yValue != null)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 values.add(yValue);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 String name = generateName(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 break1, break2, break3, parameters, measurements, dates);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 if (logger.isDebugEnabled()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 logger.debug(" --- series name: " + name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 logger.debug(" --- series items: " + values.size());
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 }
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 data.add((Double[]) values.toArray(new Double[values.size()]));
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 names.add(name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 }
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 catch (Exception e) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 logger.error(e.getMessage(), e);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 }
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 int series = data.size();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 logger.debug(" === Found total: " + series);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163 Object[][] obj = new Object[series][2];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 for (int i = 0; i < series; i++) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 obj[i][0] = names.get(i);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166 obj[i][1] = (Double[]) data.get(i);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 }
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 return obj;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 }
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
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
173 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
174 * 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
175 * measurement.
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
176 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
177 * @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
178 * @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
179 * @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
180 * @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
181 * @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
182 * @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
183 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
184 * @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
185 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 protected static String generateName(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 String break1, String break2, String break3,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 Collection parameters, Collection measurements, Collection dates)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190 return findValueTitle(parameters,break1) + " " +
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 findValueTitle(measurements,break2) + "m";
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 }
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
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
195 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
196 * 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
197 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
198 * @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
199 * @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
200 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
201 * @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
202 * 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
203 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 protected static String findValueTitle(Collection values, String id) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 if (values != null) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 Iterator it = values.iterator();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
208 while (it.hasNext()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 KeyValueDescibeData data = (KeyValueDescibeData) it.next();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 if (id.equals(data.getKey())) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212 return data.getValue();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
213 }
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 return "";
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org