Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/sq/SQRelationExporter.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 |
---|---|
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.exports.sq; | 9 package org.dive4elements.river.exports.sq; |
10 | 10 |
11 import java.io.OutputStream; | 11 import java.io.OutputStream; |
12 import java.util.ArrayList; | |
13 import java.util.List; | |
14 import java.util.Map; | |
15 import java.util.HashMap; | |
16 import java.util.Date; | |
17 import java.util.Locale; | |
18 import java.text.DateFormat; | 12 import java.text.DateFormat; |
19 import java.text.NumberFormat; | 13 import java.text.NumberFormat; |
20 | 14 import java.util.ArrayList; |
15 import java.util.Date; | |
16 import java.util.HashMap; | |
17 import java.util.List; | |
18 import java.util.Locale; | |
19 import java.util.Map; | |
20 | |
21 import org.apache.log4j.Logger; | |
22 import org.dive4elements.artifacts.CallMeta; | |
23 import org.dive4elements.artifacts.common.utils.Config; | |
24 import org.dive4elements.river.artifacts.D4EArtifact; | |
25 import org.dive4elements.river.artifacts.access.SQRelationAccess; | |
26 import org.dive4elements.river.artifacts.model.CalculationResult; | |
27 import org.dive4elements.river.artifacts.model.DateRange; | |
28 import org.dive4elements.river.artifacts.model.Parameters; | |
29 import org.dive4elements.river.artifacts.model.sq.SQ; | |
30 import org.dive4elements.river.artifacts.model.sq.SQFractionResult; | |
31 import org.dive4elements.river.artifacts.model.sq.SQMeasurementsJRDataSource; | |
32 import org.dive4elements.river.artifacts.model.sq.SQRelationJRDataSource; | |
33 import org.dive4elements.river.artifacts.model.sq.SQResult; | |
34 import org.dive4elements.river.artifacts.resources.Resources; | |
35 import org.dive4elements.river.exports.AbstractExporter; | |
36 import org.dive4elements.river.utils.Formatter; | |
37 import org.dive4elements.river.utils.RiverUtils; | |
38 | |
39 import au.com.bytecode.opencsv.CSVWriter; | |
40 import net.sf.jasperreports.engine.JRException; | |
41 import net.sf.jasperreports.engine.JRPrintPage; | |
21 import net.sf.jasperreports.engine.JasperExportManager; | 42 import net.sf.jasperreports.engine.JasperExportManager; |
22 import net.sf.jasperreports.engine.JasperFillManager; | 43 import net.sf.jasperreports.engine.JasperFillManager; |
23 import net.sf.jasperreports.engine.JasperPrint; | 44 import net.sf.jasperreports.engine.JasperPrint; |
24 import net.sf.jasperreports.engine.JRPrintPage; | |
25 import net.sf.jasperreports.engine.JRException; | |
26 | |
27 import au.com.bytecode.opencsv.CSVWriter; | |
28 | |
29 import org.dive4elements.artifacts.CallMeta; | |
30 | |
31 import org.dive4elements.river.artifacts.model.CalculationResult; | |
32 import org.dive4elements.river.artifacts.model.sq.SQFractionResult; | |
33 import org.dive4elements.river.artifacts.model.sq.SQResult; | |
34 import org.dive4elements.river.artifacts.model.sq.SQ; | |
35 import org.dive4elements.river.artifacts.model.sq.SQRelationJRDataSource; | |
36 import org.dive4elements.river.artifacts.model.sq.SQMeasurementsJRDataSource; | |
37 import org.dive4elements.river.artifacts.model.Parameters; | |
38 import org.dive4elements.river.artifacts.model.DateRange; | |
39 import org.dive4elements.river.artifacts.access.SQRelationAccess; | |
40 | |
41 import org.dive4elements.river.artifacts.resources.Resources; | |
42 | |
43 import org.dive4elements.river.artifacts.D4EArtifact; | |
44 | |
45 import org.dive4elements.river.exports.AbstractExporter; | |
46 | |
47 import org.dive4elements.river.utils.RiverUtils; | |
48 import org.dive4elements.river.utils.Formatter; | |
49 | |
50 import org.dive4elements.artifacts.common.utils.Config; | |
51 | |
52 import org.apache.log4j.Logger; | |
53 | 45 |
54 /** | 46 /** |
55 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 47 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
56 */ | 48 */ |
57 public class SQRelationExporter extends AbstractExporter { | 49 public class SQRelationExporter extends AbstractExporter { |
58 | 50 |
59 /** Private log. */ | 51 /** Private log. */ |
60 private static final Logger log = | 52 private static final Logger log = Logger.getLogger(SQRelationExporter.class); |
61 Logger.getLogger(SQRelationExporter.class); | 53 |
62 | 54 public static final String INFO_COEFF_A = "export.sqrelation.csv.info.coeff.a"; |
63 public static final String INFO_COEFF_A = | 55 |
64 "export.sqrelation.csv.info.coeff.a"; | 56 public static final String INFO_COEFF_B = "export.sqrelation.csv.info.coeff.b"; |
65 | 57 |
66 public static final String INFO_COEFF_B = | 58 public static final String INFO_QMAX = "export.sqrelation.csv.info.qmax"; |
67 "export.sqrelation.csv.info.coeff.b"; | 59 |
68 | 60 public static final String INFO_STDERR = "export.sqrelation.csv.info.stderr"; |
69 public static final String INFO_QMAX = | 61 |
70 "export.sqrelation.csv.info.qmax"; | 62 public static final String INFO_R2 = "export.sqrelation.csv.info.r2"; |
71 | 63 |
72 public static final String INFO_STDERR = | 64 public static final String INFO_NTOT = "export.sqrelation.csv.info.ntot"; |
73 "export.sqrelation.csv.info.stderr"; | 65 |
74 | 66 public static final String INFO_NOUTL = "export.sqrelation.csv.info.noutl"; |
75 public static final String INFO_R2 = | 67 |
76 "export.sqrelation.csv.info.r2"; | 68 public static final String INFO_CFERGUSON = "export.sqrelation.csv.info.cferguson"; |
77 | 69 |
78 public static final String INFO_NTOT = | 70 public static final String INFO_CDUAN = "export.sqrelation.csv.info.cduan"; |
79 "export.sqrelation.csv.info.ntot"; | 71 |
80 | 72 public static final String INFO_PARAM_A = "export.sqrelation.csv.info.param.a"; |
81 public static final String INFO_NOUTL = | 73 |
82 "export.sqrelation.csv.info.noutl"; | 74 public static final String INFO_PARAM_B = "export.sqrelation.csv.info.param.b"; |
83 | 75 |
84 public static final String INFO_CFERGUSON = | 76 public static final String INFO_PARAM_C = "export.sqrelation.csv.info.param.c"; |
85 "export.sqrelation.csv.info.cferguson"; | 77 |
86 | 78 public static final String INFO_PARAM_D = "export.sqrelation.csv.info.param.d"; |
87 public static final String INFO_CDUAN = | 79 |
88 "export.sqrelation.csv.info.cduan"; | 80 public static final String INFO_PARAM_E = "export.sqrelation.csv.info.param.e"; |
89 | 81 |
90 public static final String INFO_PARAM_A = | 82 public static final String INFO_PARAM_F = "export.sqrelation.csv.info.param.f"; |
91 "export.sqrelation.csv.info.param.a"; | 83 |
92 | 84 public static final String INFO_Q = "export.sqrelation.csv.info.q"; |
93 public static final String INFO_PARAM_B = | 85 |
94 "export.sqrelation.csv.info.param.b"; | 86 public static final String INFO_S_KG = "export.sqrelation.csv.info.s_kg"; |
95 | 87 |
96 public static final String INFO_PARAM_C = | 88 public static final String INFO_DATE = "export.sqrelation.csv.info.date"; |
97 "export.sqrelation.csv.info.param.c"; | 89 |
98 | 90 public static final String CSV_PARAMETER = "export.sqrelation.csv.header.parameter"; |
99 public static final String INFO_PARAM_D = | 91 |
100 "export.sqrelation.csv.info.param.d"; | 92 public static final String CSV_STATION = "export.sqrelation.csv.header.station"; |
101 | 93 |
102 public static final String INFO_PARAM_E = | 94 public static final String CSV_KM = "export.sqrelation.csv.header.km"; |
103 "export.sqrelation.csv.info.param.e"; | 95 |
104 | 96 public static final String CSV_FUNCTION = "export.sqrelation.csv.header.function"; |
105 public static final String INFO_PARAM_F = | 97 |
106 "export.sqrelation.csv.info.param.f"; | 98 public static final String CSV_GAUGE = "export.sqrelation.csv.header.gauge"; |
107 | 99 |
108 public static final String INFO_Q = | 100 public static final String CSV_COEFF_A = "export.sqrelation.csv.header.coeff.a"; |
109 "export.sqrelation.csv.info.q"; | 101 |
110 | 102 public static final String CSV_COEFF_B = "export.sqrelation.csv.header.coeff.b"; |
111 public static final String INFO_S_KG = | 103 |
112 "export.sqrelation.csv.info.s_kg"; | 104 public static final String CSV_COEFF_Q = "export.sqrelation.csv.header.coeff.q"; |
113 | 105 |
114 public static final String INFO_DATE = | 106 public static final String CSV_COEFF_R = "export.sqrelation.csv.header.coeff.r"; |
115 "export.sqrelation.csv.info.date"; | 107 |
116 | 108 public static final String CSV_N_TOTAL = "export.sqrelation.csv.header.n.total"; |
117 public static final String CSV_PARAMETER = | 109 |
118 "export.sqrelation.csv.header.parameter"; | 110 public static final String CSV_N_OUTLIERS = "export.sqrelation.csv.header.n.outliers"; |
119 | 111 |
120 public static final String CSV_STATION = | 112 public static final String CSV_C_DUAN = "export.sqrelation.csv.header.c.duan"; |
121 "export.sqrelation.csv.header.station"; | 113 |
122 | 114 public static final String CSV_C_FERGUSON = "export.sqrelation.csv.header.c.ferguson"; |
123 public static final String CSV_KM = | 115 |
124 "export.sqrelation.csv.header.km"; | 116 public static final String CSV_QMAX = "export.sqrelation.csv.header.qmax"; |
125 | 117 |
126 public static final String CSV_FUNCTION = | 118 public static final String CSV_SD = "export.sqrelation.csv.header.sd"; |
127 "export.sqrelation.csv.header.function"; | 119 |
128 | 120 public static final String CSV_S_KG = "export.sqrelation.csv.header.s_kg"; |
129 public static final String CSV_GAUGE = | 121 |
130 "export.sqrelation.csv.header.gauge"; | 122 public static final String CSV_Q = "common.export.csv.header.q"; |
131 | 123 |
132 public static final String CSV_COEFF_A = | 124 public static final String CSV_DATE = "export.sqrelation.csv.header.date"; |
133 "export.sqrelation.csv.header.coeff.a"; | 125 |
134 | 126 public static final String PDF_TITLE = "export.sqrelation.pdf.title"; |
135 public static final String CSV_COEFF_B = | 127 |
136 "export.sqrelation.csv.header.coeff.b"; | 128 public static final String PDF_HEADER_MODE = "export.sqrelation.pdf.mode"; |
137 | 129 |
138 public static final String CSV_COEFF_Q = | 130 public static final String JASPER_FILE = "export.sqrelation.pdf.file"; |
139 "export.sqrelation.csv.header.coeff.q"; | 131 |
140 | 132 public static final String JASPER_MEASUREMENTS_FILE = "export.sqrelation.measurements.pdf.file"; |
141 public static final String CSV_COEFF_R = | 133 |
142 "export.sqrelation.csv.header.coeff.r"; | 134 protected List<SQResult[]> data; |
143 | |
144 public static final String CSV_N_TOTAL = | |
145 "export.sqrelation.csv.header.n.total"; | |
146 | |
147 public static final String CSV_N_OUTLIERS = | |
148 "export.sqrelation.csv.header.n.outliers"; | |
149 | |
150 public static final String CSV_C_DUAN = | |
151 "export.sqrelation.csv.header.c.duan"; | |
152 | |
153 public static final String CSV_C_FERGUSON = | |
154 "export.sqrelation.csv.header.c.ferguson"; | |
155 | |
156 public static final String CSV_QMAX = | |
157 "export.sqrelation.csv.header.qmax"; | |
158 | |
159 public static final String CSV_SD = | |
160 "export.sqrelation.csv.header.sd"; | |
161 | |
162 public static final String CSV_S_KG = | |
163 "export.sqrelation.csv.header.s_kg"; | |
164 | |
165 public static final String CSV_Q = | |
166 "export.sqrelation.csv.header.q"; | |
167 | |
168 public static final String CSV_DATE = | |
169 "export.sqrelation.csv.header.date"; | |
170 | |
171 public static final String PDF_TITLE= | |
172 "export.sqrelation.pdf.title"; | |
173 | |
174 public static final String PDF_HEADER_MODE = | |
175 "export.sqrelation.pdf.mode"; | |
176 | |
177 public static final String JASPER_FILE = | |
178 "export.sqrelation.pdf.file"; | |
179 | |
180 public static final String JASPER_MEASUREMENTS_FILE = | |
181 "export.sqrelation.measurements.pdf.file"; | |
182 | |
183 protected List<SQResult []> data; | |
184 | 135 |
185 public SQRelationExporter() { | 136 public SQRelationExporter() { |
186 data = new ArrayList<SQResult []>(); | 137 this.data = new ArrayList<>(); |
187 } | 138 } |
188 | 139 |
189 @Override | 140 @Override |
190 protected void addData(Object d) { | 141 protected void addData(Object d) { |
191 if (d instanceof CalculationResult) { | 142 if (d instanceof CalculationResult) { |
192 d = ((CalculationResult)d).getData(); | 143 d = ((CalculationResult) d).getData(); |
193 if (d instanceof SQResult []) { | 144 if (d instanceof SQResult[]) { |
194 data.add((SQResult [])d); | 145 this.data.add((SQResult[]) d); |
195 } | 146 } |
196 } | 147 } |
197 } | 148 } |
198 | 149 |
199 protected void writeCSVHeader(CSVWriter writer) { | 150 protected void writeCSVHeader(final CSVWriter writer) { |
200 writer.writeNext(new String[] { | 151 writer.writeNext(new String[] { msg(CSV_KM), msg(CSV_PARAMETER), msg(CSV_COEFF_A), msg(CSV_COEFF_B), msg(CSV_SD), msg(CSV_QMAX), msg(CSV_COEFF_R), |
201 msg(CSV_KM), | 152 msg(CSV_N_TOTAL), msg(CSV_N_OUTLIERS), msg(CSV_C_DUAN), msg(CSV_C_FERGUSON), msg(CSV_S_KG), msg(CSV_Q), msg(CSV_DATE) }); |
202 msg(CSV_PARAMETER), | |
203 msg(CSV_COEFF_A), | |
204 msg(CSV_COEFF_B), | |
205 msg(CSV_SD), | |
206 msg(CSV_QMAX), | |
207 msg(CSV_COEFF_R), | |
208 msg(CSV_N_TOTAL), | |
209 msg(CSV_N_OUTLIERS), | |
210 msg(CSV_C_DUAN), | |
211 msg(CSV_C_FERGUSON), | |
212 msg(CSV_S_KG), | |
213 msg(CSV_Q), | |
214 msg(CSV_DATE) | |
215 }); | |
216 } | 153 } |
217 | 154 |
218 @Override | 155 @Override |
219 protected void writeCSVData(CSVWriter writer) { | 156 protected void writeCSVData(final CSVWriter writer) { |
220 log.debug("writeCSVData"); | 157 log.debug("writeCSVData"); |
221 | 158 |
222 writeCSVInfo(writer, new String[] { | 159 writeCSVInfo(writer, |
223 msg(INFO_PARAM_A), | 160 new String[] { msg(INFO_PARAM_A), msg(INFO_PARAM_B), msg(INFO_PARAM_C), msg(INFO_PARAM_D), msg(INFO_PARAM_E), msg(INFO_PARAM_F), |
224 msg(INFO_PARAM_B), | 161 msg(INFO_COEFF_A), msg(INFO_COEFF_B), msg(INFO_QMAX), msg(INFO_STDERR), msg(INFO_R2), msg(INFO_NTOT), msg(INFO_NOUTL), |
225 msg(INFO_PARAM_C), | 162 msg(INFO_CFERGUSON), msg(INFO_CDUAN), msg(INFO_S_KG), msg(INFO_Q), msg(INFO_DATE) }); |
226 msg(INFO_PARAM_D), | |
227 msg(INFO_PARAM_E), | |
228 msg(INFO_PARAM_F), | |
229 msg(INFO_COEFF_A), | |
230 msg(INFO_COEFF_B), | |
231 msg(INFO_QMAX), | |
232 msg(INFO_STDERR), | |
233 msg(INFO_R2), | |
234 msg(INFO_NTOT), | |
235 msg(INFO_NOUTL), | |
236 msg(INFO_CFERGUSON), | |
237 msg(INFO_CDUAN), | |
238 msg(INFO_S_KG), | |
239 msg(INFO_Q), | |
240 msg(INFO_DATE) | |
241 }); | |
242 | 163 |
243 writeCSVHeader(writer); | 164 writeCSVHeader(writer); |
244 | 165 |
245 for (SQResult [] results: data) { | 166 for (final SQResult[] results : this.data) { |
246 for (SQResult result: results) { | 167 for (final SQResult result : results) { |
247 writer.writeAll(data2StringArrays(result, true)); | 168 writer.writeAll(data2StringArrays(result, true)); |
248 } | 169 } |
249 } | 170 } |
250 } | 171 } |
251 | 172 |
252 protected List<String[]> data2StringArrays( | 173 protected List<String[]> data2StringArrays(final SQResult result, final boolean includeMeasurements) { |
253 SQResult result, | 174 final String km = Formatter.getSQRelationKM(this.context).format(result.getKm()); |
254 boolean includeMeasurements | 175 final List<String[]> retval = new ArrayList<>(); |
255 ) { | 176 |
256 String km = Formatter.getSQRelationKM(context | 177 final NumberFormat sqAFormatter = Formatter.getSQRelationA(this.context); |
257 ).format(result.getKm()); | 178 final NumberFormat sqBFormatter = Formatter.getSQRelationB(this.context); |
258 List<String[]> retval = new ArrayList<String[]>(); | 179 final NumberFormat fThreeFormatter = Formatter.getFormatter(this.context, 3, 3); |
259 | 180 final NumberFormat fTwoFormatter = Formatter.getFormatter(this.context, 2, 2); |
260 NumberFormat sqAFormatter = Formatter.getSQRelationA(context); | 181 final NumberFormat fZeroFormatter = Formatter.getFormatter(this.context, 0, 0); |
261 NumberFormat sqBFormatter = Formatter.getSQRelationB(context); | 182 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Resources.getLocale(this.context.getMeta())); |
262 NumberFormat fThreeFormatter = Formatter.getFormatter(context, 3, 3); | |
263 NumberFormat fTwoFormatter = Formatter.getFormatter(context, 2, 2); | |
264 NumberFormat fZeroFormatter = Formatter.getFormatter(context, 0, 0); | |
265 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, | |
266 Resources.getLocale(context.getMeta())); | |
267 | 183 |
268 for (int i = 0; i < SQResult.NUMBER_FRACTIONS; ++i) { | 184 for (int i = 0; i < SQResult.NUMBER_FRACTIONS; ++i) { |
269 SQFractionResult fraction = result.getFraction(i); | 185 final SQFractionResult fraction = result.getFraction(i); |
270 | 186 |
271 String name = result.getFractionName(i); | 187 final String name = result.getFractionName(i); |
272 | 188 |
273 Parameters parameters = fraction.getParameters(); | 189 final Parameters parameters = fraction.getParameters(); |
274 | 190 |
275 if (parameters == null) { | 191 if (parameters == null) { |
276 continue; | 192 continue; |
277 } | 193 } |
278 | 194 |
279 String a, b, sd, o, t, max_q, c_ferguson, c_duan, r2; | 195 String a, b, sd, o, t, max_q, c_ferguson, c_duan, r2; |
280 a = sqAFormatter.format(parameters.getValue(0, "a")); | 196 a = sqAFormatter.format(parameters.getValue(0, "a")); |
281 b = sqBFormatter.format(parameters.getValue(0, "b")); | 197 b = sqBFormatter.format(parameters.getValue(0, "b")); |
282 | 198 |
283 /* The std_dev parameter contains the standard error actually */ | 199 /* The std_dev parameter contains the standard error actually */ |
284 sd = fThreeFormatter.format(parameters.getValue(0, "std_dev")); | 200 sd = fThreeFormatter.format(parameters.getValue(0, "std_dev")); |
285 max_q = fZeroFormatter.format(parameters.getValue(0, "max_q")); | 201 max_q = fZeroFormatter.format(parameters.getValue(0, "max_q")); |
286 c_ferguson = fTwoFormatter.format( | 202 c_ferguson = fTwoFormatter.format(parameters.getValue(0, "c_ferguson")); |
287 parameters.getValue(0, "c_ferguson")); | |
288 c_duan = fTwoFormatter.format(parameters.getValue(0, "c_duan")); | 203 c_duan = fTwoFormatter.format(parameters.getValue(0, "c_duan")); |
289 r2 = fTwoFormatter.format(parameters.getValue(0, "r2")); | 204 r2 = fTwoFormatter.format(parameters.getValue(0, "r2")); |
290 | 205 |
291 | 206 o = String.valueOf(fraction.totalNumOutliers()); |
292 o = String.valueOf(fraction.totalNumOutliers()); | 207 t = String.valueOf(fraction.numMeasurements()); |
293 t = String.valueOf(fraction.numMeasurements()); | |
294 | 208 |
295 if (includeMeasurements) { | 209 if (includeMeasurements) { |
296 for (SQ sq: fraction.getMeasurements()) { | 210 for (final SQ sq : fraction.getMeasurements()) { |
297 retval.add(new String[] { | 211 retval.add(new String[] { km, name, a, b, sd, // 4 |
298 km, | 212 max_q, // 5 |
299 name, | 213 r2, // 6 |
300 a, | 214 t, // 7 |
301 b, | 215 o, // 8 |
302 sd, // 4 | 216 c_duan, // 9 |
217 c_ferguson, // 10 | |
218 fThreeFormatter.format(sq.getS()), fZeroFormatter.format(sq.getQ()), df.format(sq.getDate()) }); | |
219 } | |
220 } else { | |
221 retval.add(new String[] { km, name, a, b, sd, // 4 | |
303 max_q, // 5 | 222 max_q, // 5 |
304 r2, // 6 | 223 r2, // 6 |
305 t, // 7 | 224 t, // 7 |
306 o, // 8 | 225 o, // 8 |
307 c_duan, // 9 | 226 c_duan, // 9 |
308 c_ferguson, // 10 | 227 c_ferguson // 10 |
309 fThreeFormatter.format(sq.getS()), | |
310 fZeroFormatter.format(sq.getQ()), | |
311 df.format(sq.getDate()) | |
312 }); | |
313 } | |
314 } else { | |
315 retval.add(new String[] { | |
316 km, | |
317 name, | |
318 a, | |
319 b, | |
320 sd, // 4 | |
321 max_q, // 5 | |
322 r2, // 6 | |
323 t, // 7 | |
324 o, // 8 | |
325 c_duan, // 9 | |
326 c_ferguson // 10 | |
327 }); | 228 }); |
328 } | 229 } |
329 | 230 |
330 } | 231 } |
331 return retval; | 232 return retval; |
332 } | 233 } |
333 | 234 |
334 | |
335 protected SQRelationJRDataSource createJRData() { | 235 protected SQRelationJRDataSource createJRData() { |
336 SQRelationJRDataSource source = new SQRelationJRDataSource(); | 236 final SQRelationJRDataSource source = new SQRelationJRDataSource(); |
337 | 237 |
338 addMetaData(source); | 238 addMetaData(source); |
339 for (SQResult [] results: data) { | 239 for (final SQResult[] results : this.data) { |
340 for (SQResult result: results) { | 240 for (final SQResult result : results) { |
341 for (String[] res: data2StringArrays(result, false)) { | 241 for (final String[] res : data2StringArrays(result, false)) { |
342 source.addData(res); | 242 source.addData(res); |
343 } | 243 } |
344 } | 244 } |
345 } | 245 } |
346 return source; | 246 return source; |
347 } | 247 } |
348 | 248 |
349 protected SQMeasurementsJRDataSource createMeasurementJRData() { | 249 protected SQMeasurementsJRDataSource createMeasurementJRData() { |
350 SQMeasurementsJRDataSource source = new SQMeasurementsJRDataSource(); | 250 final SQMeasurementsJRDataSource source = new SQMeasurementsJRDataSource(); |
351 NumberFormat fZeroFormatter = Formatter.getFormatter(context, 0, 0); | 251 final NumberFormat fZeroFormatter = Formatter.getFormatter(this.context, 0, 0); |
352 NumberFormat fThreeFormatter = Formatter.getFormatter(context, 3, 3); | 252 final NumberFormat fThreeFormatter = Formatter.getFormatter(this.context, 3, 3); |
353 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, | 253 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Resources.getLocale(this.context.getMeta())); |
354 Resources.getLocale(context.getMeta())); | 254 |
355 | 255 for (final SQResult[] results : this.data) { |
356 for (SQResult [] results: data) { | 256 for (final SQResult result : results) { |
357 for (SQResult result: results) { | |
358 for (int i = 0; i < SQResult.NUMBER_FRACTIONS; ++i) { | 257 for (int i = 0; i < SQResult.NUMBER_FRACTIONS; ++i) { |
359 String name = result.getFractionName(i); | 258 final String name = result.getFractionName(i); |
360 SQFractionResult fraction = result.getFraction(i); | 259 final SQFractionResult fraction = result.getFraction(i); |
361 for (SQ sq: fraction.getMeasurements()) { | 260 for (final SQ sq : fraction.getMeasurements()) { |
362 source.addData(new String[] { | 261 source.addData( |
363 name, | 262 new String[] { name, fThreeFormatter.format(sq.getS()), fZeroFormatter.format(sq.getQ()), df.format(sq.getDate()), null }); |
364 fThreeFormatter.format(sq.getS()), | |
365 fZeroFormatter.format(sq.getQ()), | |
366 df.format(sq.getDate()), | |
367 null | |
368 }); | |
369 } | 263 } |
370 for (int j = 0; j < fraction.numIterations(); j++) { | 264 for (int j = 0; j < fraction.numIterations(); j++) { |
371 for (SQ sq: fraction.getOutliers(j)) { | 265 for (final SQ sq : fraction.getOutliers(j)) { |
372 source.addData(new String[] { | 266 source.addData(new String[] { name, fThreeFormatter.format(sq.getS()), fZeroFormatter.format(sq.getQ()), df.format(sq.getDate()), |
373 name, | 267 Integer.toString(j + 1) }); |
374 fThreeFormatter.format(sq.getS()), | |
375 fZeroFormatter.format(sq.getQ()), | |
376 df.format(sq.getDate()), | |
377 Integer.toString(j + 1) | |
378 }); | |
379 } | 268 } |
380 } | 269 } |
381 } | 270 } |
382 } | 271 } |
383 } | 272 } |
384 return source; | 273 return source; |
385 } | 274 } |
386 | 275 |
387 protected void addMetaData(SQRelationJRDataSource source) { | 276 protected void addMetaData(final SQRelationJRDataSource source) { |
388 CallMeta meta = context.getMeta(); | 277 final CallMeta meta = this.context.getMeta(); |
389 | 278 |
390 D4EArtifact arti = (D4EArtifact) master; | 279 final D4EArtifact arti = (D4EArtifact) this.master; |
391 | 280 |
392 source.addMetaData ("river", RiverUtils.getRivername(arti)); | 281 source.addMetaData("river", RiverUtils.getRivername(arti)); |
393 | 282 |
394 Locale locale = Resources.getLocale(meta); | 283 final Locale locale = Resources.getLocale(meta); |
395 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); | 284 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); |
396 | 285 |
397 source.addMetaData("date", df.format(new Date())); | 286 source.addMetaData("date", df.format(new Date())); |
398 | 287 |
399 SQRelationAccess access = new SQRelationAccess(arti); | 288 final SQRelationAccess access = new SQRelationAccess(arti); |
400 source.addMetaData( | 289 source.addMetaData("location", "KM " + getKmFormatter().format(access.getLocation())); |
401 "location", "KM " + getKmFormatter().format(access.getLocation())); | 290 |
402 | 291 final DateRange period = access.getPeriod(); |
403 DateRange period = access.getPeriod(); | 292 source.addMetaData("periods", df.format(period.getFrom()) + " - " + df.format(period.getTo())); |
404 source.addMetaData("periods", df.format(period.getFrom()) + " - " + | 293 |
405 df.format(period.getTo())); | 294 source.addMetaData("outliertest", Resources.getMsg(meta, access.getOutlierMethod(), access.getOutlierMethod())); |
406 | 295 source.addMetaData("outliers", Formatter.getRawFormatter(this.context).format(access.getOutliers())); |
407 source.addMetaData("outliertest", Resources.getMsg(meta, | 296 |
408 access.getOutlierMethod(), | 297 source.addMetaData("calculation", Resources.getMsg(locale, PDF_HEADER_MODE, "SQRelation")); |
409 access.getOutlierMethod())); | 298 |
410 source.addMetaData( | 299 final String measurementStationName = access.getMeasurementStationName(); |
411 "outliers", Formatter.getRawFormatter(context).format( | |
412 access.getOutliers())); | |
413 | |
414 source.addMetaData("calculation", Resources.getMsg( | |
415 locale, | |
416 PDF_HEADER_MODE, | |
417 "SQRelation")); | |
418 | |
419 String measurementStationName = access.getMeasurementStationName(); | |
420 | 300 |
421 if (measurementStationName != null) { | 301 if (measurementStationName != null) { |
422 source.addMetaData("msName", measurementStationName); | 302 source.addMetaData("msName", measurementStationName); |
423 } else { | 303 } else { |
424 source.addMetaData("msName", ""); | 304 source.addMetaData("msName", ""); |
425 } | 305 } |
426 | 306 |
427 String measurementStationGaugeName = access | 307 final String measurementStationGaugeName = access.getMeasurementStationGaugeName(); |
428 .getMeasurementStationGaugeName(); | |
429 | 308 |
430 if (measurementStationGaugeName != null) { | 309 if (measurementStationGaugeName != null) { |
431 source.addMetaData("msGauge", measurementStationGaugeName); | 310 source.addMetaData("msGauge", measurementStationGaugeName); |
432 } else { | 311 } else { |
433 source.addMetaData("msGauge", ""); | 312 source.addMetaData("msGauge", ""); |
434 } | 313 } |
435 | 314 |
436 } | 315 } |
437 | 316 |
438 @Override | 317 @Override |
439 protected void writePDF(OutputStream out) { | 318 protected void writePDF(final OutputStream out) { |
440 log.debug("write PDF"); | 319 log.debug("write PDF"); |
441 SQRelationJRDataSource source = createJRData(); | 320 final SQRelationJRDataSource source = createJRData(); |
442 SQMeasurementsJRDataSource measureSource = createMeasurementJRData(); | 321 final SQMeasurementsJRDataSource measureSource = createMeasurementJRData(); |
443 | 322 |
444 String jasperFile = Resources.getMsg( | 323 final String jasperFile = Resources.getMsg(this.context.getMeta(), JASPER_FILE, "/jasper/sqrelation_en.jasper"); |
445 context.getMeta(), | 324 final String jasperMeasurementsFile = Resources.getMsg(this.context.getMeta(), JASPER_MEASUREMENTS_FILE, "/jasper/sqmeasurements_en.jasper"); |
446 JASPER_FILE, | 325 final String confPath = Config.getConfigDirectory().toString(); |
447 "/jasper/sqrelation_en.jasper"); | 326 |
448 String jasperMeasurementsFile = Resources.getMsg( | 327 final Map parameters = new HashMap(); |
449 context.getMeta(), | 328 parameters.put("ReportTitle", Resources.getMsg(this.context.getMeta(), PDF_TITLE, "Exported Data")); |
450 JASPER_MEASUREMENTS_FILE, | |
451 "/jasper/sqmeasurements_en.jasper"); | |
452 String confPath = Config.getConfigDirectory().toString(); | |
453 | |
454 | |
455 Map parameters = new HashMap(); | |
456 parameters.put("ReportTitle", Resources.getMsg( | |
457 context.getMeta(), PDF_TITLE, "Exported Data")); | |
458 try { | 329 try { |
459 /* Page numbers start have a built in offset of 1 so this | 330 /* |
460 * is fine. */ | 331 * Page numbers start have a built in offset of 1 so this |
461 JasperPrint p2 = JasperFillManager.fillReport( | 332 * is fine. |
462 confPath + jasperMeasurementsFile, | 333 */ |
463 parameters, | 334 final JasperPrint p2 = JasperFillManager.fillReport(confPath + jasperMeasurementsFile, parameters, measureSource); |
464 measureSource); | |
465 parameters.put("MEASUREMENT_PAGE_NUM", p2.getPages().size()); | 335 parameters.put("MEASUREMENT_PAGE_NUM", p2.getPages().size()); |
466 JasperPrint p1 = JasperFillManager.fillReport( | 336 final JasperPrint p1 = JasperFillManager.fillReport(confPath + jasperFile, parameters, source); |
467 confPath + jasperFile, | 337 for (final Object page : p2.getPages()) { |
468 parameters, | 338 final JRPrintPage object = (JRPrintPage) page; |
469 source); | |
470 for (Object page: p2.getPages()) { | |
471 JRPrintPage object = (JRPrintPage)page; | |
472 p1.addPage(object); | 339 p1.addPage(object); |
473 } | 340 } |
474 JasperExportManager.exportReportToPdfStream(p1, out); | 341 JasperExportManager.exportReportToPdfStream(p1, out); |
475 } | 342 } |
476 catch(JRException je) { | 343 catch (final JRException je) { |
477 log.warn("Error generating PDF Report!", je); | 344 log.warn("Error generating PDF Report!", je); |
478 } | 345 } |
479 } | 346 } |
480 } | 347 } |
481 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 348 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |