tim@93: /**
tim@93: * 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 $
tim@93: * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/output/statistics/TimeseriesStatistics.java,v $
tim@93: * created by: Stefan Blume (blume)
tim@93: * erstellt am: 06.12.2007
tim@93: * Copyright: con terra GmbH, 2005
tim@93: *
tim@93: * modified by: $Author: drewnak $
tim@93: * modified on: $Date: 2008/08/18 14:50:33 $
tim@93: * Version: $Revision: 1.3 $
tim@93: * TAG: $Name: $
tim@93: * locked from: $Locker: $
tim@93: * CVS State: $State: Exp $
tim@93: * Project: $ProjectName$
tim@93: */
tim@93: package de.intevation.gnv.statistics;
tim@93:
tim@98: import java.sql.SQLException;
tim@93: import java.util.ArrayList;
tim@94: import java.util.Collection;
tim@94: import java.util.Iterator;
tim@93:
tim@93: import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
tim@93: import org.apache.commons.math.stat.regression.SimpleRegression;
tim@93: import org.apache.log4j.Logger;
tim@93:
tim@94: import de.intevation.gnv.geobackend.base.Result;
tim@98: import de.intevation.gnv.geobackend.sde.datasources.ResultSet;
tim@94: import de.intevation.gnv.statistics.exception.StatisticsException;
tim@93:
tim@94:
tim@93:
tim@93: /**
tim@93: * The class TimeseriesStatistics
fulfills the following purposes:
tim@93: *
tim@93: *
tim@93: *
tim@93: *
tim@93: * @author blume
tim@94: * @author Tim Englich
tim@93: * @version 1.0
tim@93: * @serial 1.0
tim@93: * @see
tim@93: * @since 06.12.2007 18:02:27
tim@93: */
tim@93: public class TimeseriesStatistics implements Statistics {
tim@93:
tim@93: /**
tim@93: * Default Logging instance
tim@93: */
tim@95: private static Logger log = Logger.getLogger(TimeseriesStatistics.class);
tim@95: private static boolean sDebug = log.isDebugEnabled();
tim@93:
tim@95: private Collection statistics = null;
tim@93:
tim@95: public TimeseriesStatistics(){
tim@95: super();
tim@95: }
tim@95:
tim@98: /**
tim@98: * @see de.intevation.gnv.statistics.Statistics#calculateStatistics(java.util.Collection)
tim@98: */
tim@95: public Collection calculateStatistics(Collection resultSet) throws StatisticsException {
tim@93: DescriptiveStatistics lStatistics = null;
tim@93: SimpleRegression lRegression = null;
tim@95: statistics = new ArrayList();
tim@98: String break1, break2;
tim@94: int lSeries = 1;
tim@94: try{
tim@94:
tim@94: Iterator resultIterator = resultSet.iterator();
tim@94: if (resultIterator.hasNext()){
tim@94: Result row = resultIterator.next();
tim@98: break1 = row.getString("GROUP1");
tim@98: break2 = row.getString("GROUP2");
tim@94: lRegression = new SimpleRegression();
tim@94: lStatistics = DescriptiveStatistics.newInstance();
tim@94: while (resultIterator.hasNext()) {
tim@94:
tim@98: if (!break1.equals(row.getString("GROUP1"))
tim@98: || !break2.equals(row.getString("GROUP2"))) {
tim@95: addStatisticsValues(lStatistics, lRegression, lSeries);
tim@94:
tim@94: lStatistics.clear();
tim@94: lRegression.clear();
tim@94:
tim@94: lStatistics.addValue(row.getDouble("YORDINATE"));
tim@98: Double x = this.calculateXOrdinateValue(row);
tim@94: lRegression.addData(x ,row.getDouble("YORDINATE"));
tim@94:
tim@98: break1 = row.getString("GROUP1");
tim@98: break2 = row.getString("GROUP2");
tim@97: row = resultIterator.next();
tim@94: lSeries ++;
tim@94: }
tim@94: else{
tim@97:
tim@94: lStatistics.addValue(row.getDouble("YORDINATE"));
tim@98: Double x = this.calculateXOrdinateValue(row);
tim@94: lRegression.addData(x,row.getDouble("YORDINATE"));
tim@97: row = resultIterator.next();
tim@94: }
tim@94:
tim@94: }
tim@95: addStatisticsValues(lStatistics, lRegression,lSeries);
tim@94: lStatistics.clear();
tim@94: lRegression.clear();
tim@94: }
tim@94: }
tim@94: catch (Exception e){
tim@95: log.error(e.getMessage(), e);
tim@94: }
tim@95:
tim@95: return statistics;
tim@93: }
tim@95:
tim@98:
tim@98: protected double calculateXOrdinateValue(Result row) throws SQLException{
tim@98: return new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ;
tim@98: }
tim@98:
tim@98:
tim@94: /**
tim@94: * @param lStatistics
tim@94: * @param lRegression
tim@94: * @param lStats
tim@94: * @param lSeries
tim@94: */
tim@94: private void addStatisticsValues(DescriptiveStatistics lStatistics,
tim@95: SimpleRegression lRegression, int lSeries) {
tim@95: statistics.add(new Statistic("gnviewer.statistics.series",(double)lSeries));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.arithmeticMean", lStatistics.getMean()));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.kurtosis", lStatistics.getKurtosis()));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax()));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin()));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN()));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.90", lStatistics.getPercentile(90)));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.75", lStatistics.getPercentile(75)));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.50", lStatistics.getPercentile(50)));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.percentile.10", lStatistics.getPercentile(10)));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.deviation", lStatistics.getStandardDeviation()));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.variance", lStatistics.getVariance()));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.intercept", lRegression.getIntercept()));
tim@95: statistics.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope()));
tim@94: }
tim@93: }