annotate gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java @ 1085:ec512e7992c6

Improved data initialization and axis range calculation in vertical profiles (scalar and vector). gnv-artifacts/trunk@1187 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 09 Jun 2010 17:11:54 +0000
parents 846b2b70b2e0
children f953c9a559d8
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
1081
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
3 import de.intevation.artifacts.CallContext;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
4
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
5 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
6
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
7 import de.intevation.gnv.chart.ChartLabels;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
8
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import de.intevation.gnv.geobackend.base.Result;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import de.intevation.gnv.geobackend.base.ResultDescriptor;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import de.intevation.gnv.state.describedata.KeyValueDescibeData;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import java.util.ArrayList;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import java.util.Collection;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import java.util.Iterator;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import java.util.List;
1081
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
18 import java.util.Locale;
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 import org.apache.log4j.Logger;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
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 * 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
24 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
25 * @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
26 */
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 public class HistogramHelper {
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 * 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
31 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 private static Logger logger = Logger.getLogger(HistogramHelper.class);
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
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
35 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
36 * 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
37 * 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
38 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 private HistogramHelper() {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
43 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
44 * 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
45 * 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
46 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
47 * @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
48 * histogram
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
49 * @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
50 * @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
51 * @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
52 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
53 * @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
54 * histograms
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
55 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 public static Object[][] prepareHistogramData(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 Collection input,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 Collection parameters,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 Collection measurements,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 Collection dates
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 List names = new ArrayList<String>();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 List data = new ArrayList<Double[]>();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 if (logger.isDebugEnabled()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 logger.debug("############ prepare histogram data ##########");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 logger.debug("Input data size: " + input.size());
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 if (input == null) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 return new Object[0][0];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 String break1, break2, break3;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 int b1Idx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 int b2Idx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 int b3Idx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 int yIdx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 try {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 Iterator iter = input.iterator();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 if (iter.hasNext()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 Result row = (Result) iter.next();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 Result previousRow = row;
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) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 ResultDescriptor rd = row.getResultDescriptor();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 b1Idx = rd.getColumnIndex("GROUP1");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 b2Idx = rd.getColumnIndex("GROUP2");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 b3Idx = rd.getColumnIndex("GROUP3");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 yIdx = rd.getColumnIndex("YORDINATE");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 if (b1Idx == -1 || b2Idx == -1 || b3Idx == -1 || yIdx == -1) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 return new Object[0][0];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 }
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 break1 = row.getString(b1Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 break2 = row.getString(b2Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 break3 = row.getString(b3Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 List values = new ArrayList<Double>();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 while (iter.hasNext()) {
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 // found new series
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 if (!break1.equals(row.getString(b1Idx))
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 || !break2.equals(row.getString(b2Idx))
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 || !break3.equals(row.getString(b3Idx))
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 // get parameter name
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 String name = generateName(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 break1, break2, break3,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 parameters, measurements, dates
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 );
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 // add values and parameter name
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 data.add((Double[]) values.toArray(new Double[values.size()]));
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 names.add(name);
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 if (logger.isDebugEnabled()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 logger.debug(" --- series name: " + name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 logger.debug(" --- series items: " + values.size());
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
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 values.clear();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 Double yValue = row.getDouble(yIdx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 if (yValue != null)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 values.add(yValue);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 // set new conditions to find new series
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 break1 = row.getString(b1Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 break2 = row.getString(b2Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 break3 = row.getString(b3Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 previousRow = row;
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 } else {
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 Double value = row.getDouble(yIdx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 if (value != null)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 values.add(value);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 row = (Result) iter.next();
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 }
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 Double yValue = row.getDouble(yIdx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 if (yValue != null)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 values.add(yValue);
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 String name = generateName(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 break1, break2, break3, parameters, measurements, dates);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 if (logger.isDebugEnabled()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 logger.debug(" --- series name: " + name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 logger.debug(" --- series items: " + values.size());
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 }
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 data.add((Double[]) values.toArray(new Double[values.size()]));
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 names.add(name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 catch (Exception e) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 logger.error(e.getMessage(), e);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166 }
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 int series = data.size();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 logger.debug(" === Found total: " + series);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 Object[][] obj = new Object[series][2];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 for (int i = 0; i < series; i++) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 obj[i][0] = names.get(i);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 obj[i][1] = (Double[]) data.get(i);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 return obj;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
180 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
181 * 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
182 * measurement.
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 * @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
185 * @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
186 * @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
187 * @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
188 * @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
189 * @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
190 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
191 * @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
192 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 protected static String generateName(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 String break1, String break2, String break3,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 Collection parameters, Collection measurements, Collection dates)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197 return findValueTitle(parameters,break1) + " " +
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 findValueTitle(measurements,break2) + "m";
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
202 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
203 * 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
204 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
205 * @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
206 * @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
207 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
208 * @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
209 * 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
210 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 protected static String findValueTitle(Collection values, String id) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212 if (values != null) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
213 Iterator it = values.iterator();
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 while (it.hasNext()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 KeyValueDescibeData data = (KeyValueDescibeData) it.next();
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 if (id.equals(data.getKey())) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 return data.getValue();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 return "";
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224 }
1080
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
225
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
226
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
227 /**
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
228 * Creates and returns labels to decorate histograms.
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
229 *
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
230 * @param uuid The UUID of the current artifact.
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
231 * @param context The CallContext object.
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
232 * @param data An array storing strings.
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
233 * @return A ChartLabels object with the 1st string in <i>data</i> as title.
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
234 */
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
235 public static ChartLabels createHistogramLabels(
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
236 String uuid, CallContext context, Locale locale, Object[] data)
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
237 {
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
238 RessourceFactory fac = RessourceFactory.getInstance();
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
239
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
240 return new ChartLabels(
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
241 (String) data[0],
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
242 "",
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
243 "",
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
244 fac.getRessource(locale, "histogram.axis.range.title", ""));
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
245 }
1081
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
246
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
247
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
248 public static Object[][] prepareVectorialHistogramData(Collection input) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
249 List names = new ArrayList<String>();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
250 List data = new ArrayList<Double[]>();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
251
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
252 if (logger.isDebugEnabled()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
253 logger.debug("######### prepare vectorial histogram data #######");
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
254 logger.debug("Input data size: " + input.size());
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
255 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
256
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
257 if (input == null) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
258 return new Object[0][0];
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
259 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
260
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
261 int sIdx = -1;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
262 int yIdx = -1;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
263
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
264 String series = null;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
265
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
266 try {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
267 Iterator iter = input.iterator();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
268
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
269 if (iter.hasNext()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
270 Result row = (Result) iter.next();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
271 Result previousRow = row;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
272
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
273 if (sIdx == -1 || yIdx == -1) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
274 ResultDescriptor rd = row.getResultDescriptor();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
275 sIdx = rd.getColumnIndex("SERIES");
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
276 yIdx = rd.getColumnIndex("YORDINATE");
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
277
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
278 if (sIdx == -1 || yIdx == -1) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
279 return new Object[0][0];
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
280 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
281 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
282
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
283 List values = new ArrayList<Double>();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
284 while (iter.hasNext()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
285 row = (Result) iter.next();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
286
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
287 // found new series
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
288 if (series != null && !series.equals(row.getString(sIdx))) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
289
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
290 // add values and parameter name
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
291 data.add((Double[])
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
292 values.toArray(new Double[values.size()]));
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
293 names.add(series);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
294
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
295 if (logger.isDebugEnabled()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
296 logger.debug(" --- series name: " + series);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
297 logger.debug(" --- series items: " + values.size());
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
298 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
299
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
300 values.clear();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
301 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
302
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
303 Double value = row.getDouble(yIdx);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
304 if (value != null)
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
305 values.add(value);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
306
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
307 series = row.getString(sIdx);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
308 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
309
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
310 if (logger.isDebugEnabled()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
311 logger.debug(" --- series name: " + series);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
312 logger.debug(" --- series items: " + values.size());
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
313 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
314
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
315 data.add((Double[]) values.toArray(new Double[values.size()]));
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
316 names.add(series);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
317 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
318 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
319 catch (Exception e) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
320 logger.error(e.getMessage(), e);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
321 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
322
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
323 int count = data.size();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
324 logger.debug(" === Found total: " + count);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
325 Object[][] obj = new Object[count][2];
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
326 for (int i = 0; i < count; i++) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
327 obj[i][0] = names.get(i);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
328 obj[i][1] = (Double[]) data.get(i);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
329 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
330
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
331 return obj;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
332 }
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
333 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
334 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org