# HG changeset patch # User Tim Englich # Date 1254122826 0 # Node ID c476fbbaa4ca581d930123c175f5b6f4fb641d6a # Parent 090612335a482eee5615d5f7924293f477185465 Imported Statistics-Classes from old Project. Revision: 3101 Does not compile gnv-artifacts/trunk@138 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 090612335a48 -r c476fbbaa4ca gnv-artifacts/Changelog --- 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 + + * 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 * src/test/ressources/conf.xml Edited: diff -r 090612335a48 -r c476fbbaa4ca gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistic.java --- /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 Statistic fulfills the following purposes: + *
    + *
  1. + *
+ * + * @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); + } + +} diff -r 090612335a48 -r c476fbbaa4ca gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java --- /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 Statistics fulfills the following purposes: + *
    + *
  1. Providng a marker interface for statistics.
  2. + *
+ * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 14.12.2007 09:34:32 + */ +public interface Statistics { + + +} diff -r 090612335a48 -r c476fbbaa4ca gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java --- /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 TimeseriesStatistics fulfills the following purposes: + *
    + *
  1. + *
+ * + * @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 lStats = new ArrayList(); + 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 lStats = new ArrayList(); + 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 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; + } +}