annotate gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java @ 1115:f953c9a559d8

Added license file and license headers. gnv-artifacts/trunk@1260 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:46:55 +0000
parents dfd02f8d3602
children
rev   line source
1115
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 870
diff changeset
1 /*
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 870
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 870
diff changeset
3 *
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 870
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: 870
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: 870
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: 870
diff changeset
7 */
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 870
diff changeset
8
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
9 /**
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
10 * Title: TimeseriesStatistics, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/output/statistics/TimeseriesStatistics.java,v 1.3 2008/08/18 14:50:33 drewnak Exp $
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
11 * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/output/statistics/TimeseriesStatistics.java,v $
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
12 * created by: Stefan Blume (blume)
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
13 * erstellt am: 06.12.2007
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
14 * Copyright: con terra GmbH, 2005
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
15 *
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
16 * modified by: $Author: drewnak $
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
17 * modified on: $Date: 2008/08/18 14:50:33 $
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
18 * Version: $Revision: 1.3 $
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
19 * TAG: $Name: $
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
20 * locked from: $Locker: $
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
21 * CVS State: $State: Exp $
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
22 * Project: $ProjectName$
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
23 */
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
24 package de.intevation.gnv.statistics;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
25
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
26 import de.intevation.gnv.geobackend.base.Result;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
27 import de.intevation.gnv.geobackend.base.ResultDescriptor;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
28
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
29 import de.intevation.gnv.state.describedata.KeyValueDescibeData;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
30
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
31 import de.intevation.gnv.statistics.exception.StatisticsException;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
32
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
33 import java.sql.SQLException;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
34
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
35 import java.util.ArrayList;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
36 import java.util.Collection;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
37 import java.util.Iterator;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
38
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
39 import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
40
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
41 import org.apache.commons.math.stat.regression.SimpleRegression;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
42
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
43 import org.apache.log4j.Logger;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
44
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
45 /**
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
46 * This class is used to create a statistic in timeseries products.
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
47 *
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
48 * @author blume
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
49 */
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
50 public class TimeseriesStatistics
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
51 extends AbstractStatistics
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
52 {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
53
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
54 /**
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
55 * Default Logging instance
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
56 */
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
57 private static Logger log = Logger.getLogger(TimeseriesStatistics.class);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
58
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
59 /**
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
60 * Constructor
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
61 */
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
62 public TimeseriesStatistics() {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
63 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
64
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
65
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
66 public Collection<StatisticSet> calculateStatistics(
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
67 Object result,
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
68 Collection<KeyValueDescibeData> parameters,
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
69 Collection<KeyValueDescibeData> measurements,
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
70 Collection<KeyValueDescibeData> dates
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
71 )
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
72 throws StatisticsException {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
73
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
74 if (!(result instanceof Collection)) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
75 return new ArrayList<StatisticSet>();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
76 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
77
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
78 Collection<Result> resultSet = (Collection<Result>)result;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
79
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
80 clearStatistics();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
81
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
82 DescriptiveStatistics lStatistics = null;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
83 SimpleRegression lRegression = null;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
84 Collection<StatisticSet> statisticSets = new ArrayList<StatisticSet>();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
85 String break1, break2, break3;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
86 int lSeries = 1;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
87
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
88 if (resultSet == null) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
89 return statisticSets;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
90 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
91
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
92 int b1Idx = -1;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
93 int b2Idx = -1;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
94 int b3Idx = -1;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
95 int yIdx = -1;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
96 try {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
97
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
98 Iterator<Result> resultIterator = resultSet.iterator();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
99 if (resultIterator.hasNext()) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
100 Result row = resultIterator.next();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
101 Result previousRow = row;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
102
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
103 if (b1Idx == -1) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
104 ResultDescriptor rd = row.getResultDescriptor();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
105 b1Idx = rd.getColumnIndex("GROUP1");
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
106 b2Idx = rd.getColumnIndex("GROUP2");
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
107 b3Idx = rd.getColumnIndex("GROUP3");
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
108 yIdx = rd.getColumnIndex("YORDINATE");
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
109
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
110 if (b1Idx == -1 || b2Idx == -1 || b3Idx == -1 || yIdx == -1) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
111 return statisticSets;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
112 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
113 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
114 break1 = row.getString(b1Idx);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
115 break2 = row.getString(b2Idx);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
116 break3 = row.getString(b3Idx);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
117 lRegression = new SimpleRegression();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
118 lStatistics = new DescriptiveStatistics();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
119 while (resultIterator.hasNext()) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
120
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
121 if (!break1.equals(row.getString(b1Idx))
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
122 || !break2.equals(row.getString(b2Idx))
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
123 || !break3.equals(row.getString(b3Idx))
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
124 ) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
125 String statisticsName = generateStatisticsName(
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
126 break1, break2,
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
127 break3, parameters,
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
128 measurements, dates);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
129
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
130 statisticSets.add(
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
131 generateStatisticsValues(
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
132 lStatistics,
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
133 lRegression,
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
134 statisticsName));
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
135
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
136 lStatistics.clear();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
137 lRegression.clear();
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
138
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
139 clearStatistics();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
140
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
141 Double yValue = row.getDouble(yIdx);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
142
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
143 if (yValue != null) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
144 lStatistics.addValue(yValue);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
145 Double x = calculateXOrdinateValue(previousRow,row);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
146 lRegression.addData(x, yValue);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
147 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
148
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
149 break1 = row.getString(b1Idx);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
150 break2 = row.getString(b2Idx);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
151 break3 = row.getString(b3Idx);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
152 previousRow = row;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
153 row = resultIterator.next();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
154 lSeries++;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
155 } else {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
156
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
157 Double value = row.getDouble(yIdx);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
158 if (value != null) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
159 lStatistics.addValue(value.doubleValue());
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
160 Double x = calculateXOrdinateValue(previousRow,row);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
161 lRegression.addData(x, value.doubleValue());
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
162 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
163 previousRow = row;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
164 row = resultIterator.next();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
165 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
166
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
167 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
168
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
169 Double yValue = row.getDouble(yIdx);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
170
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
171 if (yValue != null) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
172 lStatistics.addValue(yValue);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
173 Double x = calculateXOrdinateValue(previousRow, row);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
174 lRegression.addData(x, yValue);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
175 }
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
176
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
177 String statisticsName = generateStatisticsName(
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
178 break1, break2,
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
179 break3, parameters,
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
180 measurements, dates);
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
181
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
182 statisticSets.add(generateStatisticsValues(
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
183 lStatistics,
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
184 lRegression,
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
185 statisticsName));
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
186 lStatistics.clear();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
187 lRegression.clear();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
188 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
189 } catch (Exception e) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
190 log.error(e.getMessage(), e);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
191 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
192
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
193 return statisticSets;
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
194 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
195
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
196 /**
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
197 * Nothing is done here.
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
198 */
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
199 protected void clearStatistics(){}
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
200
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
201
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
202 protected String generateStatisticsName(String break1,
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
203 String break2,
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
204 String break3,
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
205 Collection<KeyValueDescibeData> parameters,
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
206 Collection<KeyValueDescibeData> measurements,
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
207 Collection<KeyValueDescibeData> dates){
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
208 log.debug("TimeseriesStatistics.generateStatisticsName");
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
209 return this.findValueTitle(parameters,break1)+ " "+
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
210 this.findValueTitle(measurements,break2) + "m";
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
211 }
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
212
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
213
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
214 protected String findValueTitle(Collection<KeyValueDescibeData> values,
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
215 String id) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
216 log.debug("TimeseriesStatistics.findValueTitle "+ id);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
217 if (values != null) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
218 Iterator<KeyValueDescibeData> it = values.iterator();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
219 while (it.hasNext()) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
220 KeyValueDescibeData data = it.next();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
221 if (id.equals(data.getKey())) {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
222 return data.getValue();
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
223 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
224 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
225 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
226 return "";
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
227 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
228
870
dfd02f8d3602 Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
229
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
230 protected double calculateXOrdinateValue(Result previousRow, Result row) throws SQLException {
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
231 return new Double((row.getDate("XORDINATE")).getTime() / 1000 / 3600);
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
232 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
233 }
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 814
diff changeset
234 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org