Mercurial > dive4elements > river
changeset 3599:659c1111db13
FixA: Added exporter for AT files.
flys-artifacts/trunk@5224 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 17 Aug 2012 11:25:37 +0000 |
parents | a1cdf8be9fd0 |
children | b5b3e73143a6 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/fixanalysis.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixATExport.java |
diffstat | 5 files changed, 121 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Aug 16 14:14:30 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Aug 17 11:25:37 2012 +0000 @@ -1,3 +1,17 @@ +2012-08-17 Raimund Renkert <raimund.renkert@intevation.de> + + * src/main/java/de/intevation/flys/exports/fixings/FixATExport.java: + New. Exporter for FixAnaylsis AT files. + + * src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java: + Add facet for AT export. + + * doc/conf/conf.xml: + Added out generator for fix AT export. + + * doc/conf/artifacts/fixanalysis.xml: + Added outputmode for AT export. + 2012-08-16 Felix Wolfsteller <felix.wolfsteller@intevation.de> * doc/conf/artifacts/fixanalysis.xml: Add more facets to
--- a/flys-artifacts/doc/conf/artifacts/fixanalysis.xml Thu Aug 16 14:14:30 2012 +0000 +++ b/flys-artifacts/doc/conf/artifacts/fixanalysis.xml Fri Aug 17 11:25:37 2012 +0000 @@ -134,6 +134,11 @@ <facet name="fix_parameters" description="facet.fix_parameters.csv" /> </facets> </outputmode> + <outputmode name="fix_wq_curve_at_export" description="output.fix_wq_curve_at_export" mime-type="text/plain" type="export"> + <facets> + <facet name="at" description="facet.fix_wq_curve_export.at"/> + </facets> + </outputmode> <outputmode name="fix_wq_curve" description="output.fix_wq_curve" mine-type="image/png" type="chart"> <facets> <facet name="fix_sector_average_wq_0" description="Average values for Ws in Q sectors."/>
--- a/flys-artifacts/doc/conf/conf.xml Thu Aug 16 14:14:30 2012 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Fri Aug 17 11:25:37 2012 +0000 @@ -296,6 +296,7 @@ <output-generator name="fix_report">de.intevation.flys.exports.ReportGenerator</output-generator> <!-- AT exporter. --> <output-generator name="computed_dischargecurve_at_export">de.intevation.flys.exports.ATExporter</output-generator> + <output-generator name="fix_wq_curve_at_export">de.intevation.flys.exports.fixings.FixATExport</output-generator> </output-generators> <!-- Path to the template file of the meta data. -->
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java Thu Aug 16 14:14:30 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java Fri Aug 17 11:25:37 2012 +0000 @@ -119,6 +119,8 @@ facets.add( new DataFacet( FIX_PARAMETERS, "parameters", ComputeType.ADVANCE, hash, id)); + facets.add( + new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, id)); int maxId = -100;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixATExport.java Fri Aug 17 11:25:37 2012 +0000 @@ -0,0 +1,99 @@ +package de.intevation.flys.exports.fixings; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import au.com.bytecode.opencsv.CSVWriter; + +import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Settings; +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.access.FixAccess; +import de.intevation.flys.artifacts.math.fitting.Function; +import de.intevation.flys.artifacts.math.fitting.FunctionFactory; +import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.Parameters; +import de.intevation.flys.artifacts.model.fixings.FixAnalysisResult; +import de.intevation.flys.collections.FLYSArtifactCollection; +import de.intevation.flys.exports.AbstractExporter; +import de.intevation.flys.exports.OutGenerator; +import de.intevation.flys.utils.FLYSUtils; + +public class FixATExport extends AbstractExporter { + + private static Logger logger = + Logger.getLogger(FixATExport.class); + + protected Function function; + protected Parameters parameters; + + + @Override + public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) { + logger.debug("AT Export doOut()."); + Object data = bundle.getData(context); + if (data instanceof CalculationResult) { + CalculationResult cr = (CalculationResult)data; + Object resData = cr.getData(); + if (resData instanceof FixAnalysisResult) { + this.parameters = ((FixAnalysisResult)resData).getParameters(); + } + } + else { + logger.debug("No CalculationResult found for AT export."); + return; + } + FixAccess access = new FixAccess((FLYSArtifact)this.master); + String f = access.getFunction(); + if (f == null || f.length() == 0) { + logger.debug("No function found for AT export."); + return; + } + this.function = FunctionFactory.getInstance().getFunction(f); + } + + @Override + public void generate() throws IOException { + if (this.function == null || this.parameters == null) { + logger.debug("No function or paramters for AT export."); + return; + } + + Writer writer = new OutputStreamWriter(out, DEFAULT_CSV_CHARSET); + + FixATWriter atWriter = new FixATWriter(this.function, this.parameters); + logger.debug("the request: " + XMLUtils.toString(request)); + NodeList nodes = request.getElementsByTagName("km"); + String km = nodes.item(0).getTextContent(); + logger.debug("the km: " + km); + double dkm = Double.valueOf(km); + String river = FLYSUtils.getRivername((FLYSArtifact)master); + atWriter.write(writer, context.getMeta(), river, dkm); + writer.close(); + } + + @Override + protected void writeCSVData(CSVWriter writer) throws IOException { + // The concrete writer is used to write csv data. + } + + @Override + protected void writePDF(OutputStream out) { + // Implement me! + } + + @Override + protected void addData(Object data) { + // Nothing to do here. + } + +}