Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/sq/SQRelationExporter.java @ 4789:0df2247d98e1
Create and add sieves regardless of the the order of diameter/value.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 09 Jan 2013 09:28:01 +0100 |
parents | 1df6984628c3 |
children |
line wrap: on
line source
package de.intevation.flys.exports.sq; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Document; import au.com.bytecode.opencsv.CSVWriter; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.sq.SQFractionResult; import de.intevation.flys.artifacts.model.sq.SQResult; import de.intevation.flys.artifacts.model.Parameters; import de.intevation.flys.exports.AbstractExporter; import org.apache.log4j.Logger; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class SQRelationExporter extends AbstractExporter { /** Private logger. */ private static final Logger logger = Logger.getLogger(SQRelationExporter.class); public static final String CSV_PARAMETER = "export.sqrelation.csv.header.parameter"; public static final String CSV_STATION = "export.sqrelation.csv.header.station"; public static final String CSV_KM = "export.sqrelation.csv.header.km"; public static final String CSV_FUNCTION = "export.sqrelation.csv.header.function"; public static final String CSV_GAUGE = "export.sqrelation.csv.header.gauge"; public static final String CSV_COEFF_A = "export.sqrelation.csv.header.coeff.a"; public static final String CSV_COEFF_B = "export.sqrelation.csv.header.coeff.b"; public static final String CSV_COEFF_Q = "export.sqrelation.csv.header.coeff.q"; public static final String CSV_COEFF_R = "export.sqrelation.csv.header.coeff.r"; public static final String CSV_N_TOTAL = "export.sqrelation.csv.header.n.total"; public static final String CSV_N_OUTLIERS = "export.sqrelation.csv.header.n.outliers"; public static final String CSV_C_DUAN = "export.sqrelation.csv.header.c.duan"; public static final String CSV_C_FERGUSON = "export.sqrelation.csv.header.c.ferguson"; public static final String CSV_VARIANCE = "export.sqrelation.csv.header.variance"; protected List<SQResult []> data; public void init(Document request, OutputStream out, CallContext cc) { super.init(request, out, cc); data = new ArrayList<SQResult []>(); } @Override protected void addData(Object d) { if (d instanceof CalculationResult) { d = ((CalculationResult)d).getData(); if (d instanceof SQResult []) { data.add((SQResult [])d); } } } protected void writeCSVHeader(CSVWriter writer) { writer.writeNext(new String[] { msg(CSV_KM , CSV_KM), msg(CSV_PARAMETER, CSV_PARAMETER), msg(CSV_COEFF_A , CSV_COEFF_A), msg(CSV_COEFF_B , CSV_COEFF_B), msg(CSV_N_TOTAL , CSV_N_TOTAL), msg(CSV_N_OUTLIERS, CSV_N_OUTLIERS), msg(CSV_VARIANCE , CSV_VARIANCE) }); } @Override protected void writeCSVData(CSVWriter writer) { logger.debug("writeCSVData"); writeCSVHeader(writer); for (SQResult [] results: data) { for (SQResult result: results) { data2CSV(writer, result); } } } protected void data2CSV(CSVWriter writer, SQResult result) { logger.debug("data2CSV"); // TODO: i18n String km = String.valueOf(result.getKm()); for (int i = 0; i < SQResult.NUMBER_FRACTIONS; ++i) { SQFractionResult fraction = result.getFraction(i); String name = result.getFractionName(i); Parameters parameters = fraction.getParameters(); if (parameters == null) { continue; } double a = parameters.getValue(0, "a"); double b = parameters.getValue(0, "b"); double sd = Math.sqrt(parameters.getValue(0, "std_dev")); int o = fraction.totalNumOutliers(); int t = fraction.numMeasurements() + o; writer.writeNext(new String[] { km, name, String.valueOf(a), String.valueOf(b), String.valueOf(t), String.valueOf(o), String.valueOf(sd) }); } } @Override protected void writePDF(OutputStream out) { logger.debug("writePDF"); logger.error("NOT IMPLEMENTED: writePDF"); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :