Mercurial > dive4elements > gnv-client
changeset 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 |
files | gnv-artifacts/Changelog gnv-artifacts/pom.xml gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/exception/StatisticsException.java |
diffstat | 4 files changed, 137 insertions(+), 160 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/Changelog Mon Sep 28 07:27:06 2009 +0000 +++ b/gnv-artifacts/Changelog Mon Sep 28 07:32:03 2009 +0000 @@ -1,3 +1,13 @@ +2009-09-28 Tim Englich <tim.englich@intevation.de> + + * pom.xml Edited: + Added Link to Apache-Commons-Math to get the required Classes for the calculation + of Statistics. + * src/main/java/de/intevation/gnv/statistics/exception/StatisticsException.java Added: + Specified ExceptionClass for the Statistics Part of the gnv-artifacts + * src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Edited: + Remove compileErrors and switch to new Datastructure + 2009-09-28 Tim Englich <tim.englich@intevation.de> * src/main/java/de/intevation/gnv/statistics/Statistic.java Added ,
--- a/gnv-artifacts/pom.xml Mon Sep 28 07:27:06 2009 +0000 +++ b/gnv-artifacts/pom.xml Mon Sep 28 07:32:03 2009 +0000 @@ -57,6 +57,11 @@ <artifactId>opencsv</artifactId> <version>2.0</version> </dependency> + <dependency> + <groupId>commons-math</groupId> + <artifactId>commons-math</artifactId> + <version>1.1</version> + </dependency> </dependencies> </project>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Mon Sep 28 07:27:06 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Mon Sep 28 07:32:03 2009 +0000 @@ -15,22 +15,18 @@ */ package de.intevation.gnv.statistics; -import java.io.FileReader; import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.List; +import java.util.Collection; +import java.util.Iterator; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; import org.apache.commons.math.stat.regression.SimpleRegression; import org.apache.log4j.Logger; -import au.com.bytecode.opencsv.CSVReader; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.statistics.exception.StatisticsException; -import de.conterra.bsh.gdi.gnviewer.datasources.ResultSet; -import de.conterra.bsh.gdi.gnviewer.datasources.Row; -import de.conterra.bsh.gdi.gnviewer.exception.TechnicalException; -import de.conterra.bsh.gdi.gnviewer.util.TempFile; + /** * The class <code>TimeseriesStatistics</code> fulfills the following purposes: @@ -39,6 +35,7 @@ * </ol> * * @author blume + * @author Tim Englich <tim.englich@intevation.de> * @version 1.0 * @serial 1.0 * @see @@ -54,125 +51,75 @@ private Statistic[] mStatistics = null; - /* - public TimeseriesStatistics(ResultSet pResults) throws TechnicalException { - DescriptiveStatistics lStatistics = null; - SimpleRegression lRegression = null; - ArrayList<Statistic> lStats = new ArrayList<Statistic>(); - int break1, break2; - int mStart = 0; - int mEnd = 0; - int lSeries = 1; - Row[] mRow = pResults.getResults(); - - break1 = mRow[mStart].getIntValue(2); - break2 = mRow[mStart].getIntValue(3); - - for (int i = 1; i < mRow.length; i++) { - if (break1 != mRow[i].getIntValue(2) - || break2 != mRow[i].getIntValue(3)) { - lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd); - lRegression = createSimpleRegressionObject(pResults,mStart,mEnd); - addStatisticsValues(lStatistics, lRegression, lStats, lSeries); - mStart = i; - break1 = mRow[i].getIntValue(2); - break2 = mRow[i].getIntValue(3); - lSeries ++; - } - mEnd = i; - } - lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd); - lRegression = createSimpleRegressionObject(pResults,mStart,mEnd); - addStatisticsValues(lStatistics, lRegression, lStats, lSeries); - - mStatistics = new Statistic[lStats.size()]; - mStatistics = lStats.toArray(mStatistics); - - } - */ - public TimeseriesStatistics(TempFile lImageFile) throws TechnicalException { + + public TimeseriesStatistics(Collection<Result> resultSet) throws StatisticsException { DescriptiveStatistics lStatistics = null; SimpleRegression lRegression = null; ArrayList<Statistic> lStats = new ArrayList<Statistic>(); - int break1, break2; - int mStart = 0; - int mEnd = 0; - int lSeries = 1; - CSVReader reader=null; - if (sDebug) sLogger.debug("TimeseriesStatistics() lImageFile != null"); - try{ - reader = new CSVReader (new FileReader(lImageFile.getFile()), ';'); - String [] sArrayStrLine = reader.readNext(); - Row row = new Row(sArrayStrLine); - - break1 = new Integer (sArrayStrLine[2]).intValue(); - break2 = new Integer (sArrayStrLine[3]).intValue(); - //int i = 1; - lRegression = new SimpleRegression(); - lStatistics = DescriptiveStatistics.newInstance(); - while ((sArrayStrLine = reader.readNext()) != null) { - - if (break1 != new Integer (sArrayStrLine[2]).intValue() - || break2 != new Integer (sArrayStrLine[3]).intValue()) { - //lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd); - //lRegression = createSimpleRegressionObject(pResults,mStart,mEnd); - - addStatisticsValues(lStatistics, lRegression, lStats, lSeries); - - lStatistics.clear(); - lRegression.clear(); - - Row lRow = new Row (sArrayStrLine); - lStatistics.addValue(lRow.getDoubleValue(1)); - Double x = new Double( (lRow.getDateValue(0)).getTime()/1000/3600) ; - lRegression.addData(x,lRow.getDoubleValue(1)); - - break1 = new Integer (sArrayStrLine[2]).intValue(); - break2 = new Integer (sArrayStrLine[3]).intValue(); - lSeries ++; - } - else{ - Row lRow = new Row (sArrayStrLine); - lStatistics.addValue(lRow.getDoubleValue(1)); - Double x = new Double( (lRow.getDateValue(0)).getTime()/1000/3600) ; - lRegression.addData(x,lRow.getDoubleValue(1)); - } - - } - //lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd); - //lRegression = createSimpleRegressionObject(pResults,mStart,mEnd); - addStatisticsValues(lStatistics, lRegression, lStats, lSeries); - lStatistics.clear(); - lRegression.clear(); - mStatistics = new Statistic[lStats.size()]; - mStatistics = lStats.toArray(mStatistics); - } - catch (Exception e){ - sLogger.error(e.getMessage(), e); - } - finally { - try{ - reader.close(); - } - catch (Exception e){ - sLogger.error(e.getMessage(), e); - } - } - + int break1, break2; + int lSeries = 1; + if (sDebug) sLogger.debug("TimeseriesStatistics() lImageFile != null"); + try{ + + Iterator<Result> resultIterator = resultSet.iterator(); + if (resultIterator.hasNext()){ + Result row = resultIterator.next(); + break1 = row.getInteger("GROUP1"); + break2 = row.getInteger("GROUP2"); + lRegression = new SimpleRegression(); + lStatistics = DescriptiveStatistics.newInstance(); + while (resultIterator.hasNext()) { + + if (break1 != row.getInteger("GROUP1") + || break2 != row.getInteger("GROUP2")) { + //lStatistics = createDescriptiveStatisticsObject(pResults,mStart,mEnd); + //lRegression = createSimpleRegressionObject(pResults,mStart,mEnd); + + addStatisticsValues(lStatistics, lRegression, lStats, lSeries); + + lStatistics.clear(); + lRegression.clear(); + + row = resultIterator.next(); + lStatistics.addValue(row.getDouble("YORDINATE")); + Double x = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; + lRegression.addData(x ,row.getDouble("YORDINATE")); + + break1 = row.getInteger("GROUP1"); + break2 = row.getInteger("GROUP2"); + lSeries ++; + } + else{ + row = resultIterator.next(); + lStatistics.addValue(row.getDouble("YORDINATE")); + Double x = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; + lRegression.addData(x,row.getDouble("YORDINATE")); + } + + } + addStatisticsValues(lStatistics, lRegression, lStats, lSeries); + lStatistics.clear(); + lRegression.clear(); + mStatistics = new Statistic[lStats.size()]; + mStatistics = lStats.toArray(mStatistics); + } + } + catch (Exception e){ + sLogger.error(e.getMessage(), e); + } } - /** - * @param lStatistics - * @param lRegression - * @param lStats - * @param lSeries - */ - private void addStatisticsValues(DescriptiveStatistics lStatistics, - SimpleRegression lRegression, ArrayList<Statistic> lStats, - int lSeries) { - lStats.add(new Statistic("gnviewer.statistics.series",(double)lSeries)); + /** + * @param lStatistics + * @param lRegression + * @param lStats + * @param lSeries + */ + private void addStatisticsValues(DescriptiveStatistics lStatistics, + SimpleRegression lRegression, ArrayList<Statistic> lStats, + int lSeries) { + lStats.add(new Statistic("gnviewer.statistics.series",(double)lSeries)); lStats.add(new Statistic("gnviewer.statistics.descriptive.arithmeticMean", lStatistics.getMean())); lStats.add(new Statistic("gnviewer.statistics.descriptive.kurtosis", lStatistics.getKurtosis())); - /* lStats.add(new Statistic("gnviewer.statistics.descriptive.kurtosisClass", lStatistics.getKurtosisClass()));*/ lStats.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax())); lStats.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin())); lStats.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN())); @@ -184,44 +131,12 @@ lStats.add(new Statistic("gnviewer.statistics.descriptive.variance", lStatistics.getVariance())); lStats.add(new Statistic("gnviewer.statistics.descriptive.intercept", lRegression.getIntercept())); lStats.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope())); - } - - - /** - * @param pResults - * @param pStart - * @param pEnd - */ - /* - private SimpleRegression createSimpleRegressionObject ( ResultSet pResults, int pStart, int pEnd)throws TechnicalException{ - SimpleRegression lRegression = new SimpleRegression(); - Row[] lRows = pResults.getResults(); - for (int i = pStart; i < pEnd; i++) { - Row lRow = lRows[i]; - Double x = new Double( ((Calendar)lRow.getValue(0)).getTimeInMillis()/1000/3600) ; - lRegression.addData(x,lRow.getDoubleValue(1)); - - } - return lRegression; - } - */ - /** - * @param pResults - * @param pStart - * @param pEnd - */ - /* - private DescriptiveStatistics createDescriptiveStatisticsObject(ResultSet pResults, int pStart, int pEnd) throws TechnicalException { - DescriptiveStatistics lStatistics = DescriptiveStatistics.newInstance(); - Row[] lRows = pResults.getResults(); - for (int i = pStart; i < pEnd; i++) { - Row lRow = lRows[i]; - lStatistics.addValue(lRow.getDoubleValue(1)); - } - return lStatistics; - } - - */ + } + + /** + * + * @return + */ public Statistic[] getStatistics() { return mStatistics; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/exception/StatisticsException.java Mon Sep 28 07:32:03 2009 +0000 @@ -0,0 +1,47 @@ +/** + * + */ +package de.intevation.gnv.statistics.exception; +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class StatisticsException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -7324280565076343394L; + + /** + * Constructor + */ + public StatisticsException() { + } + + /** + * Constructor + * @param arg0 + */ + public StatisticsException(String arg0) { + super(arg0); + } + + /** + * Constructor + * @param arg0 + */ + public StatisticsException(Throwable arg0) { + super(arg0); + } + + /** + * Constructor + * @param arg0 + * @param arg1 + */ + public StatisticsException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + +}