# HG changeset patch # User Ingo Weinzierl # Date 1328517386 0 # Node ID ea173e4c07c790b2a3aad49472b72a53b0436bb1 # Parent 86685feb5b1ca48ef70ba706bfde564b8e5eff02 Added a CSV export for historical discharge curves. flys-artifacts/trunk@3913 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Feb 06 07:39:59 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Feb 06 08:36:26 2012 +0000 @@ -1,3 +1,27 @@ +2012-02-06 Ingo Weinzierl + + * src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveExporter.java: + New. This OutGenerator exports historical discharge curves to CSV and PDF. + Currently, only the CSV export is implemented! + + * doc/conf/artifacts/winfo.xml: Registered a new Output CSV for historical + discharge curves. + + * doc/conf/conf.xml: Registered the HistoricalDischargeCurveExporter. + + * src/main/java/de/intevation/flys/artifacts/states/HistoricalDischargeComputeState.java: + Generate new Facets for CSV and PDF output. + + * src/main/java/de/intevation/flys/utils/Formatter.java: Added new functions + that return number formatters for historical discharge curves and a date + formatter for short dates. + + * src/main/resources/messages.properties, + src/main/resources/messages_de_DE.properties, + src/main/resources/messages_en.properties, + src/main/resources/messages_de.properties: Added strings for CSV header of + historical discharge curve export. + 2012-02-06 Felix Wolfsteller * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/doc/conf/artifacts/winfo.xml --- a/flys-artifacts/doc/conf/artifacts/winfo.xml Mon Feb 06 07:39:59 2012 +0000 +++ b/flys-artifacts/doc/conf/artifacts/winfo.xml Mon Feb 06 08:36:26 2012 +0000 @@ -493,6 +493,11 @@ + + + + + diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/doc/conf/conf.xml --- a/flys-artifacts/doc/conf/conf.xml Mon Feb 06 07:39:59 2012 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Mon Feb 06 08:36:26 2012 +0000 @@ -180,6 +180,7 @@ de.intevation.flys.exports.ReferenceCurveGenerator de.intevation.flys.exports.ReferenceCurveInfoGenerator de.intevation.flys.exports.HistoricalDischargeCurveGenerator + de.intevation.flys.exports.HistoricalDischargeCurveExporter de.intevation.flys.exports.ReportGenerator de.intevation.flys.exports.ReportGenerator diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/HistoricalDischargeComputeState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/HistoricalDischargeComputeState.java Mon Feb 06 07:39:59 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/HistoricalDischargeComputeState.java Mon Feb 06 08:36:26 2012 +0000 @@ -16,6 +16,7 @@ import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.HistoricalDischargeFacet; import de.intevation.flys.artifacts.model.ReportFacet; @@ -76,6 +77,12 @@ return res; } + facets.add( + new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); + + facets.add( + new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, id)); + prepareFacets(facets, data); return res; diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveExporter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveExporter.java Mon Feb 06 08:36:26 2012 +0000 @@ -0,0 +1,145 @@ +package de.intevation.flys.exports; + +import java.io.OutputStream; +import java.text.NumberFormat; +import java.text.DateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import au.com.bytecode.opencsv.CSVWriter; + +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; + +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.Timerange; +import de.intevation.flys.artifacts.model.WQTimerange; +import de.intevation.flys.artifacts.resources.Resources; +import de.intevation.flys.utils.FLYSUtils; +import de.intevation.flys.utils.Formatter; + + +/** + * @author Ingo Weinzierl + */ +public class HistoricalDischargeCurveExporter extends AbstractExporter { + + private static final Logger logger = + Logger.getLogger(HistoricalDischargeCurveExporter.class); + + + public static final String CSV_TIMERANGE_HEADER = + "export.historical.discharge.csv.header.timerange"; + + public static final String CSV_WATERLEVEL_HEADER = + "export.historical.discharge.csv.header.waterlevel"; + + public static final String CSV_DISCHARGE_HEADER = + "export.historical.discharge.csv.header.discharge"; + + public static final String CSV_DIFF_HEADER = + "export.historical.discharge.csv.header.diff"; + + public static final String CSV_GAUGENAME_HEADER = + "export.historical.discharge.csv.header.gaugename"; + + + protected List data; + + + public void init(Document request, OutputStream out, CallContext cc) { + super.init(request, out, cc); + + data = new ArrayList(); + } + + + @Override + protected void addData(Object d) { + logger.debug("Add data of class: " + d.getClass()); + + if (d instanceof CalculationResult) { + d = ((CalculationResult) d).getData(); + + logger.debug("Internal data of CalculationResult: " + d.getClass()); + + if (d instanceof WQTimerange[]) { + logger.debug("Add new data of type WQTimerange"); + data.add((WQTimerange[]) d); + } + } + } + + + @Override + protected void writeCSVData(CSVWriter writer) { + logger.info("HistoricalDischargeCurveExporter.writeCSVData"); + logger.debug("CSV gets " + data.size() + " WQTimerange[] objects."); + + writeCSVHeader(writer); + + for (WQTimerange[] arr: data) { + for (WQTimerange wqt: arr) { + wqt2CSV(writer, wqt); + } + } + } + + + @Override + protected void writePDF(OutputStream out) { + logger.warn("TODO: IMPLEMENT ME!"); + } + + + protected void writeCSVHeader(CSVWriter writer) { + writer.writeNext(new String[] { + msg(CSV_TIMERANGE_HEADER, CSV_TIMERANGE_HEADER), + msg(CSV_WATERLEVEL_HEADER, CSV_WATERLEVEL_HEADER), + msg(CSV_DISCHARGE_HEADER, CSV_DISCHARGE_HEADER), + msg(CSV_DIFF_HEADER, CSV_DIFF_HEADER), + msg(CSV_GAUGENAME_HEADER, CSV_GAUGENAME_HEADER) + }); + } + + + protected void wqt2CSV(CSVWriter writer, WQTimerange wqt) { + logger.debug("Add next WQTimerange to CSV"); + + DateFormat df = Formatter.getShortDateFormat(context); + NumberFormat wf = Formatter.getHistoricalDischargeW(context); + NumberFormat qf = Formatter.getHistoricalDischargeQ(context); + + double[] wq = new double[2]; + + String gaugeName = getReferenceGaugename(); + + for (int i = 0, n = wqt.size(); i < n; i++) { + Timerange tr = wqt.getTimerange(i); + Date start = new Date(tr.getStart()); + Date end = new Date(tr.getEnd()); + + wqt.get(i, wq); + + writer.writeNext(new String[] { + df.format(start) + " - " + df.format(end), + wf.format(wq[0]), + qf.format(wq[1]), + "TODO: Difference to reference curve", + gaugeName + }); + } + } + + + public String getReferenceGaugename() { + return FLYSUtils.getReferenceGaugeName((FLYSArtifact) master); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Mon Feb 06 07:39:59 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Mon Feb 06 08:36:26 2012 +0000 @@ -1,5 +1,6 @@ package de.intevation.flys.utils; +import java.text.DateFormat; import java.text.NumberFormat; import java.util.Locale; @@ -26,6 +27,13 @@ public static final int COMPUTED_DISCHARGE_Q_MAX_DIGITS = 2; + // HISTORICAL DISCHARGE CURVE FORMATTER CONSTANTS + public static final int HISTORICAL_DISCHARGE_W_MIN_DIGITS = 0; + public static final int HISTORICAL_DISCHARGE_W_MAX_DIGITS = 2; + public static final int HISTORICAL_DISCHARGE_Q_MIN_DIGITS = 0; + public static final int HISTORICAL_DISCHARGE_Q_MAX_DIGITS = 2; + + // DURATION CURVE FORMATTER CONSTANTS public static final int DURATION_W_MIN_DIGITS = 0; public static final int DURATION_W_MAX_DIGITS = 2; @@ -60,6 +68,15 @@ /** + * Returns a date formatter with SHORT style. + */ + public static DateFormat getShortDateFormat(CallContext cc) { + Locale locale = Resources.getLocale(cc.getMeta()); + return DateFormat.getDateInstance(DateFormat.SHORT, locale); + } + + + /** * Returns the number formatter for kilometer values in waterlevel exports. * * @return the number formatter for kilometer values. @@ -127,6 +144,34 @@ /** + * Returns the number formatter for W values in exports of historical + * discharge curves. + * + * @return the number formatter for W values. + */ + public static NumberFormat getHistoricalDischargeW(CallContext context) { + return getFormatter( + context, + HISTORICAL_DISCHARGE_W_MIN_DIGITS, + HISTORICAL_DISCHARGE_W_MAX_DIGITS); + } + + + /** + * Returns the number formatter for Q values in exports of historical + * discharge curves. + * + * @return the number formatter for Q values. + */ + public static NumberFormat getHistoricalDischargeQ(CallContext context) { + return getFormatter( + context, + HISTORICAL_DISCHARGE_Q_MIN_DIGITS, + HISTORICAL_DISCHARGE_Q_MAX_DIGITS); + } + + + /** * Returns the number formatter for W values in duration curve exports. * * @return the number formatter for W values. diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/src/main/resources/messages.properties --- a/flys-artifacts/src/main/resources/messages.properties Mon Feb 06 07:39:59 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages.properties Mon Feb 06 08:36:26 2012 +0000 @@ -121,6 +121,11 @@ export.discharge.longitudinal.section.csv.header.cw = W corr. export.discharge.longitudinal.section.csv.header.q = Q [m\u00b3/s] export.discharge.curve.at.header = Computed Discharge Curve for {0} {0}-km: {1} +export.historical.discharge.csv.header.timerange = Timerange +export.historical.discharge.csv.header.waterlevel = Waterlevel +export.historical.discharge.csv.header.discharge = Discharge +export.historical.discharge.csv.header.diff = Difference +export.historical.discharge.csv.header.gaugename = Gaugename export.waterlevel.pdf.mode = Waterlevel export.computed.discharge.pdf.mode = Computed Dischargecurve diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/src/main/resources/messages_de.properties --- a/flys-artifacts/src/main/resources/messages_de.properties Mon Feb 06 07:39:59 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_de.properties Mon Feb 06 08:36:26 2012 +0000 @@ -121,6 +121,11 @@ export.discharge.longitudinal.section.csv.header.cw = W korr. export.discharge.longitudinal.section.csv.header.q = Q [m\u00b3/s] export.discharge.curve.at.header = Berechnete Abflusskurve f\u00fcr {0} {0}-km: {1} +export.historical.discharge.csv.header.timerange = Zeitraum +export.historical.discharge.csv.header.waterlevel = Wasserstand +export.historical.discharge.csv.header.discharge = Abfluss +export.historical.discharge.csv.header.diff = Abflussdifferenz zur Bezugskurve +export.historical.discharge.csv.header.gaugename = Pegelname export.waterlevel.pdf.mode = Wasserstand export.computed.discharge.pdf.mode = Abflusskurve diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/src/main/resources/messages_de_DE.properties --- a/flys-artifacts/src/main/resources/messages_de_DE.properties Mon Feb 06 07:39:59 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_de_DE.properties Mon Feb 06 08:36:26 2012 +0000 @@ -121,6 +121,11 @@ export.discharge.longitudinal.section.csv.header.cw = W korr. export.discharge.longitudinal.section.csv.header.q = Q [m\u00b3/s] export.discharge.curve.at.header = Berechnete Abflusskurve f\u00fcr {0} {0}-km: {1} +export.historical.discharge.csv.header.timerange = Zeitraum +export.historical.discharge.csv.header.waterlevel = Wasserstand +export.historical.discharge.csv.header.discharge = Abfluss +export.historical.discharge.csv.header.diff = Abflussdifferenz zur Bezugskurve +export.historical.discharge.csv.header.gaugename = Pegelname export.waterlevel.pdf.mode = Wasserstand export.computed.discharge.pdf.mode = Abflusskurve diff -r 86685feb5b1c -r ea173e4c07c7 flys-artifacts/src/main/resources/messages_en.properties --- a/flys-artifacts/src/main/resources/messages_en.properties Mon Feb 06 07:39:59 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_en.properties Mon Feb 06 08:36:26 2012 +0000 @@ -117,6 +117,11 @@ export.discharge.longitudinal.section.csv.header.cw = W corr. export.discharge.longitudinal.section.csv.header.q = Q [m\u00b3/s] export.discharge.curve.at.header = Computed Discharge Curve for {0} {0}-km: {1} +export.historical.discharge.csv.header.timerange = Timerange +export.historical.discharge.csv.header.waterlevel = Waterlevel +export.historical.discharge.csv.header.discharge = Discharge +export.historical.discharge.csv.header.diff = Difference +export.historical.discharge.csv.header.gaugename = Gaugename export.waterlevel.pdf.mode = Waterlevel export.computed.discharge.pdf.mode = Computed Dischargecurve