# HG changeset patch # User Tim Englich # Date 1257756901 0 # Node ID 3d6d89bcbf4228fcf44af9333a86fc4943e39512 # Parent 74255064a4c5dcf40fd5613a58d927c84ab9ac53 Added special Data-Selection to the ODV-Exports of TimeSeries on TimeSeriesPoints. issue68 gnv-artifacts/trunk@300 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/ChangeLog Mon Nov 09 08:55:01 2009 +0000 @@ -1,3 +1,24 @@ +2009-11-09 Tim Englich + + * src/test/ressources/timeseries/timeseries_step_06_out_*.xml: + Added the missing out-Modes to the Testcase and rename it to + the common used way in this TestCases. + * src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java (testTimeSeriesArtifact): + Added the ODV-Export to the Unit-Testcase. + Some Refactoring Work done. + * src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java (out): + The Method for generating ODV-Export now reads its Data from + the special Method which delivers the adapted Data. + * src/main/java/de/intevation/gnv/transition/TransitionBase.java (generateFilterValuesFromInputData): + Extracted the Generation of the FilterValues for the geo-backend + to use it in several methods. + * src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java (getODVResult): + Added Method for getting the rquired Data for ODV-Exports + * doc/conf/products/timeseries/conf_timeseriespoint.xml: + Added separat QueryID Lookup for ODV-Data-Queryies + * doc/conf/queries.properties: + DB-Queries for ODV-Support TimeSeries on TimeSeriesPoints added. + 2009-11-06 Ingo Weinzierl * src/main/java/de/intevation/gnv/exports, diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml --- a/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Mon Nov 09 08:55:01 2009 +0000 @@ -98,6 +98,7 @@ timeseries_chart_data + timeseries_odv_data diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/doc/conf/queries.properties --- a/gnv-artifacts/doc/conf/queries.properties Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/doc/conf/queries.properties Mon Nov 09 08:55:01 2009 +0000 @@ -82,6 +82,35 @@ tv.TIMESERIESID , \ t.PARAMETERID , \ tv.TIMEVALUE + +timeseries_odv_data = SELECT SI.NAME CRUISE, \ + MEDIAN.TIMESERIESPOINT.NAME STATION, \ + '*' TYPE, \ + ST_ASTEXT(SHAPE), \ + 0 BOTDEPTH, \ + (M.ZLOCATION *-1) DEPTH, \ + TSV.TIMEVALUE, \ + TSV.DATAVALUE, \ + TS.PARAMETERID PARAMETER, \ + TSV.MEASUREMENTID, \ + TSV.TIMESERIESID \ + FROM MEDIAN.TIMESERIESPOINT , \ + MEDIAN.TIMESERIESVALUE TSV, \ + MEDIAN.TIMESERIES TS, \ + MEDIAN.MEASUREMENT M, \ + MEDIAN.SOURCEINFO SI \ + WHERE SI.SOURCEID = M.SOURCEID AND \ + M.FEATUREID = MEDIAN.TIMESERIESPOINT.FEATUREID AND \ + M.MEASUREMENTID = TSV.MEASUREMENTID AND \ + TSV.TIMESERIESID = TS.TIMESERIESID AND \ + TS.PARAMETERID IN ( ? ) AND \ + TSV.MEASUREMENTID IN ( ? ) AND \ + TSV.TIMEVALUE >= ? AND \ + TSV.TIMEVALUE <= ? \ + ORDER BY TSV.MEASUREMENTID , \ + TSV.TIMESERIESID , \ + TS.PARAMETERID , \ + TSV.TIMEVALUE ############################################# ############################################# @@ -685,5 +714,4 @@ FROM MEDIAN.FEATUREAREA \ WHERE (FEATURETYPE = 7 OR FEATURETYPE = 8) AND \ FEATUREID = ? \ - ORDER BY NAME - \ No newline at end of file + ORDER BY NAME \ No newline at end of file diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java Mon Nov 09 08:55:01 2009 +0000 @@ -66,7 +66,7 @@ protected XYSeries createXYSeries(String seriesName, Collection resultSet, int lUpperCut, int lLowerCut, int pStart, - int pEnd) throws TechnicalChartException { + int pEnd, double maxGap) throws TechnicalChartException { if (sDebug) sLogger.debug("createXYSeries()"); XYSeries series = new XYSeries(seriesName); diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java Mon Nov 09 08:55:01 2009 +0000 @@ -212,7 +212,7 @@ protected XYSeries createXYSeries(String seriesName, Collection resultSet, int lUpperCut, int lLowerCut, int pStart, - int pEnd) throws TechnicalChartException { + int pEnd, double maxGap) throws TechnicalChartException { if (sDebug) sLogger.debug("createXYSeries()"); XYSeries series = new XYSeries(seriesName); @@ -262,16 +262,23 @@ int mEnd = 0; Iterator resultIterator = resultSet.iterator(); + Result firstRow = null, lastRow = null; + + double maxGap; if (resultIterator.hasNext()) { // Row row = new Row(sArrayStrLine); Result row = resultIterator.next(); - + + firstRow = row; + lastRow = row; + break1 = row.getString("GROUP1"); // 2 break2 = row.getString("GROUP2"); // 3 break3 = row.getString("GROUP3"); // 4 int i = 1; while (resultIterator.hasNext()) { row = resultIterator.next(); + if (!break1.equals(row.getString("GROUP1")) || !break2.equals(row.getString("GROUP2")) || !break3.equals(row.getString("GROUP3"))) { @@ -279,8 +286,12 @@ sLogger.debug("Neuer Datensatz " + seriesName + "von Datensätzen " + mStart + " / " + mEnd); + + maxGap = this.calculateMaxGap(firstRow, lastRow, mEnd-mStart); + xyDataset.addSeries(createXYSeries(seriesName, - resultSet, lUpperCut, lLowerCut, mStart, mEnd)); + resultSet, lUpperCut, lLowerCut, mStart, mEnd,maxGap)); + firstRow = row; mStart = i; break1 = row.getString("GROUP1"); @@ -288,6 +299,7 @@ break3 = row.getString("GROUP3"); // 4 } + lastRow = row; mEnd = i; // mEnd ++; i = i + 1; @@ -296,11 +308,13 @@ String seriesName = this.createSeriesName(parameters, measurements, dates, break1, break2, break3); sLogger.debug("Neuer Datensatz " + seriesName + "von Datensätzen " + mStart + " / " + mEnd); + + maxGap = this.calculateMaxGap(firstRow, lastRow, mEnd-mStart); xyDataset.addSeries(createXYSeries(seriesName, resultSet, - lUpperCut, lLowerCut, mStart, mEnd)); + lUpperCut, lLowerCut, mStart, mEnd,maxGap)); }else{ xyDataset.addSeries(createXYSeries("", - resultSet, lUpperCut, lLowerCut, mStart, mEnd)); + resultSet, lUpperCut, lLowerCut, mStart, mEnd,9999)); } } catch (Exception e) { sLogger.error(e.getMessage(), e); @@ -308,6 +322,15 @@ } return xyDataset; } + + + protected double calculateMaxGap(Result firstRow, Result lastRow, int numResults){ + + double firstValue = firstRow.getDouble("YORDINATE"); + // TODO Implement me. Hier ist die zentrale Frage wie wir zwischen Netzen und + // anderen Datenquellen unterscheiden. + return 0; + } /** * @param parameters diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Mon Nov 09 08:55:01 2009 +0000 @@ -17,6 +17,9 @@ import de.intevation.artifacts.CallMeta; import de.intevation.gnv.artifacts.cache.CacheFactory; import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.geobackend.base.query.QueryExecutor; +import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; +import de.intevation.gnv.geobackend.base.query.exception.QueryException; import de.intevation.gnv.transition.exception.TransitionException; /** @@ -40,6 +43,8 @@ * The different Outputmodes which are provided by an OutputTransition */ protected Collection outputModes = null; + + protected String queryODVID = null; /** * Constructor @@ -63,6 +68,9 @@ public void setup(Node configuration) { log.debug("OutputTransitionBase.setup"); super.setup(configuration); + + this.queryODVID = Config.getStringXPath(configuration,"queryID-odv"); + NodeList outputModeList = Config.getNodeSetXPath(configuration, "outputsModes/outputsMode"); if (outputModeList != null) { @@ -138,6 +146,31 @@ return null; } + protected Collection getODVResult(String uuid) { + log.debug("OutputTransitionBase.getODVResult"); + // TODO add Caching? I think it's not nessessary + Collection returnValue = null; + if (this.queryODVID != null){ + try { + String[] filterValues = this.generateFilterValuesFromInputData(); + try { + QueryExecutor queryExecutor = QueryExecutorFactory + .getInstance() + .getQueryExecutor(); + returnValue = queryExecutor.executeQuery(this.queryODVID, + filterValues); + } catch (RuntimeException e) { + log.error(e, e); + } + } catch (QueryException e) { + log.error(e, e); + } + }else{ + log.warn("No Query for ODV Data is defined."); + } + return returnValue; + } + protected void removeChartResult(String uuid) { log.debug("OutputTransitionBase.getChartResult"); if (CacheFactory.getInstance().isInitialized()) { diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Mon Nov 09 08:55:01 2009 +0000 @@ -368,35 +368,7 @@ this.alternativeTransition.advance(uuid, callMeta); }else{ try { - List list = new ArrayList(); - Iterator it = this.inputValueNames.iterator(); - int i = 0; - while (it.hasNext()) { - String value = it.next(); - InputData data = this.inputData.get(value); - if (data != null - && this.inputValues.containsKey(data.getName())) { - int size = this.inputValues.get(data.getName()) - .usedInQueries(); - String type = this.inputValues.get(data.getName()) - .getType(); - String requestValue = data.getValue(); - if (type.equalsIgnoreCase("string")) { - requestValue = this - .prepareInputData4DBQuery(requestValue); - } else if (type.equalsIgnoreCase("date")) { - requestValue = this - .prepareInputData4DateDBQuery(requestValue); - } else if (type.equalsIgnoreCase("coordinate")){ - requestValue = this - .prepareInputData4RegionDBQuery(requestValue); - } - for (int j = 0; j < size; j++) { - list.add(requestValue); - } - } - } - String[] filterValues = list.toArray(new String[0]); + String[] filterValues = this.generateFilterValuesFromInputData(); Collection result = null; try { if (this.queryID != null) { @@ -415,6 +387,41 @@ } } } + + /** + * @return + */ + protected String[] generateFilterValuesFromInputData() { + List list = new ArrayList(); + Iterator it = this.inputValueNames.iterator(); + while (it.hasNext()) { + String value = it.next(); + InputData data = this.inputData.get(value); + if (data != null + && this.inputValues.containsKey(data.getName())) { + int size = this.inputValues.get(data.getName()) + .usedInQueries(); + String type = this.inputValues.get(data.getName()) + .getType(); + String requestValue = data.getValue(); + if (type.equalsIgnoreCase("string")) { + requestValue = this + .prepareInputData4DBQuery(requestValue); + } else if (type.equalsIgnoreCase("date")) { + requestValue = this + .prepareInputData4DateDBQuery(requestValue); + } else if (type.equalsIgnoreCase("coordinate")){ + requestValue = this + .prepareInputData4RegionDBQuery(requestValue); + } + for (int j = 0; j < size; j++) { + list.add(requestValue); + } + } + } + String[] filterValues = list.toArray(new String[0]); + return filterValues; + } protected String prepareInputData4RegionDBQuery(String value){ return value; diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Mon Nov 09 08:55:01 2009 +0000 @@ -7,8 +7,6 @@ import java.awt.Dimension; import java.io.IOException; import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collection; @@ -39,6 +37,9 @@ import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.ChartStyle; import de.intevation.gnv.chart.exception.TechnicalChartException; +import de.intevation.gnv.exports.DefaultExport; +import de.intevation.gnv.exports.DefaultProfile; +import de.intevation.gnv.exports.Export.Profile; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.statistics.Statistic; import de.intevation.gnv.statistics.Statistics; @@ -51,11 +52,6 @@ import de.intevation.gnv.transition.describedata.KeyValueDescibeData; import de.intevation.gnv.transition.describedata.NamedCollection; import de.intevation.gnv.transition.exception.TransitionException; - -import de.intevation.gnv.exports.DefaultExport; -import de.intevation.gnv.exports.DefaultProfile; -import de.intevation.gnv.exports.Export.Profile; - import de.intevation.gnv.utils.ArtifactXMLUtilities; @@ -93,6 +89,19 @@ "GROUP2", "GROUP3" }; + + public static final String [] TIMESERIES_ODV_PROFILE_NAMES = { + "CRUISE", + "STATION", + "TYPE", + "BOTDEPTH", + "DEPTH", + "TIMEVALUE", + "DATAVALUE", + "PARAMETER", + "MEASUREMENTID", + "TIMESERIESID" + }; /** * Profile for exporting data to cvs @@ -112,7 +121,7 @@ */ public static final Profile TIMESERIES_ODV_PROFILE = new DefaultProfile( - TIMESERIES_CSV_PROFILE_NAMES, + TIMESERIES_ODV_PROFILE_NAMES, '\t', CSVWriter.NO_QUOTE_CHARACTER, CSVWriter.NO_ESCAPE_CHARACTER, @@ -137,8 +146,8 @@ log.debug("TimeSeriesOutputTransition.out"); try { - this.advance(uuid, callMeta); - Collection chartResult = this.getChartResult(uuid); + this.advance(uuid, callMeta); // TODO This hsould only be done if it is nessessary + if (outputMode.equalsIgnoreCase("chart")) { log.debug("Chart will be generated."); int chartWidth = 600; @@ -170,10 +179,12 @@ chartStyle, chartLables, uuid); } else if (outputMode.equalsIgnoreCase("csv")) { log.debug("CSV-File will be generated."); + Collection chartResult = this.getChartResult(uuid); this.createCSV(outputStream, chartResult); } else if (outputMode.equalsIgnoreCase("statistics")) { log.debug("Statistics will be generated."); Statistics s = getStatisticsGenerator(); + Collection chartResult = this.getChartResult(uuid); Collection statistics = s .calculateStatistics(chartResult); Document doc = this.writeStatistics2XML(statistics); @@ -181,7 +192,9 @@ } else if (outputMode.equalsIgnoreCase("odv")) { //TimeSeriesExport export = new TimeSeriesExport(); //export.createODV(outputStream, chartResult); - createODV(outputStream, chartResult); + + Collection odvResult = this.getODVResult(uuid); + this.createODV(outputStream, odvResult); } } catch (IOException e) { log.error(e, e); diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java --- a/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java Mon Nov 09 08:55:01 2009 +0000 @@ -92,64 +92,56 @@ // Erster Schritt Document describeDocument = this.readDocument("src/test/ressources/timeseries/timeseries_describe.xml"); - this - .doNextStep( - artifact, - cc, - "src/test/ressources/timeseries/timeseries_step_01_feed.xml", - "src/test/ressources/timeseries/timeseries_step_01_advance.xml", describeDocument); - - // Zweiter Schritt - this - .doNextStep( - artifact, - cc, - "src/test/ressources/timeseries/timeseries_step_02_feed.xml", - "src/test/ressources/timeseries/timeseries_step_02_advance.xml", describeDocument); - - // Dritter Schritt - this - .doNextStep( - artifact, - cc, - "src/test/ressources/timeseries/timeseries_step_03_feed.xml", - "src/test/ressources/timeseries/timeseries_step_03_advance.xml", describeDocument); - - // Vierter Schritt - this - .doNextStep( + + int steps = 5; + + for (int i = 1; i <= steps; i++){ + + this.doNextStep( artifact, cc, - "src/test/ressources/timeseries/timeseries_step_04_feed.xml", - "src/test/ressources/timeseries/timeseries_step_04_advance.xml", describeDocument); - - // Fünfter Schritt - this - .doNextStep( - artifact, - cc, - "src/test/ressources/timeseries/timeseries_step_05_feed.xml", - "src/test/ressources/timeseries/timeseries_step_05_advance.xml", describeDocument); - + "src/test/ressources/timeseries/" + + "timeseries_step_0"+i+"_feed.xml", + "src/test/ressources/timeseries/" + + "timeseries_step_0"+i+"_advance.xml", + describeDocument); - Document outputData; - // Fünfter Schritt - outputData = artifact.describe(describeDocument,cc); + } + + Document outputData = artifact.describe(describeDocument,cc); FileOutputStream fos = null; + FileOutputStream fos2 = null; + FileOutputStream fos3 = null; + FileOutputStream fos4 = null; try { - fos = new FileOutputStream( - "src/test/results/timeseriesdiagramm" - + System.currentTimeMillis() + ".png"); - artifact - .feed( - this - .readDocument("src/test/ressources/timeseries/timeseries_step_06_feed.xml"), - cc); - artifact - .out( - this - .readDocument("src/test/ressources/timeseries/timeseries_step_06_out.xml"), - fos, cc); + fos = new FileOutputStream("src/test/results/timeseries" + + System.currentTimeMillis() + + ".png"); + fos2 = new FileOutputStream("src/test/results/timeseries" + + System.currentTimeMillis() + + ".xml"); + fos3 = new FileOutputStream("src/test/results/timeseries" + + System.currentTimeMillis() + + ".csv"); + fos4 = new FileOutputStream("src/test/results/timeseries" + + System.currentTimeMillis() + + ".odv"); + + artifact.feed(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_feed.xml"), + cc); + artifact.out(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_chart.xml"), + fos, cc); + artifact.out(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_statistics.xml"), + fos2, cc); + artifact.out(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_csv.xml"), + fos3, cc); + artifact.out(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_odv.xml"), + fos4, cc); } catch (Exception e) { log.error(e, e); fail(); diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out.xml --- a/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out.xml Fri Nov 06 11:12:45 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_chart.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_chart.xml Mon Nov 09 08:55:01 2009 +0000 @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_csv.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_csv.xml Mon Nov 09 08:55:01 2009 +0000 @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_odv.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_odv.xml Mon Nov 09 08:55:01 2009 +0000 @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff -r 74255064a4c5 -r 3d6d89bcbf42 gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_statistics.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_statistics.xml Mon Nov 09 08:55:01 2009 +0000 @@ -0,0 +1,12 @@ + + + + + + + + + + + +