comparison gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java @ 94:6a825a184883

Remove Compile-Errors from the StatisticsPart gnv-artifacts/trunk@139 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 28 Sep 2009 07:32:03 +0000
parents c476fbbaa4ca
children 13402ac8d8fe
comparison
equal deleted inserted replaced
93:c476fbbaa4ca 94:6a825a184883
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.io.FileReader;
19 import java.util.ArrayList; 18 import java.util.ArrayList;
20 import java.util.Calendar; 19 import java.util.Collection;
21 import java.util.Collections; 20 import java.util.Iterator;
22 import java.util.List;
23 21
24 import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; 22 import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
25 import org.apache.commons.math.stat.regression.SimpleRegression; 23 import org.apache.commons.math.stat.regression.SimpleRegression;
26 import org.apache.log4j.Logger; 24 import org.apache.log4j.Logger;
27 25
28 import au.com.bytecode.opencsv.CSVReader; 26 import de.intevation.gnv.geobackend.base.Result;
27 import de.intevation.gnv.statistics.exception.StatisticsException;
29 28
30 import de.conterra.bsh.gdi.gnviewer.datasources.ResultSet; 29
31 import de.conterra.bsh.gdi.gnviewer.datasources.Row;
32 import de.conterra.bsh.gdi.gnviewer.exception.TechnicalException;
33 import de.conterra.bsh.gdi.gnviewer.util.TempFile;
34 30
35 /** 31 /**
36 * The class <code>TimeseriesStatistics</code> fulfills the following purposes: 32 * The class <code>TimeseriesStatistics</code> fulfills the following purposes:
37 * <ol> 33 * <ol>
38 * <li></li> 34 * <li></li>
39 * </ol> 35 * </ol>
40 * 36 *
41 * @author blume 37 * @author blume
38 * @author Tim Englich <tim.englich@intevation.de>
42 * @version 1.0 39 * @version 1.0
43 * @serial 1.0 40 * @serial 1.0
44 * @see 41 * @see
45 * @since 06.12.2007 18:02:27 42 * @since 06.12.2007 18:02:27
46 */ 43 */
52 private static Logger sLogger = Logger.getLogger(TimeseriesStatistics.class); 49 private static Logger sLogger = Logger.getLogger(TimeseriesStatistics.class);
53 private static boolean sDebug = sLogger.isDebugEnabled(); 50 private static boolean sDebug = sLogger.isDebugEnabled();
54 51
55 private Statistic[] mStatistics = null; 52 private Statistic[] mStatistics = null;
56 53
57 /* 54
58 public TimeseriesStatistics(ResultSet pResults) throws TechnicalException { 55 public TimeseriesStatistics(Collection<Result> resultSet) throws StatisticsException {
59 DescriptiveStatistics lStatistics = null; 56 DescriptiveStatistics lStatistics = null;
60 SimpleRegression lRegression = null; 57 SimpleRegression lRegression = null;
61 ArrayList<Statistic> lStats = new ArrayList<Statistic>(); 58 ArrayList<Statistic> lStats = new ArrayList<Statistic>();
62 int break1, break2; 59 int break1, break2;
63 int mStart = 0; 60 int lSeries = 1;
64 int mEnd = 0; 61 if (sDebug) sLogger.debug("TimeseriesStatistics() lImageFile != null");
65 int lSeries = 1; 62 try{
66 Row[] mRow = pResults.getResults(); 63
67 64 Iterator<Result> resultIterator = resultSet.iterator();
68 break1 = mRow[mStart].getIntValue(2); 65 if (resultIterator.hasNext()){
69 break2 = mRow[mStart].getIntValue(3); 66 Result row = resultIterator.next();
70 67 break1 = row.getInteger("GROUP1");
71 for (int i = 1; i < mRow.length; i++) { 68 break2 = row.getInteger("GROUP2");
72 if (break1 != mRow[i].getIntValue(2) 69 lRegression = new SimpleRegression();
73 || break2 != mRow[i].getIntValue(3)) { 70 lStatistics = DescriptiveStatistics.newInstance();
74 lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd); 71 while (resultIterator.hasNext()) {
75 lRegression = createSimpleRegressionObject(pResults,mStart,mEnd); 72
76 addStatisticsValues(lStatistics, lRegression, lStats, lSeries); 73 if (break1 != row.getInteger("GROUP1")
77 mStart = i; 74 || break2 != row.getInteger("GROUP2")) {
78 break1 = mRow[i].getIntValue(2); 75 //lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd);
79 break2 = mRow[i].getIntValue(3); 76 //lRegression = createSimpleRegressionObject(pResults,mStart,mEnd);
80 lSeries ++; 77
81 } 78 addStatisticsValues(lStatistics, lRegression, lStats, lSeries);
82 mEnd = i; 79
83 } 80 lStatistics.clear();
84 lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd); 81 lRegression.clear();
85 lRegression = createSimpleRegressionObject(pResults,mStart,mEnd); 82
86 addStatisticsValues(lStatistics, lRegression, lStats, lSeries); 83 row = resultIterator.next();
87 84 lStatistics.addValue(row.getDouble("YORDINATE"));
88 mStatistics = new Statistic[lStats.size()]; 85 Double x = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ;
89 mStatistics = lStats.toArray(mStatistics); 86 lRegression.addData(x ,row.getDouble("YORDINATE"));
90 87
88 break1 = row.getInteger("GROUP1");
89 break2 = row.getInteger("GROUP2");
90 lSeries ++;
91 }
92 else{
93 row = resultIterator.next();
94 lStatistics.addValue(row.getDouble("YORDINATE"));
95 Double x = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ;
96 lRegression.addData(x,row.getDouble("YORDINATE"));
97 }
98
99 }
100 addStatisticsValues(lStatistics, lRegression, lStats, lSeries);
101 lStatistics.clear();
102 lRegression.clear();
103 mStatistics = new Statistic[lStats.size()];
104 mStatistics = lStats.toArray(mStatistics);
105 }
106 }
107 catch (Exception e){
108 sLogger.error(e.getMessage(), e);
109 }
91 } 110 }
92 */ 111 /**
93 public TimeseriesStatistics(TempFile lImageFile) throws TechnicalException { 112 * @param lStatistics
94 DescriptiveStatistics lStatistics = null; 113 * @param lRegression
95 SimpleRegression lRegression = null; 114 * @param lStats
96 ArrayList<Statistic> lStats = new ArrayList<Statistic>(); 115 * @param lSeries
97 int break1, break2; 116 */
98 int mStart = 0; 117 private void addStatisticsValues(DescriptiveStatistics lStatistics,
99 int mEnd = 0; 118 SimpleRegression lRegression, ArrayList<Statistic> lStats,
100 int lSeries = 1; 119 int lSeries) {
101 CSVReader reader=null; 120 lStats.add(new Statistic("gnviewer.statistics.series",(double)lSeries));
102 if (sDebug) sLogger.debug("TimeseriesStatistics() lImageFile != null");
103 try{
104 reader = new CSVReader (new FileReader(lImageFile.getFile()), ';');
105 String [] sArrayStrLine = reader.readNext();
106 Row row = new Row(sArrayStrLine);
107
108 break1 = new Integer (sArrayStrLine[2]).intValue();
109 break2 = new Integer (sArrayStrLine[3]).intValue();
110 //int i = 1;
111 lRegression = new SimpleRegression();
112 lStatistics = DescriptiveStatistics.newInstance();
113 while ((sArrayStrLine = reader.readNext()) != null) {
114
115 if (break1 != new Integer (sArrayStrLine[2]).intValue()
116 || break2 != new Integer (sArrayStrLine[3]).intValue()) {
117 //lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd);
118 //lRegression = createSimpleRegressionObject(pResults,mStart,mEnd);
119
120 addStatisticsValues(lStatistics, lRegression, lStats, lSeries);
121
122 lStatistics.clear();
123 lRegression.clear();
124
125 Row lRow = new Row (sArrayStrLine);
126 lStatistics.addValue(lRow.getDoubleValue(1));
127 Double x = new Double( (lRow.getDateValue(0)).getTime()/1000/3600) ;
128 lRegression.addData(x,lRow.getDoubleValue(1));
129
130 break1 = new Integer (sArrayStrLine[2]).intValue();
131 break2 = new Integer (sArrayStrLine[3]).intValue();
132 lSeries ++;
133 }
134 else{
135 Row lRow = new Row (sArrayStrLine);
136 lStatistics.addValue(lRow.getDoubleValue(1));
137 Double x = new Double( (lRow.getDateValue(0)).getTime()/1000/3600) ;
138 lRegression.addData(x,lRow.getDoubleValue(1));
139 }
140
141 }
142 //lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd);
143 //lRegression = createSimpleRegressionObject(pResults,mStart,mEnd);
144 addStatisticsValues(lStatistics, lRegression, lStats, lSeries);
145 lStatistics.clear();
146 lRegression.clear();
147 mStatistics = new Statistic[lStats.size()];
148 mStatistics = lStats.toArray(mStatistics);
149 }
150 catch (Exception e){
151 sLogger.error(e.getMessage(), e);
152 }
153 finally {
154 try{
155 reader.close();
156 }
157 catch (Exception e){
158 sLogger.error(e.getMessage(), e);
159 }
160 }
161
162 }
163 /**
164 * @param lStatistics
165 * @param lRegression
166 * @param lStats
167 * @param lSeries
168 */
169 private void addStatisticsValues(DescriptiveStatistics lStatistics,
170 SimpleRegression lRegression, ArrayList<Statistic> lStats,
171 int lSeries) {
172 lStats.add(new Statistic("gnviewer.statistics.series",(double)lSeries));
173 lStats.add(new Statistic("gnviewer.statistics.descriptive.arithmeticMean", lStatistics.getMean())); 121 lStats.add(new Statistic("gnviewer.statistics.descriptive.arithmeticMean", lStatistics.getMean()));
174 lStats.add(new Statistic("gnviewer.statistics.descriptive.kurtosis", lStatistics.getKurtosis())); 122 lStats.add(new Statistic("gnviewer.statistics.descriptive.kurtosis", lStatistics.getKurtosis()));
175 /* lStats.add(new Statistic("gnviewer.statistics.descriptive.kurtosisClass", lStatistics.getKurtosisClass()));*/
176 lStats.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax())); 123 lStats.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax()));
177 lStats.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin())); 124 lStats.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin()));
178 lStats.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN())); 125 lStats.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN()));
179 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.90", lStatistics.getPercentile(90))); 126 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.90", lStatistics.getPercentile(90)));
180 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.75", lStatistics.getPercentile(75))); 127 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.75", lStatistics.getPercentile(75)));
182 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.10", lStatistics.getPercentile(10))); 129 lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.10", lStatistics.getPercentile(10)));
183 lStats.add(new Statistic("gnviewer.statistics.descriptive.deviation", lStatistics.getStandardDeviation())); 130 lStats.add(new Statistic("gnviewer.statistics.descriptive.deviation", lStatistics.getStandardDeviation()));
184 lStats.add(new Statistic("gnviewer.statistics.descriptive.variance", lStatistics.getVariance())); 131 lStats.add(new Statistic("gnviewer.statistics.descriptive.variance", lStatistics.getVariance()));
185 lStats.add(new Statistic("gnviewer.statistics.descriptive.intercept", lRegression.getIntercept())); 132 lStats.add(new Statistic("gnviewer.statistics.descriptive.intercept", lRegression.getIntercept()));
186 lStats.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope())); 133 lStats.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope()));
187 } 134 }
188 135
189 136 /**
190 /** 137 *
191 * @param pResults 138 * @return
192 * @param pStart 139 */
193 * @param pEnd
194 */
195 /*
196 private SimpleRegression createSimpleRegressionObject ( ResultSet pResults, int pStart, int pEnd)throws TechnicalException{
197 SimpleRegression lRegression = new SimpleRegression();
198 Row[] lRows = pResults.getResults();
199 for (int i = pStart; i < pEnd; i++) {
200 Row lRow = lRows[i];
201 Double x = new Double( ((Calendar)lRow.getValue(0)).getTimeInMillis()/1000/3600) ;
202 lRegression.addData(x,lRow.getDoubleValue(1));
203
204 }
205 return lRegression;
206 }
207 */
208 /**
209 * @param pResults
210 * @param pStart
211 * @param pEnd
212 */
213 /*
214 private DescriptiveStatistics createDescriptiveStatisticsObject(ResultSet pResults, int pStart, int pEnd) throws TechnicalException {
215 DescriptiveStatistics lStatistics = DescriptiveStatistics.newInstance();
216 Row[] lRows = pResults.getResults();
217 for (int i = pStart; i < pEnd; i++) {
218 Row lRow = lRows[i];
219 lStatistics.addValue(lRow.getDoubleValue(1));
220 }
221 return lStatistics;
222 }
223
224 */
225 public Statistic[] getStatistics() { 140 public Statistic[] getStatistics() {
226 return mStatistics; 141 return mStatistics;
227 } 142 }
228 } 143 }

http://dive4elements.wald.intevation.org