annotate artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveExporter.java @ 5867:59ff03ff48f1

River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 15:23:01 +0200
parents 73da40528cf2
children b740f0c4179e
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
9 package org.dive4elements.river.exports;
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import java.io.OutputStream;
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
12 import java.text.NumberFormat;
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import java.util.ArrayList;
701
dad1a2c88f9f Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 664
diff changeset
14 import java.util.Arrays;
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import java.util.List;
2177
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
16 import java.util.Map;
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
17 import java.util.HashMap;
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
18 import java.util.Date;
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
19 import java.text.DateFormat;
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
20 import java.util.Locale;
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import org.w3c.dom.Document;
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 import org.apache.log4j.Logger;
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 import au.com.bytecode.opencsv.CSVWriter;
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27
2177
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
28 import net.sf.jasperreports.engine.JasperExportManager;
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
29 import net.sf.jasperreports.engine.JasperFillManager;
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
30 import net.sf.jasperreports.engine.JasperPrint;
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
31 import net.sf.jasperreports.engine.JRException;
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
32
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
33 import org.dive4elements.artifacts.common.utils.Config;
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
35 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
36 import org.dive4elements.artifacts.CallMeta;
715
9665d6a48f7b Fix for flys/issue154
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 701
diff changeset
37
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5865
diff changeset
38 import org.dive4elements.river.artifacts.D4EArtifact;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
39
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
40 import org.dive4elements.river.artifacts.access.RangeAccess;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
41 import org.dive4elements.river.artifacts.model.CalculationResult;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
42 import org.dive4elements.river.artifacts.model.WQKms;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
43 import org.dive4elements.river.artifacts.model.WKmsJRDataSource;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
44 import org.dive4elements.river.artifacts.resources.Resources;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
45
5865
73da40528cf2 River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
46 import org.dive4elements.river.utils.RiverUtils;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
47 import org.dive4elements.river.utils.Formatter;
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 /**
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 */
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 public class ComputedDischargeCurveExporter extends AbstractExporter {
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 /** The logger used in this exporter.*/
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 private static Logger logger =
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 Logger.getLogger(ComputedDischargeCurveExporter.class);
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
59 public static final String CSV_W_HEADER =
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
60 "export.computed.discharge.curve.csv.header.w";
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
61
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
62 public static final String CSV_Q_HEADER =
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
63 "export.computed.discharge.curve.csv.header.q";
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
64
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
65 public static final String DEFAULT_CSV_W_HEADER = "W [NN + m]";
664
e006da5679d2 s@m³/s@m\u00b3/s@
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 445
diff changeset
66 public static final String DEFAULT_CSV_Q_HEADER = "Q [m\u00b3/s]";
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
67
2177
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
68 public static final String PDF_HEADER_MODE = "export.computed.discharge.pdf.mode";
2185
a9a8df1473fd Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2182
diff changeset
69 public static final String JASPER_FILE = "export.computed.discharge.pdf.file";
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
394
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
71 protected List<WQKms> data;
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
72
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
73
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 public void init(Document request, OutputStream out, CallContext context) {
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 logger.debug("ComputedDischargeCurveExporter.init");
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 super.init(request, out, context);
394
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
78
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
79 this.data = new ArrayList<WQKms>();
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 }
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82
701
dad1a2c88f9f Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 664
diff changeset
83 @Override
dad1a2c88f9f Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 664
diff changeset
84 protected void addData(Object d) {
715
9665d6a48f7b Fix for flys/issue154
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 701
diff changeset
85 if (d instanceof CalculationResult) {
9665d6a48f7b Fix for flys/issue154
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 701
diff changeset
86 d = ((CalculationResult)d).getData();
701
dad1a2c88f9f Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 664
diff changeset
87 }
4585
b4a95290ec63 Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents: 2185
diff changeset
88 if (d instanceof WQKms[]){
b4a95290ec63 Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents: 2185
diff changeset
89 data.addAll(Arrays.asList((WQKms [])d));
b4a95290ec63 Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents: 2185
diff changeset
90 return;
b4a95290ec63 Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents: 2185
diff changeset
91 }
b4a95290ec63 Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents: 2185
diff changeset
92 else if (d instanceof WQKms) {
b4a95290ec63 Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents: 2185
diff changeset
93 data.add((WQKms)d);
4610
497bc73ca64a Fix: Don't show the warning if datatype is WQKms
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4585
diff changeset
94 return;
4585
b4a95290ec63 Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents: 2185
diff changeset
95 }
b4a95290ec63 Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents: 2185
diff changeset
96 logger.warn("Can't add data for csv export. Unkown data type " +
b4a95290ec63 Refactor ComputedDischargeCurveExporter to support WQKms values and WQKms arrays
Björn Ricks <bjoern.ricks@intevation.de>
parents: 2185
diff changeset
97 d.getClass().getName());
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 }
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 protected void writeCSVData(CSVWriter writer) {
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 logger.info("ComputedDischargeCurveExporter.writeData");
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
104 writeCSVHeader(writer);
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
105
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
106 NumberFormat wf = getWFormatter();
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
107 NumberFormat qf = getQFormatter();
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
108
394
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
109 double[] res = new double[3];
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
110
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
111 for (WQKms wqkms: data) {
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
112 int size = wqkms.size();
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
113
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
114 for (int i = 0; i < size; i++) {
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
115 res = wqkms.get(i, res);
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
116
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
117 writer.writeNext(new String[] {
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
118 wf.format(res[0]),
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
119 qf.format(res[1])
394
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
120 });
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
121 }
b9175ddea49b Filled the discharge curve exporter (CSV) with code - now, it generates a CSV export with the computed discharge curve data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 392
diff changeset
122 }
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 }
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
124
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
125
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
126 protected void writeCSVHeader(CSVWriter writer) {
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
127 logger.debug("ComputedDischargeCurveExporter.writeCSVHeader");
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
128
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5865
diff changeset
129 String unit = RiverUtils.getRiver((D4EArtifact) master).getWstUnit().getName();
5420
0bb57e72b8ea Fix flys/issue1206 (reference system in discharge curve).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4856
diff changeset
130
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
131 writer.writeNext(new String[] {
5420
0bb57e72b8ea Fix flys/issue1206 (reference system in discharge curve).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4856
diff changeset
132 msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { unit }),
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
133 msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER)
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
134 });
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 394
diff changeset
135 }
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
136
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
137
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
138 /**
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
139 * Returns the number formatter for W values.
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
140 *
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
141 * @return the number formatter for W values.
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
142 */
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
143 protected NumberFormat getWFormatter() {
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
144 return Formatter.getComputedDischargeW(context);
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
145 }
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
146
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
147
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
148 /**
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
149 * Returns the number formatter for Q values.
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
150 *
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
151 * @return the number formatter for Q values.
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
152 */
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
153 protected NumberFormat getQFormatter() {
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
154 return Formatter.getComputedDischargeQ(context);
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
155 }
2176
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 715
diff changeset
156
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 715
diff changeset
157
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 715
diff changeset
158 @Override
2177
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
159 protected void writePDF(OutputStream out) {
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
160 WKmsJRDataSource source = createJRData();
2185
a9a8df1473fd Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2182
diff changeset
161
a9a8df1473fd Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2182
diff changeset
162 String jasperFile = Resources.getMsg(
a9a8df1473fd Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2182
diff changeset
163 context.getMeta(),
a9a8df1473fd Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2182
diff changeset
164 JASPER_FILE,
a9a8df1473fd Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2182
diff changeset
165 "/jasper/computed-discharge_en.jasper");
a9a8df1473fd Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2182
diff changeset
166 String confPath = Config.getConfigDirectory().toString();
a9a8df1473fd Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2182
diff changeset
167
2177
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
168 Map parameters = new HashMap();
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
169 parameters.put("ReportTitle", "Exported Data");
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
170 try {
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
171 JasperPrint print = JasperFillManager.fillReport(
2185
a9a8df1473fd Added i18n support to PDF report export.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2182
diff changeset
172 confPath + jasperFile,
2177
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
173 parameters,
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
174 source);
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
175 JasperExportManager.exportReportToPdfStream(print, out);
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
176 }
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
177 catch(JRException je) {
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
178 logger.warn("Error generating PDF Report!");
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
179 je.printStackTrace();
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
180 }
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
181 }
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
182
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
183
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
184 protected WKmsJRDataSource createJRData() {
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
185 WKmsJRDataSource source = new WKmsJRDataSource();
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
186
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
187 addMetaData(source);
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
188 addWQData(source);
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
189
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
190 return source;
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
191 }
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
192
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
193
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
194 protected void addMetaData(WKmsJRDataSource source) {
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
195 CallMeta meta = context.getMeta();
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
196
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5865
diff changeset
197 D4EArtifact flys = (D4EArtifact) master;
2177
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
198
5865
73da40528cf2 River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
199 source.addMetaData ("river", RiverUtils.getRivername(flys));
2177
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
200
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
201 Locale locale = Resources.getLocale(meta);
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
202 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
203
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
204 source.addMetaData("date", df.format(new Date()));
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
205
4856
d9ef525bff08 ChartGenerator, ComputedDischargeCurveExporter: Updated to use RangeAccess instead of FLYSUtils.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4610
diff changeset
206 RangeAccess rangeAccess = new RangeAccess(flys, null);
d9ef525bff08 ChartGenerator, ComputedDischargeCurveExporter: Updated to use RangeAccess instead of FLYSUtils.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4610
diff changeset
207 double[] kms = rangeAccess.getKmRange();
2177
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
208 source.addMetaData("range", String.valueOf(kms[0]));
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
209
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
210 source.addMetaData("calculation", Resources.getMsg(
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
211 locale,
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
212 PDF_HEADER_MODE,
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
213 "Computed Discharge"));
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
214 }
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
215
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
216 protected void addWQData(WKmsJRDataSource source) {
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
217 NumberFormat wf = getWFormatter();
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
218 NumberFormat qf = getQFormatter();
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
219
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
220 double[] res = new double[3];
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
221
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
222 for (WQKms wqkms: data) {
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
223 int size = wqkms.size();
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
224
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
225 for (int i = 0; i < size; i++) {
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
226 res = wqkms.get(i, res);
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
227
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
228 source.addData(new String[] {
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
229 "", // Empty, the WKmsJRDtasource stores km here.
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
230 wf.format(res[0]),
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
231 qf.format(res[1])
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
232 });
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
233 }
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
234 }
28dbeb64ce7c Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2176
diff changeset
235 }
392
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
236 }
72177020db92 Improved the transition model and added classes to enable the WINFO artifact to create computed discharge curves - NOTE: each of the new classes is just a stub.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org