Mercurial > dive4elements > gnv-client
changeset 93:c476fbbaa4ca
Imported Statistics-Classes from old Project. Revision: 3101 Does not compile
gnv-artifacts/trunk@138 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 28 Sep 2009 07:27:06 +0000 |
parents | 090612335a48 |
children | 6a825a184883 |
files | gnv-artifacts/Changelog gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistic.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java |
diffstat | 4 files changed, 329 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/Changelog Fri Sep 25 14:37:35 2009 +0000 +++ b/gnv-artifacts/Changelog Mon Sep 28 07:27:06 2009 +0000 @@ -1,3 +1,10 @@ +2009-09-28 Tim Englich <tim.englich@intevation.de> + + * src/main/java/de/intevation/gnv/statistics/Statistic.java Added , + src/main/java/de/intevation/gnv/statistics/Statistics.java Added , + src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Added: + Imported Statistics-Classes from old Project. Revision: 3101 Does not compile + 2009-09-25 Tim Englich <tim.englich@intevation.de> * src/test/ressources/conf.xml Edited:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistic.java Mon Sep 28 07:27:06 2009 +0000 @@ -0,0 +1,61 @@ +/** + * Title: Statistic, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/output/statistics/Statistic.java,v 1.2 2007/12/21 12:31:15 blume Exp $ + * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/output/statistics/Statistic.java,v $ + * created by: Stefan Blume (blume) + * erstellt am: 14.12.2007 + * Copyright: con terra GmbH, 2005 + * + * modified by: $Author: blume $ + * modified on: $Date: 2007/12/21 12:31:15 $ + * Version: $Revision: 1.2 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +package de.intevation.gnv.statistics; + +import org.apache.log4j.Logger; + +/** + * The class <code>Statistic</code> fulfills the following purposes: + * <ol> + * <li></li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 14.12.2007 09:38:18 + */ +public class Statistic { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(Statistic.class); + private static boolean sDebug = sLogger.isDebugEnabled(); + + private double mValue; + private String mKey; + + public Statistic(String pKey, double pValue) { + mKey = pKey; + mValue = pValue; + } + + public double getValue() { + return mValue; + } + + public String getKey() { + return mKey; + } + + public String getStringValue() { + java.text.DecimalFormat df = new java.text.DecimalFormat("#.##"); + return df.format(mValue); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java Mon Sep 28 07:27:06 2009 +0000 @@ -0,0 +1,33 @@ +/** + * Title: Statistics, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/output/statistics/Statistics.java,v 1.2 2008/01/30 12:38:34 blume Exp $ + * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/output/statistics/Statistics.java,v $ + * created by: Stefan Blume (blume) + * erstellt am: 14.12.2007 + * Copyright: con terra GmbH, 2005 + * + * modified by: $Author: blume $ + * modified on: $Date: 2008/01/30 12:38:34 $ + * Version: $Revision: 1.2 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +package de.intevation.gnv.statistics; + +/** + * The interface <code>Statistics</code> fulfills the following purposes: + * <ol> + * <li>Providng a marker interface for statistics.</li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 14.12.2007 09:34:32 + */ +public interface Statistics { + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Mon Sep 28 07:27:06 2009 +0000 @@ -0,0 +1,228 @@ +/** + * 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 $ + * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/output/statistics/TimeseriesStatistics.java,v $ + * created by: Stefan Blume (blume) + * erstellt am: 06.12.2007 + * Copyright: con terra GmbH, 2005 + * + * modified by: $Author: drewnak $ + * modified on: $Date: 2008/08/18 14:50:33 $ + * Version: $Revision: 1.3 $ + * TAG: $Name: $ + * locked from: $Locker: $ + * CVS State: $State: Exp $ + * Project: $ProjectName$ + */ +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 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.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: + * <ol> + * <li></li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 06.12.2007 18:02:27 + */ +public class TimeseriesStatistics implements Statistics { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(TimeseriesStatistics.class); + private static boolean sDebug = sLogger.isDebugEnabled(); + + 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 { + 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); + } + } + + } + /** + * @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())); + lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.90", lStatistics.getPercentile(90))); + lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.75", lStatistics.getPercentile(75))); + lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.50", lStatistics.getPercentile(50))); + lStats.add(new Statistic("gnviewer.statistics.descriptive.percentile.10", lStatistics.getPercentile(10))); + lStats.add(new Statistic("gnviewer.statistics.descriptive.deviation", lStatistics.getStandardDeviation())); + 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; + } + + */ + public Statistic[] getStatistics() { + return mStatistics; + } +}