Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveExporter.java @ 1106:e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
flys-artifacts/trunk@2609 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 30 Aug 2011 11:09:54 +0000 |
parents | 3b7e9ddf6bb1 |
children | efe1b8545f5c |
line wrap: on
line source
package de.intevation.flys.exports; import java.io.OutputStream; import java.text.NumberFormat; import java.util.ArrayList; 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.flys.artifacts.model.WQDay; import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.utils.Formatter; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class DurationCurveExporter extends AbstractExporter { /** The logger used in this exporter.*/ private static Logger logger = Logger.getLogger(WaterlevelExporter.class); public static final String CSV_DURATION_HEADER = "export.duration.curve.csv.header.duration"; public static final String CSV_W_HEADER = "export.duration.curve.csv.header.w"; public static final String CSV_Q_HEADER = "export.duration.curve.csv.header.q"; public static final String DEFAULT_CSV_DURATION_HEADER = "D [Tagen]"; public static final String DEFAULT_CSV_W_HEADER = "W [NN + m]"; public static final String DEFAULT_CSV_Q_HEADER = "Q [m\u00b3/s]"; /** The storage that contains all WQKms objects for the different facets.*/ protected List<WQDay> data; public void init(Document request, OutputStream out, CallContext context) { logger.debug("DurationCurveExporter.init"); super.init(request, out, context); this.data = new ArrayList<WQDay>(); } @Override protected void addData(Object d) { if (d instanceof CalculationResult) { d = ((CalculationResult)d).getData(); if (d instanceof WQDay) { data.add((WQDay)d); } } } protected void writeCSVData(CSVWriter writer) { logger.info("DurationCurveExporter.writeData"); writeCSVHeader(writer); for (WQDay wqday: data) { wQDay2CSV(writer, wqday); } } protected void writeCSVHeader(CSVWriter writer) { logger.info("DurationCurveExporter.writeCSVHeader"); writer.writeNext(new String[] { msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER), msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER), msg(CSV_DURATION_HEADER, DEFAULT_CSV_DURATION_HEADER) }); } protected void wQDay2CSV(CSVWriter writer, WQDay wqday) { logger.debug("DurationCurveExporter.wQDay2CSV"); int size = wqday.size(); NumberFormat wf = getWFormatter(); NumberFormat qf = getQFormatter(); NumberFormat df = getDFormatter(); for (int i = 0; i < size; i ++) { writer.writeNext(new String[] { wf.format(wqday.getW(i)), qf.format(wqday.getQ(i)), df.format(wqday.getDay(i)) }); } } /** * Returns the number formatter for W values. * * @return the number formatter for W values. */ protected NumberFormat getWFormatter() { return Formatter.getDurationW(context); } /** * Returns the number formatter for Q values. * * @return the number formatter for Q values. */ protected NumberFormat getQFormatter() { return Formatter.getDurationQ(context); } /** * Returns the number formatter for duration values. * * @return the number formatter for duration values. */ protected NumberFormat getDFormatter() { return Formatter.getDurationD(context); } }