Mercurial > dive4elements > river
changeset 2258:ea173e4c07c7
Added a CSV export for historical discharge curves.
flys-artifacts/trunk@3913 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 06 Feb 2012 08:36:26 +0000 (2012-02-06) |
parents | 86685feb5b1c |
children | 0dcb8326be08 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/HistoricalDischargeComputeState.java flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveExporter.java flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties |
diffstat | 10 files changed, 247 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 <ingo@intevation.de> + + * 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 <felix.wolfsteller@intevation.de> * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
--- 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 @@ <facet name="historical_discharge.historicalq"/> </facets> </outputmode> + <outputmode name="historical_discharge_export" description="output.w_differences.export" mime-type="text/plain" type="export"> + <facets> + <facet name="csv" description="facet.historical_discharge.csv" /> + </facets> + </outputmode> <outputmode name="historical_discharge_report" description="output.historical_discharge_report" mime-type="text/xml" type="report"> <facets> <facet name="report" description="facet.historical_discharge.report"/>
--- 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 @@ <output-generator name="reference_curve">de.intevation.flys.exports.ReferenceCurveGenerator</output-generator> <output-generator name="reference_curve_chartinfo">de.intevation.flys.exports.ReferenceCurveInfoGenerator</output-generator> <output-generator name="historical_discharge">de.intevation.flys.exports.HistoricalDischargeCurveGenerator</output-generator> + <output-generator name="historical_discharge_export">de.intevation.flys.exports.HistoricalDischargeCurveExporter</output-generator> <!-- Error report generators. --> <output-generator name="discharge_longitudinal_section_report">de.intevation.flys.exports.ReportGenerator</output-generator> <output-generator name="waterlevel_report">de.intevation.flys.exports.ReportGenerator</output-generator>
--- 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;
--- /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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +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<WQTimerange[]> data; + + + public void init(Document request, OutputStream out, CallContext cc) { + super.init(request, out, cc); + + data = new ArrayList<WQTimerange[]>(); + } + + + @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 :
--- 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.
--- 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
--- 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
--- 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
--- 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