Mercurial > dive4elements > river
changeset 447:5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
flys-artifacts/trunk@1939 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 18 May 2011 08:04:54 +0000 |
parents | c0bec245f608 |
children | 88d9e1d75d64 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/NamedObject.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/WstWriter.java |
diffstat | 6 files changed, 130 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue May 17 16:31:07 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed May 18 08:04:54 2011 +0000 @@ -1,3 +1,21 @@ +2011-05-18 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/NamedObject.java: + New. This object is used to give objects a name. + + * src/main/java/de/intevation/flys/artifacts/model/WQKms.java: Inherit + from NamedObject now. Because we need to display names for those objects + in different places. + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: The WQKms + objects returned by a waterlevel computation will now have names. + + * src/main/java/de/intevation/flys/exports/WaterlevelExporter.java: + Insert the column names for the WSTs into the WstWriter. + + * src/main/java/de/intevation/flys/exports/WstWriter.java: The column + names are written into the head of the WSTs now. + 2011-05-17 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/WstLine.java: New. This
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue May 17 16:31:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed May 18 08:04:54 2011 +0000 @@ -252,12 +252,15 @@ throw new NullPointerException("No Kms selected."); } - double[] qs = getQs(); + double[] qs = getQs(); + double[] ws = null; + boolean qSel = true; + if (qs == null) { logger.debug("Determine Q values based on a set of W values."); - - double[] ws = getWs(); - qs = getQsForWs(ws); + qSel = false; + ws = getWs(); + qs = getQsForWs(ws); } WstValueTable wst = WstValueTableFactory.getTable(river); @@ -265,9 +268,28 @@ throw new NullPointerException("No Wst found for selected river."); } + WQKms[] results = computeWaterlevelData(kms, qs, wst); + // TODO Introduce a caching mechanism here! - return computeWaterlevelData(kms, qs, wst); + setWaterlevelNames(results, qSel ? qs : ws, qSel ? "Q" : "W"); + + return results; + } + + + /** + * Sets the name for waterlevels where each WQKms in <i>r</i> represents a + * column. + * + * @param r The waterlevel columns. + * @param v The input values of the computations. + * @param wq The WQ mode - can be one of "W" or "Q". + */ + public static void setWaterlevelNames(WQKms[] r, double[] v, String wq) { + for (int i = 0; i < v.length; i++) { + r[i].setName(wq + "=" + Double.toString(v[i])); + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/NamedObject.java Wed May 18 08:04:54 2011 +0000 @@ -0,0 +1,32 @@ +package de.intevation.flys.artifacts.model; + +import java.io.Serializable; + + +/** + * This class represents an object that has a name. The default case would be to + * inherit from this class. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class NamedObject implements Serializable { + + /** The name of this object.*/ + protected String name; + + + public NamedObject(String name) { + this.name = name; + } + + + public void setName(String name) { + this.name = name; + } + + + public String getName() { + return name; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Tue May 17 16:31:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Wed May 18 08:04:54 2011 +0000 @@ -1,7 +1,5 @@ package de.intevation.flys.artifacts.model; -import java.io.Serializable; - import gnu.trove.TDoubleArrayList; import org.apache.log4j.Logger; @@ -13,7 +11,7 @@ * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class WQKms implements Serializable { +public class WQKms extends NamedObject { private static Logger logger = Logger.getLogger(WQKms.class); @@ -29,12 +27,27 @@ public WQKms() { + this(""); + } + + + public WQKms(String name) { + super(name); + this.w = new TDoubleArrayList(); this.q = new TDoubleArrayList(); this.kms = new TDoubleArrayList(); } + public WQKms(int capacity) { + this(capacity, ""); + } + + + public WQKms(int capacity, String name) { + super(name); + this.w = new TDoubleArrayList(capacity); this.q = new TDoubleArrayList(capacity); this.kms = new TDoubleArrayList(capacity); @@ -42,6 +55,13 @@ public WQKms(double[] kms, double[] qs, double[] ws) { + this(kms, qs, ws, ""); + } + + + public WQKms(double[] kms, double[] qs, double[] ws, String name) { + super(name); + this.w = new TDoubleArrayList(ws); this.q = new TDoubleArrayList(qs); this.kms = new TDoubleArrayList(kms);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Tue May 17 16:31:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Wed May 18 08:04:54 2011 +0000 @@ -171,6 +171,8 @@ for (WQKms wqkms: tmp) { int size = wqkms != null ? wqkms.size() : 0; + writer.addColumn(wqkms.getName()); + for (int i = 0; i < size; i++) { result = wqkms.get(i, result);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WstWriter.java Tue May 17 16:31:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WstWriter.java Wed May 18 08:04:54 2011 +0000 @@ -5,8 +5,10 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TreeMap; @@ -34,6 +36,9 @@ /** The lines that need to be included for the export.*/ protected Map<Double, WstLine> lines; + /** The column names.*/ + protected List<String> columnNames; + /** The locale used to format the values.*/ protected Locale locale; @@ -53,10 +58,11 @@ * @param cols The number of columns of the resulting WST. */ public WstWriter(int cols) { - this.cols = cols; - this.qs = new double[cols]; - this.locale = Locale.US; - this.lines = new HashMap<Double, WstLine>(); + this.columnNames = new ArrayList<String>(cols); + this.lines = new HashMap<Double, WstLine>(); + this.qs = new double[cols]; + this.locale = Locale.US; + this.cols = cols; } @@ -105,6 +111,18 @@ /** + * Adds a further column name. + * + * @param name The name of the new column. + */ + public void addColumn(String name) { + if (name != null) { + columnNames.add(name); + } + } + + + /** * This method writes the header of the WST. * * @param writer The PrintWriter that creates the output. @@ -113,8 +131,13 @@ logger.debug("WstWriter.writeHeader"); writer.println(cols); + writer.print(" "); - // TODO WRITE DISCHARGE COLUMNS + for (String columnName: columnNames) { + writer.printf(locale, "%9s", columnName); + } + + writer.println(); writer.write("* KM "); writer.write(DEFAULT_UNIT);