# HG changeset patch # User Ingo Weinzierl # Date 1304497490 0 # Node ID befedd7629d55603c61cb44a898b5bd60ebebb4a # Parent 72177020db9276de0fc086fb87b9df73c66f16d5 Enabled the WINFO artifact to compute the data for discharge curves (computed) - ComputedDischargeCurveGenerator uses those values now to create the chart. flys-artifacts/trunk@1818 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 72177020db92 -r befedd7629d5 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed May 04 07:48:39 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed May 04 08:24:50 2011 +0000 @@ -1,3 +1,12 @@ +2011-05-04 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Added + methods to compute and retrieve the data for discharge curves (computed). + + * src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java: + Fetch the computed discharge curve data from WINFOArtifact and add the + values into the JFreeChart dataset. + 2011-05-04 Ingo Weinzierl * doc/conf/artifacts/winfo.xml: Added new transitions and states to enable diff -r 72177020db92 -r befedd7629d5 flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed May 04 07:48:39 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed May 04 08:24:50 2011 +0000 @@ -376,5 +376,73 @@ return wqday; } + + + /** + * Returns the data that is computed by a discharge curve computation. + * + * @return the data computed by a discharge curve computation. + */ + public WQKms getComputedDischargeCurveData() + throws NullPointerException + { + logger.debug("WINFOArtifact.getComputedDischargeCurveData"); + + River r = getRiver(); + + if (r == null) { + throw new NullPointerException("Cannot determine river."); + } + + double[] locations = getLocations(); + + if (locations == null) { + throw new NullPointerException("Cannot determine location."); + } + + WstValueTable wst = WstValueTable.getTable(r); + if (wst == null) { + throw new NullPointerException("No Wst found for selected river."); + } + + // TODO Introduce a caching mechanism here! + + return computeDischargeCurveData(wst, locations[0]); + } + + + /** + * Computes the data used to create computed discharge curves. + * + * @param wst The WstValueTable that is used for the interpolation. + * @param location The location where the computation should be based on. + * + * @return an object that contains tuples of W/Q values at the specified + * location. + */ + public static WQKms computeDischargeCurveData( + WstValueTable wst, + double location) + { + logger.info("WINFOArtifact.computeDischargeCurveData"); + + double[][] wqs = wst.interpolateWQ(location); + + if (wqs == null) { + logger.error("Cannot compute discharge curve data."); + return null; + } + + double[] ws = wqs[0]; + double[] qs = wqs[1]; + + WQKms wqkms = new WQKms(ws.length); + + for (int i = 0; i < ws.length; i++) { + wqkms.add(ws[i], qs[i], location); + } + + return wqkms; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 72177020db92 -r befedd7629d5 flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Wed May 04 07:48:39 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Wed May 04 08:24:50 2011 +0000 @@ -6,6 +6,9 @@ import de.intevation.artifacts.Artifact; +import de.intevation.flys.artifacts.WINFOArtifact; +import de.intevation.flys.artifacts.model.WQKms; + /** * An OutGenerator that generates discharge curves. @@ -22,7 +25,32 @@ @Override public void doOut(Artifact artifact, String facet, Document attr) { logger.debug("ComputedDischargeCurveGenerator.doOut"); - // TODO FILL ME + + WQKms wqkms = getData(artifact); + + int size = wqkms.size(); + + double[][] data = new double[2][size]; + double[] res = new double[3]; + + for (int i = 0; i < size; i++) { + res = wqkms.get(i, res); + + data[0][i] = res[1]; + data[1][i] = res[0]; + } + + // TODO find the correct name + dataset.addSeries("Abflusskurve", data); + } + + + protected WQKms getData(Artifact artifact) { + logger.debug("ComputedDischargeCurveGenerator.getData"); + + WINFOArtifact winfoArtifact = (WINFOArtifact) artifact; + + return winfoArtifact.getComputedDischargeCurveData(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :