annotate gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java @ 1129:ccfa07b88476

merged geo-backend
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:01 +0200
parents f953c9a559d8
children
rev   line source
1115
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1081
diff changeset
1 /*
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1081
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1081
diff changeset
3 *
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1081
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1081
diff changeset
5 * Read the file LGPL.txt coming with the software for details
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1081
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1081
diff changeset
7 */
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1081
diff changeset
8
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 package de.intevation.gnv.histogram;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
1081
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
11 import de.intevation.artifacts.CallContext;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
12
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
13 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
14
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
15 import de.intevation.gnv.chart.ChartLabels;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
16
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import de.intevation.gnv.geobackend.base.Result;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import de.intevation.gnv.geobackend.base.ResultDescriptor;
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 de.intevation.gnv.state.describedata.KeyValueDescibeData;
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 import java.util.ArrayList;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 import java.util.Collection;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 import java.util.Iterator;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 import java.util.List;
1081
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
26 import java.util.Locale;
617
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 import org.apache.log4j.Logger;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 /**
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
31 * 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
32 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
33 * @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
34 */
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public class HistogramHelper {
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 * 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
39 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 private static Logger logger = Logger.getLogger(HistogramHelper.class);
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 * 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
45 * 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
46 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 private HistogramHelper() {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
51 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
52 * 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
53 * 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
54 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
55 * @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
56 * histogram
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
57 * @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
58 * @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
59 * @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
60 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
61 * @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
62 * histograms
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
63 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 public static Object[][] prepareHistogramData(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 Collection input,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 Collection parameters,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 Collection measurements,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 Collection dates
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 List names = new ArrayList<String>();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 List data = new ArrayList<Double[]>();
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 if (logger.isDebugEnabled()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 logger.debug("############ prepare histogram data ##########");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 logger.debug("Input data size: " + input.size());
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 if (input == null) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 return new Object[0][0];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 }
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 String break1, break2, break3;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 int b1Idx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 int b2Idx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 int b3Idx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 int yIdx = -1;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 try {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 Iterator iter = input.iterator();
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 if (iter.hasNext()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 Result row = (Result) iter.next();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 Result previousRow = row;
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 if (b1Idx == -1) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 ResultDescriptor rd = row.getResultDescriptor();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 b1Idx = rd.getColumnIndex("GROUP1");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 b2Idx = rd.getColumnIndex("GROUP2");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 b3Idx = rd.getColumnIndex("GROUP3");
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 yIdx = rd.getColumnIndex("YORDINATE");
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 if (b1Idx == -1 || b2Idx == -1 || b3Idx == -1 || yIdx == -1) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 return new Object[0][0];
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 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 break1 = row.getString(b1Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 break2 = row.getString(b2Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 break3 = 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 List values = new ArrayList<Double>();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 while (iter.hasNext()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 // found new series
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 if (!break1.equals(row.getString(b1Idx))
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 || !break2.equals(row.getString(b2Idx))
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 || !break3.equals(row.getString(b3Idx))
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 // get parameter name
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 String name = generateName(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 break1, break2, break3,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 parameters, measurements, dates
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 );
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 // add values and parameter name
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 data.add((Double[]) values.toArray(new Double[values.size()]));
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 names.add(name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 if (logger.isDebugEnabled()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 logger.debug(" --- series name: " + name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 logger.debug(" --- series items: " + values.size());
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 }
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 values.clear();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 Double yValue = row.getDouble(yIdx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 if (yValue != null)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 values.add(yValue);
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 // set new conditions to find new series
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 break1 = row.getString(b1Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 break2 = row.getString(b2Idx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 break3 = row.getString(b3Idx);
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 previousRow = row;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 row = (Result) iter.next();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 } else {
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 value = row.getDouble(yIdx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 if (value != null)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 values.add(value);
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 row = (Result) iter.next();
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 }
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 Double yValue = row.getDouble(yIdx);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 if (yValue != null)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 values.add(yValue);
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 String name = generateName(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 break1, break2, break3, parameters, measurements, dates);
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 if (logger.isDebugEnabled()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 logger.debug(" --- series name: " + name);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 logger.debug(" --- series items: " + values.size());
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 data.add((Double[]) values.toArray(new Double[values.size()]));
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 names.add(name);
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 catch (Exception e) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 logger.error(e.getMessage(), e);
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 int series = data.size();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 logger.debug(" === Found total: " + series);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 Object[][] obj = new Object[series][2];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 for (int i = 0; i < series; i++) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 obj[i][0] = names.get(i);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 obj[i][1] = (Double[]) data.get(i);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 return obj;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
188 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
189 * 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
190 * measurement.
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
191 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
192 * @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
193 * @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
194 * @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
195 * @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
196 * @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
197 * @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
198 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
199 * @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
200 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 protected static String generateName(
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 String break1, String break2, String break3,
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 Collection parameters, Collection measurements, Collection dates)
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 return findValueTitle(parameters,break1) + " " +
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 findValueTitle(measurements,break2) + "m";
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
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209
770
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
210 /**
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
211 * 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
212 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
213 * @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
214 * @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
215 *
d70cac2bafc0 Added and repaired javadoc in de.intevation.gnv.histogram package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 617
diff changeset
216 * @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
217 * 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
218 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 protected static String findValueTitle(Collection values, String id) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 if (values != null) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221 Iterator it = values.iterator();
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 while (it.hasNext()) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224 KeyValueDescibeData data = (KeyValueDescibeData) it.next();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 if (id.equals(data.getKey())) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 return data.getValue();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
228 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
229 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
230 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
231 return "";
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232 }
1080
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
233
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 /**
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
236 * 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
237 *
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
238 * @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
239 * @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
240 * @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
241 * @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
242 */
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
243 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
244 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
245 {
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
246 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
247
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
248 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
249 (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
250 "",
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
251 "",
01e26528bb39 Some code refactoring for the implementation of histograms using vectorial parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
252 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
253 }
1081
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
254
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 public static Object[][] prepareVectorialHistogramData(Collection input) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
257 List names = new ArrayList<String>();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
258 List data = new ArrayList<Double[]>();
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 if (logger.isDebugEnabled()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
261 logger.debug("######### prepare vectorial histogram data #######");
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
262 logger.debug("Input data size: " + input.size());
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
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
265 if (input == null) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
266 return new Object[0][0];
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
267 }
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 int sIdx = -1;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
270 int yIdx = -1;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
271
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
272 String series = null;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
273
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
274 try {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
275 Iterator iter = input.iterator();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
276
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
277 if (iter.hasNext()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
278 Result row = (Result) iter.next();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
279 Result previousRow = row;
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 if (sIdx == -1 || yIdx == -1) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
282 ResultDescriptor rd = row.getResultDescriptor();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
283 sIdx = rd.getColumnIndex("SERIES");
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
284 yIdx = rd.getColumnIndex("YORDINATE");
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
285
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
286 if (sIdx == -1 || yIdx == -1) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
287 return new Object[0][0];
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
288 }
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
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
291 List values = new ArrayList<Double>();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
292 while (iter.hasNext()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
293 row = (Result) iter.next();
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 // found new series
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
296 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
297
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
298 // add values and parameter name
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
299 data.add((Double[])
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
300 values.toArray(new Double[values.size()]));
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
301 names.add(series);
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 if (logger.isDebugEnabled()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
304 logger.debug(" --- series name: " + series);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
305 logger.debug(" --- series items: " + values.size());
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
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
308 values.clear();
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
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
311 Double value = row.getDouble(yIdx);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
312 if (value != null)
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
313 values.add(value);
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 series = row.getString(sIdx);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
316 }
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 if (logger.isDebugEnabled()) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
319 logger.debug(" --- series name: " + series);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
320 logger.debug(" --- series items: " + values.size());
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 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
324 names.add(series);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
325 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
326 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
327 catch (Exception e) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
328 logger.error(e.getMessage(), e);
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 int count = data.size();
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
332 logger.debug(" === Found total: " + count);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
333 Object[][] obj = new Object[count][2];
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
334 for (int i = 0; i < count; i++) {
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
335 obj[i][0] = names.get(i);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
336 obj[i][1] = (Double[]) data.get(i);
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
337 }
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
338
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
339 return obj;
846b2b70b2e0 Implemented histogram creation for vectorial timeseries.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1080
diff changeset
340 }
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
341 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
342 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org