Mercurial > dive4elements > gnv-client
changeset 98:156db25ad4b4
Add Statisticssupport also to VerticalProfiles
gnv-artifacts/trunk@144 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 28 Sep 2009 10:20:41 +0000 |
parents | fce237b6fdb8 |
children | bb45c5097cb6 |
files | gnv-artifacts/Changelog 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/VerticalProfileStatistics.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java |
diffstat | 6 files changed, 97 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/Changelog Mon Sep 28 09:53:17 2009 +0000 +++ b/gnv-artifacts/Changelog Mon Sep 28 10:20:41 2009 +0000 @@ -1,3 +1,18 @@ +2009-09-28 Tim Englich <tim.englich@intevation.de> + + * src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java (getStatisticsGenerator) Edited: + Extracted the Instantiation of the Statistics-object to an protected Methode + to make it possible that extending Classes could change it. + * src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java (getStatisticsGenerator) Edited: + Overwrite getStatisticsGenerator to instantiate the VerticalProfileStatistics- + * src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java Added: + Class for Calculating Statistics for VerticalProfiles- The Only thing whisch differs to + TimeSeriesStatists is that the XoordinateValue is an double and not an Date-Value + * src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java (calculateXOrdinateValue) Edited: + Added the Methode calculateXOrdinateValue to this Class to switch is Values in extending Classes. + * src/main/java/de/intevation/gnv/statistics/Statistics.java (calculateStatistics) Edited: + Added methodsignature to Interface for usage in different Implementations of Statistics. + 2009-09-28 Tim Englich <tim.englich@intevation.de> * src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java (calculateStatistics) Edited:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java Mon Sep 28 09:53:17 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java Mon Sep 28 10:20:41 2009 +0000 @@ -15,6 +15,11 @@ */ package de.intevation.gnv.statistics; +import java.util.Collection; + +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.statistics.exception.StatisticsException; + /** * The interface <code>Statistics</code> fulfills the following purposes: * <ol> @@ -29,5 +34,11 @@ */ public interface Statistics { + /** + * @param resultSet + * @return + * @throws StatisticsException + */ + public Collection<Statistic> calculateStatistics(Collection<Result> resultSet) throws StatisticsException; }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Mon Sep 28 09:53:17 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Mon Sep 28 10:20:41 2009 +0000 @@ -15,6 +15,7 @@ */ package de.intevation.gnv.statistics; +import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -24,6 +25,7 @@ import org.apache.log4j.Logger; import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.geobackend.sde.datasources.ResultSet; import de.intevation.gnv.statistics.exception.StatisticsException; @@ -55,43 +57,46 @@ 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>(); - int break1, break2; + String break1, break2; int lSeries = 1; try{ Iterator<Result> resultIterator = resultSet.iterator(); if (resultIterator.hasNext()){ Result row = resultIterator.next(); - break1 = row.getInteger("GROUP1"); - break2 = row.getInteger("GROUP2"); + break1 = row.getString("GROUP1"); + break2 = row.getString("GROUP2"); lRegression = new SimpleRegression(); lStatistics = DescriptiveStatistics.newInstance(); while (resultIterator.hasNext()) { - if (break1 != row.getInteger("GROUP1") - || break2 != row.getInteger("GROUP2")) { + 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 = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; + Double x = this.calculateXOrdinateValue(row); lRegression.addData(x ,row.getDouble("YORDINATE")); - break1 = row.getInteger("GROUP1"); - break2 = row.getInteger("GROUP2"); + break1 = row.getString("GROUP1"); + break2 = row.getString("GROUP2"); row = resultIterator.next(); lSeries ++; } else{ lStatistics.addValue(row.getDouble("YORDINATE")); - Double x = new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; + Double x = this.calculateXOrdinateValue(row); lRegression.addData(x,row.getDouble("YORDINATE")); row = resultIterator.next(); } @@ -109,6 +114,12 @@ return statistics; } + + protected double calculateXOrdinateValue(Result row) throws SQLException{ + return new Double( (row.getDate("XORDINATE")).getTime()/1000/3600) ; + } + + /** * @param lStatistics * @param lRegression
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java Mon Sep 28 10:20:41 2009 +0000 @@ -0,0 +1,29 @@ +/** + * + */ +package de.intevation.gnv.statistics; + +import java.sql.SQLException; + +import de.intevation.gnv.geobackend.base.Result; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class VerticalProfileStatistics extends TimeseriesStatistics { + + /** + * Constructor + */ + public VerticalProfileStatistics() { + super(); + } + + @Override + protected double calculateXOrdinateValue(Result row) throws SQLException { + return row.getDouble("XORDINATE"); + } + + +}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Mon Sep 28 09:53:17 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Mon Sep 28 10:20:41 2009 +0000 @@ -11,6 +11,9 @@ import de.intevation.gnv.chart.ChartStyle; import de.intevation.gnv.chart.VerticalProfileChartFactory; import de.intevation.gnv.chart.exception.TechnicalChartException; +import de.intevation.gnv.statistics.Statistics; +import de.intevation.gnv.statistics.TimeseriesStatistics; +import de.intevation.gnv.statistics.VerticalProfileStatistics; import de.intevation.gnv.transition.describedata.KeyValueDescibeData; import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition; @@ -54,6 +57,14 @@ parameters, measurements, outputStream, this.chartResult); } + + /** + * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#getStatisticsGenerator() + */ + @Override + protected Statistics getStatisticsGenerator() { + return new VerticalProfileStatistics(); + } }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Mon Sep 28 09:53:17 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Mon Sep 28 10:20:41 2009 +0000 @@ -32,6 +32,7 @@ import de.intevation.gnv.chart.exception.TechnicalChartException; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.statistics.Statistic; +import de.intevation.gnv.statistics.Statistics; import de.intevation.gnv.statistics.TimeseriesStatistics; import de.intevation.gnv.statistics.exception.StatisticsException; import de.intevation.gnv.transition.InputData; @@ -129,8 +130,8 @@ } }else if (outputMode.equalsIgnoreCase("statistics")){ log.debug("Statistics will be generated."); - TimeseriesStatistics tss = new TimeseriesStatistics(); - Collection<Statistic> statistics = tss.calculateStatistics(this.chartResult); + Statistics s = getStatisticsGenerator(); + Collection<Statistic> statistics = s.calculateStatistics(this.chartResult); Document doc = this.writeStatistics2XML(statistics); this.writeDocument2OutputStream(doc, outputStream); } @@ -145,6 +146,14 @@ throw new TransitionException(e); } } + + /** + * @return + */ + protected Statistics getStatisticsGenerator() { + Statistics s = new TimeseriesStatistics(); + return s; + } protected void writeDocument2OutputStream(Document document, OutputStream os){