Mercurial > dive4elements > gnv-client
changeset 454:04cfb4e3da4f
Refactored statistics classes a bit. Added class for vertical cross sections.
gnv-artifacts/trunk@503 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 04 Jan 2010 15:20:14 +0000 |
parents | 537e663d6c0c |
children | 363236fc462d |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/AbstractStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalCrossSectionStatistics.java |
diffstat | 7 files changed, 212 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Mon Jan 04 13:42:49 2010 +0000 +++ b/gnv-artifacts/ChangeLog Mon Jan 04 15:20:14 2010 +0000 @@ -1,3 +1,29 @@ +2010-01-04 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/gnv/statistics/Statistics.java: + Changed interface to allow general object results as + input for statistic calculation. This is needed because + the vertical cross section produces no SQL like resultsets. + + * src/main/java/de/intevation/gnv/statistics/AbstractStatistics.java: + New. Added common base class for different kind of statistics. + TODO: Move more common code into this class. + + * src/main/java/de/intevation/gnv/statistics/VerticalCrossSectionStatistics.java: + New. Statistics for vertical cross sections. Does nothing + by now. + + * src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java: + Creates a VerticalCrossSectionStatistics object as statistics + generator now. + + * src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java: + Inherits from AbstractStatistics now. Some code moved to new + base class. + + * src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java: + Cleaned up the usage of statistics. + 2010-01-04 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/gnv/math/Interpolation3D.java:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java Mon Jan 04 13:42:49 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java Mon Jan 04 15:20:14 2010 +0000 @@ -65,7 +65,7 @@ import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; import de.intevation.gnv.statistics.Statistics; -import de.intevation.gnv.statistics.VerticalProfileStatistics; +import de.intevation.gnv.statistics.VerticalCrossSectionStatistics; import de.intevation.gnv.utils.DistanceCalculator; import de.intevation.gnv.utils.WKTUtils; @@ -510,7 +510,7 @@ */ @Override protected Statistics getStatisticsGenerator() { - return new VerticalProfileStatistics(); + return new VerticalCrossSectionStatistics(); } /**
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Mon Jan 04 13:42:49 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Mon Jan 04 15:20:14 2010 +0000 @@ -362,23 +362,23 @@ } else if (outputMode.equalsIgnoreCase("statistics")) { log.debug("Statistics will be generated."); - Statistics s = getStatisticsGenerator(); - Collection<StatisticSet> statistics; - Object result = getChartResult(uuid, callContext); + Statistics s = getStatisticsGenerator(); + Object result = getChartResult(uuid, callContext); - if (result instanceof Collection) { - Collection<Result> chartResult = - (Collection<Result>) result; + if (result != null && s != null) { Collection<KeyValueDescibeData> parameters = - this.getParameters(uuid); + getParameters(uuid); + Collection<KeyValueDescibeData> measurements = - this.getMeasurements(uuid); + getMeasurements(uuid); + Collection<KeyValueDescibeData> dates = - this.getDates(uuid); + getDates(uuid); + statistics = s.calculateStatistics( - chartResult, + result, parameters, measurements, dates); @@ -387,8 +387,10 @@ statistics = new ArrayList<StatisticSet>(); } - Document doc = this.writeStatistics2XML(statistics); - this.writeDocument2OutputStream(doc, outputStream); + Document doc = writeStatistics2XML(statistics); + + writeDocument2OutputStream(doc, outputStream); + } else if (outputMode.equalsIgnoreCase("odv")) { Collection<Result> odvResult = this.getODVResult(uuid);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/AbstractStatistics.java Mon Jan 04 15:20:14 2010 +0000 @@ -0,0 +1,100 @@ +package de.intevation.gnv.statistics; + +import java.util.Collection; +import java.util.ArrayList; + +import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; + +import org.apache.commons.math.stat.regression.SimpleRegression; + +import org.apache.log4j.Logger; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ +public abstract class AbstractStatistics +implements Statistics +{ + private static Logger log = Logger.getLogger( + AbstractStatistics.class); + + public AbstractStatistics() { + } + + protected StatisticSet generateStatisticsValues( + DescriptiveStatistics lStatistics, + SimpleRegression lRegression, + String statisticName + ) { + StatisticSet statisticSet = new StatisticSet(statisticName); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.arithmeticMean", + lStatistics.getMean())); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.kurtosis", + lStatistics.getKurtosis())); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.max", + lStatistics.getMax())); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.min", + lStatistics.getMin())); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.n", + lStatistics.getN())); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.percentile.90", + lStatistics.getPercentile(90))); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.percentile.75", + lStatistics.getPercentile(75))); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.percentile.50", + lStatistics.getPercentile(50))); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.percentile.10", + lStatistics.getPercentile(10))); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.deviation", + lStatistics.getStandardDeviation())); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.variance", + lStatistics.getVariance())); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.intercept", + lRegression.getIntercept())); + + statisticSet.addStatistic( + new Statistic( + "gnviewer.statistics.descriptive.slope", + lRegression.getSlope())); + + return statisticSet; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java Mon Jan 04 13:42:49 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java Mon Jan 04 15:20:14 2010 +0000 @@ -17,8 +17,8 @@ import java.util.Collection; -import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.state.describedata.KeyValueDescibeData; + import de.intevation.gnv.statistics.exception.StatisticsException; /** @@ -45,11 +45,10 @@ * @throws StatisticsException */ public Collection<StatisticSet> calculateStatistics( - Collection<Result> resultSet, - Collection<KeyValueDescibeData> parameters, - Collection<KeyValueDescibeData> measurements, - Collection<KeyValueDescibeData> dates - ) - throws StatisticsException; - + Object resultSet, + Collection<KeyValueDescibeData> parameters, + Collection<KeyValueDescibeData> measurements, + Collection<KeyValueDescibeData> dates + ) + throws StatisticsException; }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Mon Jan 04 13:42:49 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Mon Jan 04 15:20:14 2010 +0000 @@ -42,7 +42,9 @@ * @see * @since 06.12.2007 18:02:27 */ -public class TimeseriesStatistics implements Statistics { +public class TimeseriesStatistics +extends AbstractStatistics +{ /** * Default Logging instance @@ -53,21 +55,27 @@ * Constructor */ public TimeseriesStatistics() { - super(); } /** * @see de.intevation.gnv.statistics.Statistics#calculateStatistics(java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection) */ public Collection<StatisticSet> calculateStatistics( - Collection<Result> resultSet, + Object result, Collection<KeyValueDescibeData> parameters, Collection<KeyValueDescibeData> measurements, Collection<KeyValueDescibeData> dates ) throws StatisticsException { + if (!(result instanceof Collection)) { + return new ArrayList<StatisticSet>(); + } + + Collection<Result> resultSet = (Collection<Result>)result; + clearStatistics(); + DescriptiveStatistics lStatistics = null; SimpleRegression lRegression = null; Collection<StatisticSet> statisticSets = new ArrayList<StatisticSet>(); @@ -224,52 +232,4 @@ return new Double((row.getDate("XORDINATE")).getTime() / 1000 / 3600); } - /** - * @param lStatistics - * @param lRegression - * @param lStats - * @param lSeries - */ - private StatisticSet generateStatisticsValues(DescriptiveStatistics lStatistics, - SimpleRegression lRegression, String statisticName) { - - StatisticSet statisticSet = new StatisticSet(statisticName); - - statisticSet.addStatistic(new Statistic( - "gnviewer.statistics.descriptive.arithmeticMean", lStatistics - .getMean())); - statisticSet.addStatistic(new Statistic( - "gnviewer.statistics.descriptive.kurtosis", lStatistics - .getKurtosis())); - statisticSet.addStatistic(new Statistic("gnviewer.statistics.descriptive.max", - lStatistics.getMax())); - statisticSet.addStatistic(new Statistic("gnviewer.statistics.descriptive.min", - lStatistics.getMin())); - statisticSet.addStatistic(new Statistic("gnviewer.statistics.descriptive.n", - lStatistics.getN())); - statisticSet.addStatistic(new Statistic( - "gnviewer.statistics.descriptive.percentile.90", lStatistics - .getPercentile(90))); - statisticSet.addStatistic(new Statistic( - "gnviewer.statistics.descriptive.percentile.75", lStatistics - .getPercentile(75))); - statisticSet.addStatistic(new Statistic( - "gnviewer.statistics.descriptive.percentile.50", lStatistics - .getPercentile(50))); - statisticSet.addStatistic(new Statistic( - "gnviewer.statistics.descriptive.percentile.10", lStatistics - .getPercentile(10))); - statisticSet.addStatistic(new Statistic( - "gnviewer.statistics.descriptive.deviation", lStatistics - .getStandardDeviation())); - statisticSet.addStatistic(new Statistic( - "gnviewer.statistics.descriptive.variance", lStatistics - .getVariance())); - statisticSet.addStatistic(new Statistic( - "gnviewer.statistics.descriptive.intercept", lRegression - .getIntercept())); - statisticSet.addStatistic(new Statistic("gnviewer.statistics.descriptive.slope", - lRegression.getSlope())); - return statisticSet; - } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalCrossSectionStatistics.java Mon Jan 04 15:20:14 2010 +0000 @@ -0,0 +1,52 @@ +package de.intevation.gnv.statistics; + +import java.util.Collection; +import java.util.ArrayList; + +import org.apache.log4j.Logger; + +import de.intevation.gnv.state.describedata.KeyValueDescibeData; + +import de.intevation.gnv.statistics.exception.StatisticsException; + +import de.intevation.gnv.math.AttributedXYColumns; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ +public class VerticalCrossSectionStatistics +extends AbstractStatistics +{ + private static Logger log = Logger.getLogger( + VerticalCrossSectionStatistics.class); + + public VerticalCrossSectionStatistics() { + } + + public Collection<StatisticSet> calculateStatistics( + Object result, + Collection<KeyValueDescibeData> parameters, + Collection<KeyValueDescibeData> measurements, + Collection<KeyValueDescibeData> dates + ) + throws StatisticsException { + + boolean debug = log.isDebugEnabled(); + + if (debug) { + log.debug("calculateStatistics --------------"); + } + + ArrayList<StatisticSet> statisticSet = + new ArrayList<StatisticSet>(); + + if (!(result instanceof AttributedXYColumns)) { + log.error("wrong type of result"); + return statisticSet; + } + AttributedXYColumns columns = (AttributedXYColumns)result; + + return statisticSet; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :