Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java @ 2046:2ae0627f956e
Improved ChartSettings and depending classes to avoid a lot of casting.
flys-artifacts/trunk@3534 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 23 Dec 2011 08:51:28 +0000 |
parents | c09c9e05ecfa |
children | 2f5628f0de0e |
line wrap: on
line source
package de.intevation.flys.exports; import java.text.NumberFormat; import org.apache.log4j.Logger; import au.com.bytecode.opencsv.CSVWriter; import de.intevation.flys.artifacts.model.WQCKms; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.artifacts.model.CalculationResult; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class DischargeLongitudinalSectionExporter extends WaterlevelExporter { /** The logger used in this exporter.*/ private static Logger logger = Logger.getLogger(DischargeLongitudinalSectionExporter.class); public static final String CSV_KM_HEADER = "export.discharge.longitudinal.section.csv.header.km"; public static final String CSV_W_HEADER = "export.discharge.longitudinal.section.csv.header.w"; public static final String CSV_CW_HEADER = "export.discharge.longitudinal.section.csv.header.cw"; public static final String CSV_Q_HEADER = "export.discharge.longitudinal.section.csv.header.q"; public static final String DEFAULT_CSV_KM_HEADER = "Fluss-Km"; public static final String DEFAULT_CSV_W_HEADER = "W [NN + m]"; public static final String DEFAULT_CSV_CW_HEADER = "W korr."; public static final String DEFAULT_CSV_Q_HEADER = "Q [m\u00b3/s]"; @Override protected void addData(Object d) { if (d instanceof CalculationResult) { d = ((CalculationResult)d).getData(); if (d instanceof WQKms []) { data.add((WQKms [])d); } } } @Override protected void writeCSVHeader(CSVWriter writer) { logger.info("WaterlevelExporter.writeCSVHeader"); writer.writeNext(new String[] { msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER), msg(CSV_CW_HEADER, DEFAULT_CSV_CW_HEADER), msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER) }); } @Override protected void wQKms2CSV(CSVWriter writer, WQKms wqkms) { logger.debug("WaterlevelExporter.wQKms2CSV"); int size = wqkms.size(); double[] result = new double[4]; NumberFormat kmf = getKmFormatter(); NumberFormat wf = getWFormatter(); NumberFormat qf = getQFormatter(); for (int i = 0; i < size; i ++) { result = wqkms.get(i, result); String wc = ""; if (wqkms instanceof WQCKms) { wc = wf.format(result[3]); } writer.writeNext(new String[] { kmf.format(result[2]), wf.format(result[0]), wc, qf.format(result[1]) }); } } @Override protected void addWSTColumn(WstWriter writer, WQKms wqkms) { String name = wqkms.getName(); // is it a W or a Q mode? int wIdx = name.indexOf("W"); int qIdx = name.indexOf("Q"); String wq = null; if (wIdx >= 0) { wq = "W"; } else if (qIdx >= 0) { wq = "Q"; } // we just want to display the first W or Q value in the WST int start = name.indexOf("("); int end = name.indexOf(")"); String tmp = name.substring(start+1, end); String[] values = tmp.split(";"); String column = wq + "=" + values[0]; writer.addColumn(column); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :