Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/exports/FlowVelocityExporter.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/exports/FlowVelocityExporter.java@aa4391648a05 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.exports; | |
2 | |
3 import java.io.OutputStream; | |
4 import java.text.NumberFormat; | |
5 import java.util.ArrayList; | |
6 import java.util.List; | |
7 | |
8 import org.w3c.dom.Document; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 | |
12 import au.com.bytecode.opencsv.CSVWriter; | |
13 | |
14 import org.dive4elements.artifacts.CallContext; | |
15 | |
16 import org.dive4elements.river.artifacts.FLYSArtifact; | |
17 import org.dive4elements.river.artifacts.model.CalculationResult; | |
18 import org.dive4elements.river.artifacts.model.FlowVelocityData; | |
19 import org.dive4elements.river.utils.FLYSUtils; | |
20 import org.dive4elements.river.utils.Formatter; | |
21 | |
22 | |
23 /** | |
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
25 */ | |
26 public class FlowVelocityExporter extends AbstractExporter { | |
27 | |
28 private static final Logger logger = | |
29 Logger.getLogger(FlowVelocityExporter.class); | |
30 | |
31 | |
32 public static final String CSV_KM = | |
33 "export.flow_velocity.csv.header.km"; | |
34 | |
35 public static final String CSV_V_TOTAL = | |
36 "export.flow_velocity.csv.header.v_total"; | |
37 | |
38 public static final String CSV_V_MAIN = | |
39 "export.flow_velocity.csv.header.v_main"; | |
40 | |
41 public static final String CSV_TAU_MAIN = | |
42 "export.flow_velocity.csv.header.tau_main"; | |
43 | |
44 public static final String CSV_Q = | |
45 "export.flow_velocity.csv.header.q"; | |
46 | |
47 public static final String CSV_LOCATIONS = | |
48 "export.flow_velocity.csv.header.locations"; | |
49 | |
50 | |
51 protected List<FlowVelocityData[]> data; | |
52 | |
53 | |
54 public void init(Document request, OutputStream out, CallContext cc) { | |
55 super.init(request, out, cc); | |
56 data = new ArrayList<FlowVelocityData[]>(); | |
57 } | |
58 | |
59 | |
60 @Override | |
61 protected void addData(Object d) { | |
62 if (d instanceof CalculationResult) { | |
63 d = ((CalculationResult) d).getData(); | |
64 | |
65 if (d instanceof FlowVelocityData[]) { | |
66 logger.debug("Add new data of type FlowVelocityData"); | |
67 data.add((FlowVelocityData[]) d); | |
68 } | |
69 } | |
70 } | |
71 | |
72 | |
73 @Override | |
74 protected void writeCSVData(CSVWriter writer) { | |
75 logger.info("FlowVelocityExporter.writeCSVData"); | |
76 logger.debug("CSV gets " + data.size() + " FlowVelocityData objects."); | |
77 | |
78 writeCSVHeader(writer); | |
79 | |
80 for (FlowVelocityData[] d: data) { | |
81 data2CSV(writer, d); | |
82 } | |
83 } | |
84 | |
85 | |
86 protected void writeCSVHeader(CSVWriter writer) { | |
87 writer.writeNext(new String[] { | |
88 msg(CSV_KM, CSV_KM), | |
89 msg(CSV_V_TOTAL, CSV_V_TOTAL), | |
90 msg(CSV_V_MAIN, CSV_V_MAIN), | |
91 msg(CSV_TAU_MAIN, CSV_TAU_MAIN), | |
92 msg(CSV_Q, CSV_Q), | |
93 msg(CSV_LOCATIONS, CSV_LOCATIONS) | |
94 }); | |
95 } | |
96 | |
97 | |
98 protected void data2CSV(CSVWriter writer, FlowVelocityData[] fData) { | |
99 logger.debug("Add next FlowVelocityData to CSV"); | |
100 | |
101 FLYSArtifact flys = (FLYSArtifact) master; | |
102 | |
103 for (FlowVelocityData data: fData) { | |
104 for (int i = 0, n = data.size(); i < n; i++) { | |
105 NumberFormat kmF = Formatter.getFlowVelocityKM(context); | |
106 NumberFormat valF = Formatter.getFlowVelocityValues(context); | |
107 NumberFormat qF = Formatter.getFlowVelocityQ(context); | |
108 | |
109 writer.writeNext(new String[] { | |
110 kmF.format(data.getKM(i)), | |
111 valF.format(data.getVMain(i)), | |
112 valF.format(data.getVTotal(i)), | |
113 valF.format(data.getTauMain(i)), | |
114 qF.format(data.getQ(i)) + "=" + data.getZone(), | |
115 FLYSUtils.getLocationDescription(flys, data.getKM(i)), | |
116 }); | |
117 } | |
118 } | |
119 } | |
120 | |
121 | |
122 @Override | |
123 protected void writePDF(OutputStream out) { | |
124 logger.error("TODO: Implement FlowVelocityExporter.writePDF"); | |
125 } | |
126 } | |
127 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |