Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/FlowVelocityExporter.java @ 9312:740d65e4aa14
Q [m³/s] one message
author | gernotbelger |
---|---|
date | Thu, 26 Jul 2018 15:54:20 +0200 |
parents | 5e38e2924c07 |
children |
comparison
equal
deleted
inserted
replaced
9311:7c7f73e5e01e | 9312:740d65e4aa14 |
---|---|
12 import java.text.NumberFormat; | 12 import java.text.NumberFormat; |
13 import java.util.ArrayList; | 13 import java.util.ArrayList; |
14 import java.util.List; | 14 import java.util.List; |
15 | 15 |
16 import org.apache.log4j.Logger; | 16 import org.apache.log4j.Logger; |
17 | |
18 import au.com.bytecode.opencsv.CSVWriter; | |
19 | |
20 import org.dive4elements.river.artifacts.D4EArtifact; | 17 import org.dive4elements.river.artifacts.D4EArtifact; |
21 import org.dive4elements.river.artifacts.model.CalculationResult; | 18 import org.dive4elements.river.artifacts.model.CalculationResult; |
22 import org.dive4elements.river.artifacts.model.FlowVelocityData; | 19 import org.dive4elements.river.artifacts.model.FlowVelocityData; |
20 import org.dive4elements.river.utils.Formatter; | |
23 import org.dive4elements.river.utils.RiverUtils; | 21 import org.dive4elements.river.utils.RiverUtils; |
24 import org.dive4elements.river.utils.Formatter; | |
25 | 22 |
23 import au.com.bytecode.opencsv.CSVWriter; | |
26 | 24 |
27 /** | 25 /** |
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
29 */ | 27 */ |
30 public class FlowVelocityExporter extends AbstractExporter { | 28 public class FlowVelocityExporter extends AbstractExporter { |
31 | 29 |
32 private static final Logger log = | 30 private static final Logger log = Logger.getLogger(FlowVelocityExporter.class); |
33 Logger.getLogger(FlowVelocityExporter.class); | |
34 | 31 |
32 public static final String CSV_KM = "export.flow_velocity.csv.header.km"; | |
35 | 33 |
36 public static final String CSV_KM = | 34 public static final String CSV_V_TOTAL = "export.flow_velocity.csv.header.v_total"; |
37 "export.flow_velocity.csv.header.km"; | |
38 | 35 |
39 public static final String CSV_V_TOTAL = | 36 public static final String CSV_V_MAIN = "export.flow_velocity.csv.header.v_main"; |
40 "export.flow_velocity.csv.header.v_total"; | |
41 | 37 |
42 public static final String CSV_V_MAIN = | 38 public static final String CSV_TAU_MAIN = "export.flow_velocity.csv.header.tau_main"; |
43 "export.flow_velocity.csv.header.v_main"; | |
44 | 39 |
45 public static final String CSV_TAU_MAIN = | 40 public static final String CSV_Q = "common.export.csv.header.q"; |
46 "export.flow_velocity.csv.header.tau_main"; | |
47 | 41 |
48 public static final String CSV_Q = | 42 public static final String CSV_LOCATIONS = "export.flow_velocity.csv.header.locations"; |
49 "export.flow_velocity.csv.header.q"; | |
50 | |
51 public static final String CSV_LOCATIONS = | |
52 "export.flow_velocity.csv.header.locations"; | |
53 | |
54 | 43 |
55 protected List<FlowVelocityData[]> data; | 44 protected List<FlowVelocityData[]> data; |
56 | 45 |
57 public FlowVelocityExporter() { | 46 public FlowVelocityExporter() { |
58 data = new ArrayList<FlowVelocityData[]>(); | 47 this.data = new ArrayList<>(); |
59 } | 48 } |
60 | 49 |
61 @Override | 50 @Override |
62 protected void addData(Object d) { | 51 protected void addData(Object d) { |
63 if (d instanceof CalculationResult) { | 52 if (d instanceof CalculationResult) { |
64 d = ((CalculationResult) d).getData(); | 53 d = ((CalculationResult) d).getData(); |
65 | 54 |
66 if (d instanceof FlowVelocityData[]) { | 55 if (d instanceof FlowVelocityData[]) { |
67 log.debug("Add new data of type FlowVelocityData"); | 56 log.debug("Add new data of type FlowVelocityData"); |
68 data.add((FlowVelocityData[]) d); | 57 this.data.add((FlowVelocityData[]) d); |
69 } | 58 } |
70 } | 59 } |
71 } | 60 } |
72 | 61 |
73 | |
74 @Override | 62 @Override |
75 protected void writeCSVData(CSVWriter writer) { | 63 protected void writeCSVData(final CSVWriter writer) { |
76 log.info("FlowVelocityExporter.writeCSVData"); | 64 log.info("FlowVelocityExporter.writeCSVData"); |
77 log.debug("CSV gets " + data.size() + " FlowVelocityData objects."); | 65 log.debug("CSV gets " + this.data.size() + " FlowVelocityData objects."); |
78 | 66 |
79 writeCSVHeader(writer); | 67 writeCSVHeader(writer); |
80 | 68 |
81 for (FlowVelocityData[] d: data) { | 69 for (final FlowVelocityData[] d : this.data) { |
82 data2CSV(writer, d); | 70 data2CSV(writer, d); |
83 } | 71 } |
84 } | 72 } |
85 | 73 |
86 | 74 protected void writeCSVHeader(final CSVWriter writer) { |
87 protected void writeCSVHeader(CSVWriter writer) { | 75 writer.writeNext(new String[] { msg(CSV_KM, CSV_KM), msg(CSV_V_MAIN, CSV_V_MAIN), msg(CSV_V_TOTAL, CSV_V_TOTAL), msg(CSV_TAU_MAIN, CSV_TAU_MAIN), |
88 writer.writeNext(new String[] { | 76 msg(CSV_Q, CSV_Q), msg(CSV_LOCATIONS, CSV_LOCATIONS) }); |
89 msg(CSV_KM, CSV_KM), | |
90 msg(CSV_V_MAIN, CSV_V_MAIN), | |
91 msg(CSV_V_TOTAL, CSV_V_TOTAL), | |
92 msg(CSV_TAU_MAIN, CSV_TAU_MAIN), | |
93 msg(CSV_Q, CSV_Q), | |
94 msg(CSV_LOCATIONS, CSV_LOCATIONS) | |
95 }); | |
96 } | 77 } |
97 | 78 |
98 | 79 protected void data2CSV(final CSVWriter writer, final FlowVelocityData[] fData) { |
99 protected void data2CSV(CSVWriter writer, FlowVelocityData[] fData) { | |
100 log.debug("Add next FlowVelocityData to CSV"); | 80 log.debug("Add next FlowVelocityData to CSV"); |
101 | 81 |
102 D4EArtifact flys = (D4EArtifact) master; | 82 final D4EArtifact flys = (D4EArtifact) this.master; |
103 | 83 |
104 for (FlowVelocityData data: fData) { | 84 for (final FlowVelocityData data : fData) { |
105 for (int i = 0, n = data.size(); i < n; i++) { | 85 for (int i = 0, n = data.size(); i < n; i++) { |
106 NumberFormat kmF = Formatter.getFlowVelocityKM(context); | 86 final NumberFormat kmF = Formatter.getFlowVelocityKM(this.context); |
107 NumberFormat valF = Formatter.getFlowVelocityValues(context); | 87 final NumberFormat valF = Formatter.getFlowVelocityValues(this.context); |
108 NumberFormat qF = Formatter.getFlowVelocityQ(context); | 88 final NumberFormat qF = Formatter.getFlowVelocityQ(this.context); |
109 | 89 |
110 String vMain = ""; | 90 String vMain = ""; |
111 String vTotal = ""; | 91 String vTotal = ""; |
112 | 92 |
113 if (data.getType().equals("main") | 93 if (data.getType().equals("main") || data.getType().equals("main_total")) { |
114 || data.getType().equals("main_total") | |
115 ) { | |
116 vMain = valF.format(data.getVMain(i)); | 94 vMain = valF.format(data.getVMain(i)); |
117 } | 95 } |
118 if (data.getType().equals("total") | 96 if (data.getType().equals("total") || data.getType().equals("main_total")) { |
119 || data.getType().equals("main_total") | |
120 ) { | |
121 vTotal = valF.format(data.getVTotal(i)); | 97 vTotal = valF.format(data.getVTotal(i)); |
122 } | 98 } |
123 writer.writeNext(new String[] { | 99 writer.writeNext(new String[] { kmF.format(data.getKM(i)), vMain, vTotal, valF.format(data.getTauMain(i)), |
124 kmF.format(data.getKM(i)), | 100 qF.format(data.getQ(i)) + "=" + data.getZone(), RiverUtils.getLocationDescription(flys, data.getKM(i)), }); |
125 vMain, | |
126 vTotal, | |
127 valF.format(data.getTauMain(i)), | |
128 qF.format(data.getQ(i)) + "=" + data.getZone(), | |
129 RiverUtils.getLocationDescription(flys, data.getKM(i)), | |
130 }); | |
131 } | 101 } |
132 } | 102 } |
133 } | 103 } |
134 | 104 |
135 | |
136 @Override | 105 @Override |
137 protected void writePDF(OutputStream out) { | 106 protected void writePDF(final OutputStream out) { |
138 log.error("TODO: Implement FlowVelocityExporter.writePDF"); | 107 log.error("TODO: Implement FlowVelocityExporter.writePDF"); |
139 } | 108 } |
140 } | 109 } |
141 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 110 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |