# HG changeset patch # User Felix Wolfsteller # Date 1330941606 0 # Node ID 0611ae467e4a392ccabb72a60b9e5e623f87d88c # Parent 475dd07c2cb1ede7e6e69935dd7cd7b3a0140d9e Stub to export the 'W (cm)' column of reference curves conditionally on Gauge presence. flys-artifacts/trunk@4114 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 475dd07c2cb1 -r 0611ae467e4a flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Mar 05 09:53:30 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Mar 05 10:00:06 2012 +0000 @@ -1,3 +1,13 @@ +2012-03-05 Felix Wolfsteller + + * src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java: + Stub to export the "W (cm)" column conditionally on Gauge presence. + +2012-03-05 Felix Wolfsteller + + * src/main/java/de/intevation/flys/exports/StepCSVWriter.java: + New utility to handle csv rows of more "dynamical" length. + 2012-03-05 Felix Wolfsteller * src/main/java/de/intevation/flys/exports/StepCSVWriter.java: diff -r 475dd07c2cb1 -r 0611ae467e4a flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java Mon Mar 05 09:53:30 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java Mon Mar 05 10:00:06 2012 +0000 @@ -3,14 +3,17 @@ import java.io.IOException; import java.io.OutputStream; import java.text.NumberFormat; + import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; import java.util.List; - +import java.util.LinkedList; +import java.util.Locale; import java.util.Map; import java.util.HashMap; -import java.util.Date; + import java.text.DateFormat; -import java.util.Locale; import org.w3c.dom.Document; @@ -36,6 +39,7 @@ import de.intevation.flys.utils.FLYSUtils; + /** * (CSV)Exporter for Reference Curves. */ @@ -44,7 +48,6 @@ /** The logger used in this exporter. */ private static Logger logger = Logger.getLogger(ReferenceCurveExporter.class); - public static final String RC_CSV_KM_HEADER = "export.reference_curve.csv.header.km"; @@ -73,7 +76,11 @@ /** The storage that contains all WKms objects for the different facets. */ protected List data; + protected boolean startAtGauge = false; + protected boolean endAtGauge = false; + + public void init(Document request, OutputStream out, CallContext context) { logger.debug("ReferenceCurveExporter.init"); @@ -109,7 +116,7 @@ /** * Adds given data. - * @param d a WWQQ[]. + * @param d A CalculationResult with WWQQ[]. */ @Override protected void addData(Object d) { @@ -118,7 +125,17 @@ if (d instanceof CalculationResult) { d = ((CalculationResult)d).getData(); if (d instanceof WWQQ []) { - data.add((WWQQ [])d); + WWQQ[] wwqqs = (WWQQ []) d; + for (WWQQ wwqq: wwqqs) { + if (wwqq.startAtGauge()) { + startAtGauge = true; + } + // TODO this one probably has to be inverted. + if (wwqq.endAtGauge()) { + endAtGauge = true; + } + } + data.add(wwqqs); logger.debug("ReferenceCurveExporter.addData wwqq[]."); } else { @@ -158,19 +175,40 @@ protected void writeCSVHeader(CSVWriter writer) { logger.info("ReferenceCurveExporter.writeCSVHeader"); - // TODO missing 'relative' W(cm). - writer.writeNext(new String[] { + StepCSVWriter stepWriter; + + // TODO use StepCVSWriter here + ArrayList list = new ArrayList(); + list.addAll(Arrays.asList( new String[] { msg(RC_CSV_KM_HEADER, RC_DEFAULT_CSV_KM_HEADER), msg(CSV_LOCATION_HEADER, DEFAULT_CSV_LOCATION_HEADER), - msg(RC_CSV_W_M_HEADER, RC_DEFAULT_CSV_W_M_HEADER), - msg(RC_CSV_W_CM_HEADER, RC_DEFAULT_CSV_W_CM_HEADER), + msg(RC_CSV_W_M_HEADER, RC_DEFAULT_CSV_W_M_HEADER) + })); + if (startAtGauge) { + list.addAll(Arrays.asList( new String[] { + msg(RC_CSV_W_CM_HEADER, RC_DEFAULT_CSV_W_CM_HEADER) + })); + } + list.addAll(Arrays.asList( new String[] { msg(RC_CSV_Q_HEADER, RC_DEFAULT_CSV_Q_HEADER), msg(RC_CSV_KM_HEADER, RC_DEFAULT_CSV_KM_HEADER), msg(CSV_LOCATION_HEADER, DEFAULT_CSV_LOCATION_HEADER), - msg(RC_CSV_W_M_HEADER, RC_DEFAULT_CSV_W_M_HEADER), - msg(RC_CSV_W_CM_HEADER, RC_DEFAULT_CSV_W_CM_HEADER), - msg(RC_CSV_Q_HEADER, RC_DEFAULT_CSV_Q_HEADER), - }); + msg(RC_CSV_W_M_HEADER, RC_DEFAULT_CSV_W_M_HEADER) + })); + if (endAtGauge) { + list.addAll(Arrays.asList( new String[] { + msg(RC_CSV_W_CM_HEADER, RC_DEFAULT_CSV_W_CM_HEADER), + msg(RC_CSV_Q_HEADER, RC_DEFAULT_CSV_Q_HEADER) + })); + } + else { + list.addAll(Arrays.asList( new String[] { + msg(RC_CSV_Q_HEADER, RC_DEFAULT_CSV_Q_HEADER) + })); + } + + + writer.writeNext(list.toArray(new String[list.size()])); } @@ -181,30 +219,37 @@ NumberFormat wf = getWFormatter(); NumberFormat qf = getQFormatter(); - int size = ww.size(); + int size = ww.size(); FLYSArtifact flys = (FLYSArtifact) master; + StepCSVWriter stepWriter = new StepCSVWriter(); + stepWriter.setCSVWriter(writer); + String startLocationDescription = FLYSUtils.getLocationDescription( flys, ww.getStartKm()); String endLocationDescription = FLYSUtils.getLocationDescription( flys, ww.getEndKm()); - // TODO missing 'relative' W(cm). for (int i = 0; i < size; i ++) { - writer.writeNext(new String[] { - kmf.format(ww.getStartKm()), - startLocationDescription, - wf.format(ww.getW1(i)), - wf.format(ww.getRelHeight1Cm(i)), + stepWriter.addNexts(kmf.format(ww.getStartKm()), + startLocationDescription); + if (startAtGauge) { + stepWriter.addNext(wf.format(ww.getRelHeight1Cm(i))); + } + stepWriter.addNext(wf.format(ww.getW1(i))); + stepWriter.addNexts( qf.format(ww.getQ1(i)), // "Q" kmf.format(ww.getEndKm()), - endLocationDescription, - wf.format(ww.getW2(i)), - wf.format(ww.getRelHeight2Cm(i)), - qf.format(ww.getQ2(i)) // "Q" - }); + endLocationDescription); + if (endAtGauge) { + stepWriter.addNext(wf.format(ww.getRelHeight2Cm(i))); + } + stepWriter.addNext(wf.format(ww.getW2(i))); + stepWriter.addNext(qf.format(ww.getQ2(i)) // "Q" + ); + stepWriter.flush(); } } @@ -274,7 +319,7 @@ int size = ww.size(); - FLYSArtifact flys = (FLYSArtifact) master; + FLYSArtifact flys = (FLYSArtifact) master; String startLocationDescription = FLYSUtils.getLocationDescription( flys, ww.getStartKm());