Mercurial > dive4elements > river
changeset 2787:e63969c173e9
FixA: Added CSV export for Delta W/t values.
flys-artifacts/trunk@4526 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 26 May 2012 21:26:10 +0000 |
parents | f9e62e76ee1f |
children | 063b784b60b4 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java |
diffstat | 5 files changed, 223 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Sat May 26 20:13:00 2012 +0000 +++ b/flys-artifacts/ChangeLog Sat May 26 21:26:10 2012 +0000 @@ -1,3 +1,17 @@ +2012-05-26 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java: + Added getters to access the inner data structures. + + * src/main/java/de/intevation/flys/utils/Formatter.java: Added formatting + support for delta w/t exports of fix analysis. + + * src/main/java/de/intevation/flys/exports/DeltaWtExporter.java: + New. CSV exporter for delta w/ts of fix analysis. + + * src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java: + Reordered imports. + 2012-05-26 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/fixings/FitResult.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java Sat May 26 20:13:00 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java Sat May 26 21:26:10 2012 +0000 @@ -79,5 +79,9 @@ int idx = Collections.binarySearch(kms, new KM(km)); return idx >= 0 ? kms.get(idx) : null; } + + public List<KM> getKms() { + return kms; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java Sat May 26 21:26:10 2012 +0000 @@ -0,0 +1,161 @@ +package de.intevation.flys.exports; + +import au.com.bytecode.opencsv.CSVWriter; + +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; + +import de.intevation.flys.artifacts.model.CalculationResult; + +import de.intevation.flys.artifacts.model.fixings.DeltaWT; +import de.intevation.flys.artifacts.model.fixings.DeltaWTsKM; +import de.intevation.flys.artifacts.model.fixings.FixResult; + +import de.intevation.flys.artifacts.resources.Resources; + +import de.intevation.flys.utils.Formatter; + +import java.io.IOException; +import java.io.OutputStream; + +import java.text.DateFormat; +import java.text.NumberFormat; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; + +public class DeltaWtExporter +extends AbstractExporter +{ + private static Logger log = Logger.getLogger(DeltaWtExporter.class); + + public static final String CSV_KM_HEADER = + "export.fixings.deltawt.csv.header.km"; + + public static final String CSV_DELTA_W_HEADER = + "export.fixings.deltawt.csv.header.deltaw"; + + public static final String CSV_T_HEADER = + "export.fixings.deltawt.csv.header.t"; + + public static final String CSV_T_DESC_HEADER = + "export.fixings.deltawt.csv.header.description"; + + public static final String DEFAULT_CSV_KM_HEADER = "km"; + + public static final String DEFAULT_CSV_DELTA_W_HEADER = "\u0394 W"; + + public static final String DEFAULT_CSV_T_HEADER = "Datum"; + + public static final String DEFAULT_CSV_T_DESC_HEADER = "Beschreibung"; + + protected List<DeltaWTsKM> deltaWTsKMs; + + @Override + public void init(Document request, OutputStream out, CallContext context) { + log.debug("DeltaWtExporter.init"); + super.init(request, out, context); + deltaWTsKMs = new ArrayList<DeltaWTsKM>(); + } + + @Override + public void generate() throws IOException { + log.debug("DeltaWtExporter.generate"); + if (facet == null) { + throw new IOException("invalid (null) facet for exporter"); + } + else if (facet.equals(FACET_CSV)) { + generateCSV(); + } + else if (facet.equals(FACET_PDF)) { + generatePDF(); + } + else { + throw new IOException("invalid facet (" + facet + ") for exporter"); + } + } + + @Override + protected void addData(Object d) { + log.debug("DeltaWtExporter.addData"); + if (!(d instanceof CalculationResult)) { + log.warn("Invalid data type"); + return; + } + + Object data = ((CalculationResult)d).getData(); + if (!(data instanceof FixResult)) { + log.warn("Invalid data stored in result."); + } + FixResult result = (FixResult)data; + deltaWTsKMs.add(result.getDeltaWTsKM()); + } + + @Override + protected void writeCSVData(CSVWriter writer) { + + writeCSVHeader(writer); + + NumberFormat kmF = getKMFormatter(); + NumberFormat dwF = getDeltaWFormatter(); + + CallMeta meta = context.getMeta(); + Locale locale = Resources.getLocale(meta); + DateFormat dF = DateFormat.getDateInstance(DateFormat.SHORT, locale); + + for (DeltaWTsKM deltaWTsKM: deltaWTsKMs) { + List<DeltaWTsKM.KM> dkms = deltaWTsKM.getKms(); + for (DeltaWTsKM.KM dkm: dkms) { + double km = dkm.getKm(); + String kmS = kmF.format(km); + List<DeltaWT> deltaWTs = dkm.getDeltaWTs(); + for (DeltaWT dwt: deltaWTs) { + double deltaW = dwt.getDeltaW(); + Date date = dwt.getDate(); + String desc = dwt.getDescription(); + + String deltaWS = dwF.format(deltaW); + String dateS = dF.format(date); + + writer.writeNext(new String[] { + kmS, + deltaWS, + dateS, + desc != null ? desc : "" }); + } + } + } + } + + + protected NumberFormat getKMFormatter() { + return Formatter.getFixDeltaWKM(context); + } + + protected NumberFormat getDeltaWFormatter() { + return Formatter.getFixDeltaWDeltaW(context); + } + + protected void writeCSVHeader(CSVWriter writer) { + log.debug("DeltaWtExporter.writeCSVHeader"); + + writer.writeNext(new String[] { + msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), + msg(CSV_DELTA_W_HEADER, DEFAULT_CSV_DELTA_W_HEADER), + msg(CSV_T_HEADER, DEFAULT_CSV_T_HEADER), + msg(CSV_T_DESC_HEADER, DEFAULT_CSV_T_DESC_HEADER) + }); + } + + @Override + protected void writePDF(OutputStream out) { + // TODO: Implement me! + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java Sat May 26 20:13:00 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java Sat May 26 21:26:10 2012 +0000 @@ -1,30 +1,10 @@ package de.intevation.flys.exports; -import java.io.IOException; -import java.io.OutputStream; -import java.text.NumberFormat; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.HashMap; - -import java.text.DateFormat; - -import org.w3c.dom.Document; - -import org.apache.log4j.Logger; - import au.com.bytecode.opencsv.CSVWriter; -import net.sf.jasperreports.engine.JasperExportManager; -import net.sf.jasperreports.engine.JasperFillManager; -import net.sf.jasperreports.engine.JasperPrint; -import net.sf.jasperreports.engine.JRException; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.CallMeta; + import de.intevation.artifacts.common.utils.Config; import de.intevation.flys.artifacts.FLYSArtifact; @@ -33,10 +13,32 @@ import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.WWQQ; import de.intevation.flys.artifacts.model.WWQQJRDataSource; + import de.intevation.flys.artifacts.resources.Resources; import de.intevation.flys.utils.FLYSUtils; +import java.io.IOException; +import java.io.OutputStream; + +import java.text.DateFormat; +import java.text.NumberFormat; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; /** * (CSV)Exporter for Reference Curves. @@ -82,6 +84,7 @@ protected boolean endAtGauge = false; + @Override public void init(Document request, OutputStream out, CallContext context) { logger.debug("ReferenceCurveExporter.init"); @@ -157,7 +160,7 @@ */ @Override protected void writeCSVData(CSVWriter writer) { - logger.info("ReferenceCurveExporter.writeData"); + logger.debug("ReferenceCurveExporter.writeData"); writeCSVHeader(writer);
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Sat May 26 20:13:00 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Sat May 26 21:26:10 2012 +0000 @@ -71,6 +71,11 @@ public static final int MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS = 3; public static final int MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS = 3; + public static final int FIX_DELTA_W_KM_MIN_DIGITS = 3; + public static final int FIX_DELTA_W_KM_MAX_DIGITS = 3; + public static final int FIX_DELTA_W_DELTA_W_MIN_DIGITS = 3; + public static final int FIX_DELTA_W_DELTA_W_MAX_DIGITS = 3; + public static NumberFormat getFormatter(CallMeta m, int min, int max){ Locale locale = Resources.getLocale(m); NumberFormat nf = NumberFormat.getInstance(locale); @@ -328,5 +333,19 @@ MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS, MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS); } + + public static NumberFormat getFixDeltaWKM(CallContext context) { + return getFormatter( + context, + FIX_DELTA_W_KM_MIN_DIGITS, + FIX_DELTA_W_KM_MAX_DIGITS); + } + + public static NumberFormat getFixDeltaWDeltaW(CallContext context) { + return getFormatter( + context, + FIX_DELTA_W_DELTA_W_MIN_DIGITS, + FIX_DELTA_W_DELTA_W_MAX_DIGITS); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :