comparison flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/DeltaWtExporter.java @ 3402:0336132ec9db

Adjusted Delta W(t) CSV exporter to customers wishes. flys-artifacts/trunk@5044 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 18 Jul 2012 16:28:00 +0000
parents 7f9fe694f8d1
children e3c7a3228bc2
comparison
equal deleted inserted replaced
3401:086326be721c 3402:0336132ec9db
25 import java.text.MessageFormat; 25 import java.text.MessageFormat;
26 import java.text.NumberFormat; 26 import java.text.NumberFormat;
27 27
28 import java.util.ArrayList; 28 import java.util.ArrayList;
29 import java.util.List; 29 import java.util.List;
30 import java.util.Locale;
31 30
32 import org.apache.log4j.Logger; 31 import org.apache.log4j.Logger;
33 32
34 import org.w3c.dom.Document; 33 import org.w3c.dom.Document;
35 34
45 "export.fixings.deltawt.csv.header.deltaw"; 44 "export.fixings.deltawt.csv.header.deltaw";
46 45
47 public static final String CSV_Q_HEADER = 46 public static final String CSV_Q_HEADER =
48 "export.fixings.deltawt.csv.header.q"; 47 "export.fixings.deltawt.csv.header.q";
49 48
49 public static final String CSV_W_HEADER =
50 "export.fixings.deltawt.csv.header.w";
51
50 public static final String CSV_TRANGE_HEADER = 52 public static final String CSV_TRANGE_HEADER =
51 "export.fixings.deltawt.csv.header.time.range"; 53 "export.fixings.deltawt.csv.header.time.range";
52 54
53 public static final String CSV_T_HEADER = 55 public static final String CSV_T_HEADER =
54 "export.fixings.deltawt.csv.header.t"; 56 "export.fixings.deltawt.csv.header.t";
55 57
56 public static final String CSV_T_DESC_HEADER = 58 public static final String CSV_T_FORMAT =
57 "export.fixings.deltawt.csv.header.description"; 59 "export.fixings.deltawt.csv.t.format";
58 60
59 public static final String DEFAULT_CSV_KM_HEADER = "km"; 61 public static final String DEFAULT_CSV_KM_HEADER = "km";
60 62
61 public static final String DEFAULT_CSV_DELTA_W_HEADER = "\u0394 W [cm]"; 63 public static final String DEFAULT_CSV_DELTA_W_HEADER = "\u0394 W [cm]";
62 64
65 public static final String DEFAULT_CSV_W_HEADER = "Wasserstand [m]";
66
63 public static final String DEFAULT_CSV_Q_HEADER = "Abfluss [m\u00b3/s]"; 67 public static final String DEFAULT_CSV_Q_HEADER = "Abfluss [m\u00b3/s]";
64 68
65 public static final String DEFAULT_CSV_T_HEADER = "Datum"; 69 public static final String DEFAULT_CSV_T_HEADER = "Datum";
66 70
67 public static final String DEFAULT_CSV_T_DESC_HEADER = "Beschreibung";
68
69 public static final String DEFAULT_CSV_TRANGE_DESC_HEADER = 71 public static final String DEFAULT_CSV_TRANGE_DESC_HEADER =
70 "Zeitraum"; 72 "Status";
71 73
72 public static final String CSV_REFERENCE = 74 public static final String CSV_REFERENCE =
73 "export.fixings.deltawt.csv.reference"; 75 "export.fixings.deltawt.csv.reference";
74 76
75 public static final String CSV_ANALYSIS = 77 public static final String CSV_ANALYSIS =
76 "export.fixings.deltawt.csv.analysis"; 78 "export.fixings.deltawt.csv.analysis";
77 79
78 public static final String DEFAULT_CSV_REFERENCE = 80 public static final String DEFAULT_CSV_REFERENCE =
79 "Bezug"; 81 "B";
80 82
81 public static final String DEFAULT_CSV_ANALYSIS = 83 public static final String DEFAULT_CSV_ANALYSIS =
82 "Analyse {0,number,integer}"; 84 "A{0,number,integer}";
85
86 public static final String DEFAULT_CSV_T_FORMAT =
87 "dd.MM.yyyy";
83 88
84 protected List<KMIndex<AnalysisPeriod []>> analysisPeriods; 89 protected List<KMIndex<AnalysisPeriod []>> analysisPeriods;
85 90
86 protected List<KMIndex<QWD[]>> referenceEvents; 91 protected List<KMIndex<QWD[]>> referenceEvents;
87 92
118 writeCSVHeader(writer); 123 writeCSVHeader(writer);
119 124
120 NumberFormat kmF = getKMFormatter(); 125 NumberFormat kmF = getKMFormatter();
121 NumberFormat dwF = getDeltaWFormatter(); 126 NumberFormat dwF = getDeltaWFormatter();
122 NumberFormat qF = getQFormatter(); 127 NumberFormat qF = getQFormatter();
123 128 NumberFormat wF = getWFormatter();
124 CallMeta meta = context.getMeta(); 129
125 Locale locale = Resources.getLocale(meta); 130 DateFormat dF = getDateFormatter();
126 DateFormat dF = DateFormat.getDateInstance(DateFormat.SHORT, locale);
127 131
128 String referenceS = getReference(); 132 String referenceS = getReference();
129 133
130 for (KMIndex<QWD[]> reference: referenceEvents) { 134 for (KMIndex<QWD[]> reference: referenceEvents) {
131 135
132 for (KMIndex.Entry<QWD[]> kmEntry: reference) { 136 for (KMIndex.Entry<QWD[]> kmEntry: reference) {
133 137
134 String kmS = kmF.format(kmEntry.getKm()); 138 String kmS = kmF.format(kmEntry.getKm());
135 for (QWD qwd: kmEntry.getValue()) { 139 for (QWD qwd: kmEntry.getValue()) {
136 String desc = qwd.getDescription();
137 String deltaWS = dwF.format(qwd.getDeltaW()); 140 String deltaWS = dwF.format(qwd.getDeltaW());
138 String qS = qF.format(qwd.getQ()); 141 String qS = qF.format(qwd.getQ());
142 String wS = wF.format(qwd.getW());
139 String dateS = dF.format(qwd.getDate()); 143 String dateS = dF.format(qwd.getDate());
140 144
141 writer.writeNext(new String[] { 145 writer.writeNext(new String[] {
142 kmS, 146 kmS,
147 qS,
148 wS,
143 referenceS, 149 referenceS,
144 deltaWS,
145 qS,
146 dateS, 150 dateS,
147 desc != null ? desc : "" }); 151 deltaWS
152 });
148 } 153 }
149 } 154 }
150 } 155 }
151 156
152 if (debug) { 157 if (debug) {
168 173
169 for (AnalysisPeriod period: kmEntry.getValue()) { 174 for (AnalysisPeriod period: kmEntry.getValue()) {
170 QWD [] qwds = period.getQWDs(); 175 QWD [] qwds = period.getQWDs();
171 if (qwds != null) { 176 if (qwds != null) {
172 for (QWD qwd: qwds) { 177 for (QWD qwd: qwds) {
173 String desc = qwd.getDescription();
174 String deltaWS = dwF.format(qwd.getDeltaW()); 178 String deltaWS = dwF.format(qwd.getDeltaW());
175 String qS = qF.format(qwd.getQ()); 179 String qS = qF.format(qwd.getQ());
180 String wS = wF.format(qwd.getW());
176 String dateS = dF.format(qwd.getDate()); 181 String dateS = dF.format(qwd.getDate());
177 182
178 writer.writeNext(new String[] { 183 writer.writeNext(new String[] {
179 kmS, 184 kmS,
185 qS,
186 wS,
180 analyisS, 187 analyisS,
181 deltaWS,
182 qS,
183 dateS, 188 dateS,
184 desc != null ? desc : "" }); 189 deltaWS });
185 } 190 }
186 } 191 }
187 } 192 }
188 ++analysisCount; 193 ++analysisCount;
189 } 194 }
213 218
214 protected NumberFormat getQFormatter() { 219 protected NumberFormat getQFormatter() {
215 return Formatter.getFixDeltaWQ(context); 220 return Formatter.getFixDeltaWQ(context);
216 } 221 }
217 222
223 protected NumberFormat getWFormatter() {
224 return Formatter.getFixDeltaWW(context);
225 }
226
227 protected DateFormat getDateFormatter() {
228 CallMeta meta = context.getMeta();
229 return Formatter.getDateFormatter(
230 meta,
231 Resources.getMsg(
232 meta,
233 CSV_T_FORMAT,
234 DEFAULT_CSV_T_FORMAT));
235 }
236
218 protected void writeCSVHeader(CSVWriter writer) { 237 protected void writeCSVHeader(CSVWriter writer) {
219 log.debug("DeltaWtExporter.writeCSVHeader"); 238 log.debug("DeltaWtExporter.writeCSVHeader");
220 239
221 writer.writeNext(new String[] { 240 writer.writeNext(new String[] {
222 msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), 241 msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER),
242 msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER),
243 msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER),
223 msg(CSV_TRANGE_HEADER, DEFAULT_CSV_TRANGE_DESC_HEADER), 244 msg(CSV_TRANGE_HEADER, DEFAULT_CSV_TRANGE_DESC_HEADER),
224 msg(CSV_DELTA_W_HEADER, DEFAULT_CSV_DELTA_W_HEADER),
225 msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER),
226 msg(CSV_T_HEADER, DEFAULT_CSV_T_HEADER), 245 msg(CSV_T_HEADER, DEFAULT_CSV_T_HEADER),
227 msg(CSV_T_DESC_HEADER, DEFAULT_CSV_T_DESC_HEADER) 246 msg(CSV_DELTA_W_HEADER, DEFAULT_CSV_DELTA_W_HEADER)
228 }); 247 });
229 } 248 }
230 249
231 @Override 250 @Override
232 protected void writePDF(OutputStream out) { 251 protected void writePDF(OutputStream out) {

http://dive4elements.wald.intevation.org