Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java @ 205:6e7952fd1744
Added the support to Display the Time and the position of an Measurement in an VerticalProfile of Type Instantaneous Point
gnv-artifacts/trunk@261 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Thu, 22 Oct 2009 14:02:30 +0000 |
parents | 7fb9441dd8af |
children | 07650fc6014c |
line wrap: on
line source
/** * 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.sql.SQLException; import java.util.ArrayList; 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 de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.statistics.exception.StatisticsException; /** * The class <code>TimeseriesStatistics</code> fulfills the following purposes: * <ol> * <li></li> * </ol> * * @author blume * @author Tim Englich <tim.englich@intevation.de> * @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 log = Logger.getLogger(TimeseriesStatistics.class); private static boolean sDebug = log.isDebugEnabled(); private Collection<Statistic> statistics = null; public TimeseriesStatistics() { super(); } /** * @see de.intevation.gnv.statistics.Statistics#calculateStatistics(java.util.Collection) */ public Collection<Statistic> calculateStatistics( Collection<Result> resultSet) throws StatisticsException { DescriptiveStatistics lStatistics = null; SimpleRegression lRegression = null; statistics = new ArrayList<Statistic>(); String break1, break2; int lSeries = 1; try { Iterator<Result> resultIterator = resultSet.iterator(); if (resultIterator.hasNext()) { Result row = resultIterator.next(); break1 = row.getString("GROUP1"); break2 = row.getString("GROUP2"); lRegression = new SimpleRegression(); lStatistics = DescriptiveStatistics.newInstance(); while (resultIterator.hasNext()) { if (!break1.equals(row.getString("GROUP1")) || !break2.equals(row.getString("GROUP2"))) { addStatisticsValues(lStatistics, lRegression, lSeries); lStatistics.clear(); lRegression.clear(); lStatistics.addValue(row.getDouble("YORDINATE")); Double x = this.calculateXOrdinateValue(row); lRegression.addData(x, row.getDouble("YORDINATE")); break1 = row.getString("GROUP1"); break2 = row.getString("GROUP2"); row = resultIterator.next(); lSeries++; } else { lStatistics.addValue(row.getDouble("YORDINATE")); Double x = this.calculateXOrdinateValue(row); lRegression.addData(x, row.getDouble("YORDINATE")); row = resultIterator.next(); } } addStatisticsValues(lStatistics, lRegression, lSeries); lStatistics.clear(); lRegression.clear(); } } catch (Exception e) { log.error(e.getMessage(), e); } return statistics; } protected double calculateXOrdinateValue(Result row) throws SQLException { return new Double((row.getDate("XORDINATE")).getTime() / 1000 / 3600); } /** * @param lStatistics * @param lRegression * @param lStats * @param lSeries */ private void addStatisticsValues(DescriptiveStatistics lStatistics, SimpleRegression lRegression, int lSeries) { statistics.add(new Statistic("gnviewer.statistics.series", lSeries)); statistics.add(new Statistic( "gnviewer.statistics.descriptive.arithmeticMean", lStatistics .getMean())); statistics.add(new Statistic( "gnviewer.statistics.descriptive.kurtosis", lStatistics .getKurtosis())); statistics.add(new Statistic("gnviewer.statistics.descriptive.max", lStatistics.getMax())); statistics.add(new Statistic("gnviewer.statistics.descriptive.min", lStatistics.getMin())); statistics.add(new Statistic("gnviewer.statistics.descriptive.n", lStatistics.getN())); statistics.add(new Statistic( "gnviewer.statistics.descriptive.percentile.90", lStatistics .getPercentile(90))); statistics.add(new Statistic( "gnviewer.statistics.descriptive.percentile.75", lStatistics .getPercentile(75))); statistics.add(new Statistic( "gnviewer.statistics.descriptive.percentile.50", lStatistics .getPercentile(50))); statistics.add(new Statistic( "gnviewer.statistics.descriptive.percentile.10", lStatistics .getPercentile(10))); statistics.add(new Statistic( "gnviewer.statistics.descriptive.deviation", lStatistics .getStandardDeviation())); statistics.add(new Statistic( "gnviewer.statistics.descriptive.variance", lStatistics .getVariance())); statistics.add(new Statistic( "gnviewer.statistics.descriptive.intercept", lRegression .getIntercept())); statistics.add(new Statistic("gnviewer.statistics.descriptive.slope", lRegression.getSlope())); } }