comparison gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java @ 98:156db25ad4b4

Add Statisticssupport also to VerticalProfiles gnv-artifacts/trunk@144 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 28 Sep 2009 10:20:41 +0000
parents fce237b6fdb8
children 158e89c2263b
comparison
equal deleted inserted replaced
97:fce237b6fdb8 98:156db25ad4b4
13 * CVS State: $State: Exp $ 13 * CVS State: $State: Exp $
14 * Project: $ProjectName$ 14 * Project: $ProjectName$
15 */ 15 */
16 package de.intevation.gnv.statistics; 16 package de.intevation.gnv.statistics;
17 17
18 import java.sql.SQLException;
18 import java.util.ArrayList; 19 import java.util.ArrayList;
19 import java.util.Collection; 20 import java.util.Collection;
20 import java.util.Iterator; 21 import java.util.Iterator;
21 22
22 import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; 23 import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
23 import org.apache.commons.math.stat.regression.SimpleRegression; 24 import org.apache.commons.math.stat.regression.SimpleRegression;
24 import org.apache.log4j.Logger; 25 import org.apache.log4j.Logger;
25 26
26 import de.intevation.gnv.geobackend.base.Result; 27 import de.intevation.gnv.geobackend.base.Result;
28 import de.intevation.gnv.geobackend.sde.datasources.ResultSet;
27 import de.intevation.gnv.statistics.exception.StatisticsException; 29 import de.intevation.gnv.statistics.exception.StatisticsException;
28 30
29 31
30 32
31 /** 33 /**
53 55
54 public TimeseriesStatistics(){ 56 public TimeseriesStatistics(){
55 super(); 57 super();
56 } 58 }
57 59
60 /**
61 * @see de.intevation.gnv.statistics.Statistics#calculateStatistics(java.util.Collection)
62 */
58 public Collection<Statistic> calculateStatistics(Collection<Result> resultSet) throws StatisticsException { 63 public Collection<Statistic> calculateStatistics(Collection<Result> resultSet) throws StatisticsException {
59 DescriptiveStatistics lStatistics = null; 64 DescriptiveStatistics lStatistics = null;
60 SimpleRegression lRegression = null; 65 SimpleRegression lRegression = null;
61 statistics = new ArrayList<Statistic>(); 66 statistics = new ArrayList<Statistic>();
62 int break1, break2; 67 String break1, break2;
63 int lSeries = 1; 68 int lSeries = 1;
64 try{ 69 try{
65 70
66 Iterator<Result> resultIterator = resultSet.iterator(); 71 Iterator<Result> resultIterator = resultSet.iterator();
67 if (resultIterator.hasNext()){ 72 if (resultIterator.hasNext()){
68 Result row = resultIterator.next(); 73 Result row = resultIterator.next();
69 break1 = row.getInteger("GROUP1"); 74 break1 = row.getString("GROUP1");
70 break2 = row.getInteger("GROUP2"); 75 break2 = row.getString("GROUP2");
71 lRegression = new SimpleRegression(); 76 lRegression = new SimpleRegression();
72 lStatistics = DescriptiveStatistics.newInstance(); 77 lStatistics = DescriptiveStatistics.newInstance();
73 while (resultIterator.hasNext()) { 78 while (resultIterator.hasNext()) {
74 79
75 if (break1 != row.getInteger("GROUP1") 80 if (!break1.equals(row.getString("GROUP1"))
76 || break2 != row.getInteger("GROUP2")) { 81 || !break2.equals(row.getString("GROUP2"))) {
77 addStatisticsValues(lStatistics, lRegression, lSeries); 82 addStatisticsValues(lStatistics, lRegression, lSeries);
78 83
79 lStatistics.clear(); 84 lStatistics.clear();
80 lRegression.clear(); 85 lRegression.clear();
81 86
82 lStatistics.addValue(row.getDouble("YORDINATE")); 87 lStatistics.addValue(row.getDouble("YORDINATE"));
83 Double x = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; 88 Double x = this.calculateXOrdinateValue(row);
84 lRegression.addData(x ,row.getDouble("YORDINATE")); 89 lRegression.addData(x ,row.getDouble("YORDINATE"));
85 90
86 break1 = row.getInteger("GROUP1"); 91 break1 = row.getString("GROUP1");
87 break2 = row.getInteger("GROUP2"); 92 break2 = row.getString("GROUP2");
88 row = resultIterator.next(); 93 row = resultIterator.next();
89 lSeries ++; 94 lSeries ++;
90 } 95 }
91 else{ 96 else{
92 97
93 lStatistics.addValue(row.getDouble("YORDINATE")); 98 lStatistics.addValue(row.getDouble("YORDINATE"));
94 Double x = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; 99 Double x = this.calculateXOrdinateValue(row);
95 lRegression.addData(x,row.getDouble("YORDINATE")); 100 lRegression.addData(x,row.getDouble("YORDINATE"));
96 row = resultIterator.next(); 101 row = resultIterator.next();
97 } 102 }
98 103
99 } 104 }
106 log.error(e.getMessage(), e); 111 log.error(e.getMessage(), e);
107 } 112 }
108 113
109 return statistics; 114 return statistics;
110 } 115 }
116
117
118 protected double calculateXOrdinateValue(Result row) throws SQLException{
119 return new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ;
120 }
121
111 122
112 /** 123 /**
113 * @param lStatistics 124 * @param lStatistics
114 * @param lRegression 125 * @param lRegression
115 * @param lStats 126 * @param lStats

http://dive4elements.wald.intevation.org