annotate flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionExporter.java @ 701:dad1a2c88f9f facets-slt

Base WST/CSV exports on facets. TODO: generate the facets. flys-artifacts/branches/facets-slt@2151 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 17 Jun 2011 13:45:50 +0000
parents e006da5679d2
children 733d6db30722
rev   line source
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.exports;
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
3 import java.text.NumberFormat;
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
4
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import org.apache.log4j.Logger;
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import au.com.bytecode.opencsv.CSVWriter;
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import de.intevation.flys.artifacts.model.WQCKms;
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import de.intevation.flys.artifacts.model.WQKms;
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 /**
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 */
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 public class DischargeLongitudinalSectionExporter extends WaterlevelExporter {
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 /** The logger used in this exporter.*/
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 private static Logger logger =
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 Logger.getLogger(DischargeLongitudinalSectionExporter.class);
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
22 public static final String CSV_KM_HEADER =
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
23 "export.discharge.longitudinal.section.csv.header.km";
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
24
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
25 public static final String CSV_W_HEADER =
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
26 "export.discharge.longitudinal.section.csv.header.w";
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
27
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
28 public static final String CSV_CW_HEADER =
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
29 "export.discharge.longitudinal.section.csv.header.cw";
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
30
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
31 public static final String CSV_Q_HEADER =
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
32 "export.discharge.longitudinal.section.csv.header.q";
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
33
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
34 public static final String DEFAULT_CSV_KM_HEADER = "Fluss-Km";
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
35 public static final String DEFAULT_CSV_W_HEADER = "W [NN + m]";
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
36 public static final String DEFAULT_CSV_CW_HEADER = "W korr.";
664
e006da5679d2 s@m³/s@m\u00b3/s@
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
37 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: 407
diff changeset
38
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
39
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 @Override
701
dad1a2c88f9f Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 664
diff changeset
41 protected void addData(Object d) {
dad1a2c88f9f Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 664
diff changeset
42 if (d instanceof WQKms []) {
dad1a2c88f9f Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 664
diff changeset
43 data.add((WQKms [])d);
dad1a2c88f9f Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 664
diff changeset
44 }
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 }
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 @Override
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
49 protected void writeCSVHeader(CSVWriter writer) {
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
50 logger.info("WaterlevelExporter.writeCSVHeader");
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
51
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
52 writer.writeNext(new String[] {
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
53 msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER),
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
54 msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER),
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
55 msg(CSV_CW_HEADER, DEFAULT_CSV_CW_HEADER),
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
56 msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER)
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
57 });
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
58 }
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
59
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 407
diff changeset
60 @Override
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 protected void wQKms2CSV(CSVWriter writer, WQKms wqkms) {
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 logger.debug("WaterlevelExporter.wQKms2CSV");
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 int size = wqkms.size();
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 double[] result = new double[4];
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
67 NumberFormat kmf = getKmFormatter();
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
68 NumberFormat wf = getWFormatter();
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
69 NumberFormat qf = getQFormatter();
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
70
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 for (int i = 0; i < size; i ++) {
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 result = wqkms.get(i, result);
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 String wc = "";
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 if (wqkms instanceof WQCKms) {
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
76 wc = wf.format(result[3]);
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 }
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 writer.writeNext(new String[] {
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
80 kmf.format(result[2]),
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
81 wf.format(result[0]),
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 wc,
418
e0fec407a280 ISSUE-53 Formatted number values of CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 416
diff changeset
83 qf.format(result[1])
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 });
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 }
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 }
450
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
87
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
88
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
89 @Override
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
90 protected void addWSTColumn(WstWriter writer, WQKms wqkms) {
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
91 String name = wqkms.getName();
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
92
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
93 // is it a W or a Q mode?
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
94 int wIdx = name.indexOf("W");
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
95 int qIdx = name.indexOf("Q");
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
96
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
97 String wq = null;
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
98 if (wIdx >= 0) {
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
99 wq = "W";
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
100 }
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
101 else if (qIdx >= 0) {
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
102 wq = "Q";
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
103 }
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
104
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
105 // we just want to display the first W or Q value in the WST
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
106 int start = name.indexOf("(");
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
107 int end = name.indexOf(")");
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
108
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
109 String tmp = name.substring(start+1, end);
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
110 String[] values = tmp.split(";");
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
111
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
112 String column = wq + "=" + values[0];
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
113
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
114 writer.addColumn(column);
c8bb38115290 Enabled the discharge longitudinal section to be exported as WST.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
115 }
407
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 }
9eb5f0c8fe7f Added a CSV exporter for the discharge longitudinal section computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org