Mercurial > dive4elements > gnv-client
changeset 1081:846b2b70b2e0
Implemented histogram creation for vectorial timeseries.
gnv-artifacts/trunk@1183 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 09 Jun 2010 09:51:05 +0000 |
parents | 01e26528bb39 |
children | 3c0fd3c2fd6b |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/VectorDataProcessor.java |
diffstat | 4 files changed, 171 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Wed Jun 09 09:37:57 2010 +0000 +++ b/gnv-artifacts/ChangeLog Wed Jun 09 09:51:05 2010 +0000 @@ -1,3 +1,21 @@ +2010-06-09 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java: + Override method getHistograms(.) of TimeSeriesOutputState to create + histograms that contain the components of vectorial parameters. This + method doesn't have many tasks but calls getHistograms(.) of + VectorDataProcessor. + + * src/main/java/de/intevation/gnv/utils/VectorDataProcessor.java: The real + implementation of getHistograms(.) for creating histograms that contain + the components of vectorial parameters. This place was chosen to make it + possible to use this method in all vector output states (because multiple + inheritance is not available in Java). + + * src/main/java/de/intevation/gnv/histogram/HistogramHelper.java: + A new method to prepare the data for histograms that contain the + components of vectorial parameters. + 2010-06-09 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java Wed Jun 09 09:37:57 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java Wed Jun 09 09:51:05 2010 +0000 @@ -1,5 +1,11 @@ package de.intevation.gnv.histogram; +import de.intevation.artifacts.CallContext; + +import de.intevation.gnv.artifacts.ressource.RessourceFactory; + +import de.intevation.gnv.chart.ChartLabels; + import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.geobackend.base.ResultDescriptor; @@ -9,6 +15,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Locale; import org.apache.log4j.Logger; @@ -236,5 +243,92 @@ "", fac.getRessource(locale, "histogram.axis.range.title", "")); } + + + public static Object[][] prepareVectorialHistogramData(Collection input) { + List names = new ArrayList<String>(); + List data = new ArrayList<Double[]>(); + + if (logger.isDebugEnabled()) { + logger.debug("######### prepare vectorial histogram data #######"); + logger.debug("Input data size: " + input.size()); + } + + if (input == null) { + return new Object[0][0]; + } + + int sIdx = -1; + int yIdx = -1; + + String series = null; + + try { + Iterator iter = input.iterator(); + + if (iter.hasNext()) { + Result row = (Result) iter.next(); + Result previousRow = row; + + if (sIdx == -1 || yIdx == -1) { + ResultDescriptor rd = row.getResultDescriptor(); + sIdx = rd.getColumnIndex("SERIES"); + yIdx = rd.getColumnIndex("YORDINATE"); + + if (sIdx == -1 || yIdx == -1) { + return new Object[0][0]; + } + } + + List values = new ArrayList<Double>(); + while (iter.hasNext()) { + row = (Result) iter.next(); + + // found new series + if (series != null && !series.equals(row.getString(sIdx))) { + + // add values and parameter name + data.add((Double[]) + values.toArray(new Double[values.size()])); + names.add(series); + + if (logger.isDebugEnabled()) { + logger.debug(" --- series name: " + series); + logger.debug(" --- series items: " + values.size()); + } + + values.clear(); + } + + Double value = row.getDouble(yIdx); + if (value != null) + values.add(value); + + series = row.getString(sIdx); + } + + if (logger.isDebugEnabled()) { + logger.debug(" --- series name: " + series); + logger.debug(" --- series items: " + values.size()); + } + + data.add((Double[]) values.toArray(new Double[values.size()])); + names.add(series); + } + } + catch (Exception e) { + logger.error(e.getMessage(), e); + } + + int count = data.size(); + logger.debug(" === Found total: " + count); + Object[][] obj = new Object[count][2]; + for (int i = 0; i < count; i++) { + obj[i][0] = names.get(i); + obj[i][1] = (Double[]) data.get(i); + } + + return obj; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java Wed Jun 09 09:37:57 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java Wed Jun 09 09:51:05 2010 +0000 @@ -20,6 +20,7 @@ import de.intevation.gnv.utils.VectorDataProcessor; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.state.exception.StateException; import de.intevation.gnv.statistics.Statistics; @@ -30,6 +31,7 @@ import java.util.Collection; import java.util.Locale; +import java.util.Map; import net.sf.ehcache.Cache; @@ -163,6 +165,23 @@ @Override + protected Chart[] getHistograms( + String uuid, + CallContext callContext, + Collection<KeyValueDescibeData> parameters, + Collection<KeyValueDescibeData> measurements, + Collection<KeyValueDescibeData> dates, + Map requestParameter + ) { + Collection results = (Collection) getChartResult(uuid, callContext); + ChartTheme theme = createStyle(callContext); + + return VectorDataProcessor.getHistograms( + uuid, callContext, results, theme, requestParameter); + } + + + @Override protected void createODV( OutputStream outputStream, Collection result, String uuid) throws IOException, StateException
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/VectorDataProcessor.java Wed Jun 09 09:37:57 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/VectorDataProcessor.java Wed Jun 09 09:51:05 2010 +0000 @@ -1,19 +1,33 @@ package de.intevation.gnv.utils; +import de.intevation.artifacts.CallContext; + +import de.intevation.gnv.chart.Chart; +import de.intevation.gnv.chart.ChartLabels; +import de.intevation.gnv.chart.DefaultHistogram; + import de.intevation.gnv.geobackend.base.DefaultResult; import de.intevation.gnv.geobackend.base.DefaultResultDescriptor; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.geobackend.base.ResultDescriptor; +import de.intevation.gnv.histogram.HistogramHelper; + +import de.intevation.gnv.state.describedata.KeyValueDescibeData; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import org.apache.log4j.Logger; +import org.jfree.chart.ChartTheme; + + /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ @@ -101,5 +115,31 @@ " columns"); return desc; } + + + public static Chart[] getHistograms( + String uuid, + CallContext callContext, + Collection<KeyValueDescibeData> results, + ChartTheme theme, + Map requestParameter + ) { + Locale locale = (Locale) requestParameter.get("locale"); + + Object[][] data = HistogramHelper.prepareVectorialHistogramData(results); + int size = data.length; + + Chart[] histograms = new Chart[size]; + + for (int i = 0; i < size; i++) { + ChartLabels labels = HistogramHelper.createHistogramLabels( + uuid, callContext, locale, data[i]); + + histograms[i] = new DefaultHistogram( + labels, data[i], theme, requestParameter); + } + + return histograms; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :