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@94: import de.intevation.gnv.statistics.exception.StatisticsException;
tim@93:
tim@93: /**
tim@93: * The class TimeseriesStatistics
fulfills the following purposes:
tim@93: *
tim@93: *
tim@93: *
tim@171: *
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@171: public TimeseriesStatistics() {
tim@95: super();
tim@95: }
tim@171:
tim@98: /**
tim@98: * @see de.intevation.gnv.statistics.Statistics#calculateStatistics(java.util.Collection)
tim@98: */
tim@171: public Collection calculateStatistics(
tim@171: Collection resultSet)
tim@171: 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@171: try {
tim@171:
tim@94: Iterator resultIterator = resultSet.iterator();
tim@171: if (resultIterator.hasNext()) {
tim@94: Result row = resultIterator.next();
tim@98: break1 = row.getString("GROUP1");
tim@98: break2 = row.getString("GROUP2");
tim@171: lRegression = new SimpleRegression();
tim@171: lStatistics = DescriptiveStatistics.newInstance();
tim@171: while (resultIterator.hasNext()) {
tim@171:
tim@171: if (!break1.equals(row.getString("GROUP1"))
tim@98: || !break2.equals(row.getString("GROUP2"))) {
tim@171: addStatisticsValues(lStatistics, lRegression, lSeries);
tim@171:
tim@171: lStatistics.clear();
tim@171: lRegression.clear();
tim@171:
tim@171: lStatistics.addValue(row.getDouble("YORDINATE"));
tim@171: Double x = this.calculateXOrdinateValue(row);
tim@171: lRegression.addData(x, row.getDouble("YORDINATE"));
tim@171:
tim@171: break1 = row.getString("GROUP1");
tim@171: break2 = row.getString("GROUP2");
tim@171: row = resultIterator.next();
tim@171: lSeries++;
tim@171: } else {
tim@171:
tim@171: lStatistics.addValue(row.getDouble("YORDINATE"));
tim@171: Double x = this.calculateXOrdinateValue(row);
tim@171: lRegression.addData(x, row.getDouble("YORDINATE"));
tim@171: row = resultIterator.next();
tim@171: }
tim@171:
tim@94: }
tim@171: addStatisticsValues(lStatistics, lRegression, lSeries);
tim@171: lStatistics.clear();
tim@171: lRegression.clear();
tim@94: }
tim@171: } catch (Exception e) {
tim@95: log.error(e.getMessage(), e);
tim@94: }
tim@171:
tim@95: return statistics;
tim@93: }
tim@171:
tim@171: protected double calculateXOrdinateValue(Result row) throws SQLException {
tim@171: return new Double((row.getDate("XORDINATE")).getTime() / 1000 / 3600);
tim@98: }
tim@171:
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@171: SimpleRegression lRegression, int lSeries) {
tim@171: statistics.add(new Statistic("gnviewer.statistics.series",
tim@171: lSeries));
tim@171: statistics.add(new Statistic(
tim@171: "gnviewer.statistics.descriptive.arithmeticMean", lStatistics
tim@171: .getMean()));
tim@171: statistics.add(new Statistic(
tim@171: "gnviewer.statistics.descriptive.kurtosis", lStatistics
tim@171: .getKurtosis()));
tim@171: statistics.add(new Statistic("gnviewer.statistics.descriptive.max",
tim@171: lStatistics.getMax()));
tim@171: statistics.add(new Statistic("gnviewer.statistics.descriptive.min",
tim@171: lStatistics.getMin()));
tim@171: statistics.add(new Statistic("gnviewer.statistics.descriptive.n",
tim@171: lStatistics.getN()));
tim@171: statistics.add(new Statistic(
tim@171: "gnviewer.statistics.descriptive.percentile.90", lStatistics
tim@171: .getPercentile(90)));
tim@171: statistics.add(new Statistic(
tim@171: "gnviewer.statistics.descriptive.percentile.75", lStatistics
tim@171: .getPercentile(75)));
tim@171: statistics.add(new Statistic(
tim@171: "gnviewer.statistics.descriptive.percentile.50", lStatistics
tim@171: .getPercentile(50)));
tim@171: statistics.add(new Statistic(
tim@171: "gnviewer.statistics.descriptive.percentile.10", lStatistics
tim@171: .getPercentile(10)));
tim@171: statistics.add(new Statistic(
tim@171: "gnviewer.statistics.descriptive.deviation", lStatistics
tim@171: .getStandardDeviation()));
tim@171: statistics.add(new Statistic(
tim@171: "gnviewer.statistics.descriptive.variance", lStatistics
tim@171: .getVariance()));
tim@171: statistics.add(new Statistic(
tim@171: "gnviewer.statistics.descriptive.intercept", lRegression
tim@171: .getIntercept()));
tim@171: statistics.add(new Statistic("gnviewer.statistics.descriptive.slope",
tim@171: lRegression.getSlope()));
tim@171: }
tim@93: }