annotate flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedQualityExporter.java @ 3882:8e806d51ebe4

Removed trailing whitespace. flys-artifacts/trunk@5519 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 19 Sep 2012 09:17:14 +0000
parents e7f99e30997c
children 393c10b07a76
rev   line source
3880
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.exports.minfo;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 import gnu.trove.TDoubleArrayList;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 import java.io.IOException;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 import java.io.OutputStream;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import java.text.DateFormat;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 import java.text.NumberFormat;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 import java.util.Arrays;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 import java.util.LinkedList;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import java.util.List;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import org.apache.log4j.Logger;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import org.w3c.dom.Document;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 import au.com.bytecode.opencsv.CSVWriter;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import de.intevation.artifacts.CallContext;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 import de.intevation.flys.artifacts.model.CalculationResult;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 import de.intevation.flys.artifacts.model.minfo.BedDiameterResult;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 import de.intevation.flys.artifacts.model.minfo.BedParametersResult;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 import de.intevation.flys.artifacts.model.minfo.BedQualityResult;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 import de.intevation.flys.artifacts.model.minfo.BedloadDiameterResult;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 import de.intevation.flys.exports.AbstractExporter;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 import de.intevation.flys.utils.Formatter;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 public class BedQualityExporter
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 extends AbstractExporter
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 /** Private logger. */
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 private static Logger logger = Logger.getLogger(BedQualityExporter.class);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 private static final String CSV_HEADER_KM = "export.minfo.bedquality.km";
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 private static final String CSV_HEADER_DENSITY_CAP =
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 "export.minfo.bedquality.density_cap";
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 private static final String CSV_HEADER_DENSITY_SUB =
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 "export.minfo.bedquality.density_sub";
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 private static final String CSV_HEADER_POROSITY_CAP =
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 "export.minfo.bedquality.porosity_cap";
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 private static final String CSV_HEADER_POROSITY_SUB =
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 "export.minfo.bedquality.porosity_sub";
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 private static final String CSV_HEADER_BEDLOAD =
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 "export.minfo.bedquality.bedload";
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 private static final String CSV_HEADER_BED_CAP =
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 "export.minfo.bedquality.bed_cap";
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 private static final String CSV_HEADER_BED_SUB =
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 "export.minfo.bedquality.bed_sub";
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 private BedQualityResult[] results;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 @Override
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 public void init(Document request, OutputStream out, CallContext context) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 logger.debug("BedQualityExporter.init");
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 super.init(request, out, context);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 results = new BedQualityResult[0];
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 @Override
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 protected void writeCSVData(CSVWriter writer) throws IOException {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 // TODO Auto-generated method stub
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 writeCSVHeader(writer);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 TDoubleArrayList kms = new TDoubleArrayList();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 int cols = 1;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 for (int i = 0; i < results.length; i++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 BedDiameterResult[] beds = results[i].getBedResults();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 for (int j = 0; j < beds.length; j++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 TDoubleArrayList bkms = beds[j].getKms();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 for (int k = 0; k < bkms.size(); k++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 if (!kms.contains(bkms.get(k))) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 kms.add(bkms.get(k));
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 BedloadDiameterResult[] loads = results[i].getBedloadResults();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 for (int j = 0; j < loads.length; j++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 TDoubleArrayList lkms = loads[i].getKms();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 for (int k = 0; k < lkms.size(); k++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 if (!kms.contains(lkms.get(k))) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 kms.add(lkms.get(k));
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 cols += beds.length * 2;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 cols += loads.length;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 if (beds.length > 0) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 cols += 4;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93 kms.sort();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 List<double[]> rows = new LinkedList<double[]>();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95 for (int i = 0; i < kms.size(); i++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
96 double[] row = new double[cols];
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97 double km = kms.get(i);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 row[0] = km;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99 for (int j = 0; j < results.length; j++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100 BedloadDiameterResult[] loads = results[j].getBedloadResults();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 for(int k = 0; k < loads.length; k++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 // k + 1: shift km column.
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 // j* loads.length: shift periods.
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 row[(k + 1) + (j * loads.length)] =
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 loads[k].getDiameter(km);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 BedDiameterResult[] beds = results[j].getBedResults();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 for (int k = 0; k < beds.length; k++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 // k + 1: shift km column.
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 // j * beds.length: shift periods.
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 // loads.length * results.length: shift bed load columns.
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 int ndx = (k + 1) + (j * beds.length) + (loads.length * results.length);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 row[ndx] = beds[k].getDiameterCap(km);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
115 row[ndx + 1] = beds[k].getDiameterSub(km);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
117 BedParametersResult[] params = results[j].getParameters();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
118 for(int k = 0; k < params.length; k++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119 // loads.length + (beds.lenght * 2) * (j + 1): shift bed and bedload columns.
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
120 int ndx = 1 + (loads.length + (beds.length * 2) * (j + 1));
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
121 row[ndx] = params[k].getLoadDensityCap(km);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
122 row[ndx + 1] = params[k].getLoadDensitySub(km);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123 row[ndx + 2] = params[k].getPorosityCap(km);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 row[ndx + 3] = params[k].getPorositySub(km);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 rows.add(row);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 for (double[] d : rows) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130 logger.debug(Arrays.toString(d));
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131 List<String> cells = new LinkedList<String>();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
132 for (int i = 0; i < d.length; i++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
133 if (!Double.isNaN(d[i])) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134 NumberFormat nf = Formatter.getFormatter(context, 1, 3);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
135 cells.add(nf.format(d[i]));
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
136 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
137 else {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
138 cells.add("");
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
139 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
140 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
141 writer.writeNext(cells.toArray(new String[cells.size()]));
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
142 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
143 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
144
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
145 @Override
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
146 protected void writePDF(OutputStream out) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
147 // TODO Auto-generated method stub
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
148
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
149 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
150
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
151 @Override
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
152 protected void addData(Object data) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
153 // TODO Auto-generated method stub
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
154 logger.debug("addData()");
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
155 if (!(data instanceof CalculationResult)) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
156 logger.warn("Invalid data type.");
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
157 return;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
158 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
159 Object[] d = (Object[])((CalculationResult)data).getData();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
160
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
161 if (!(d instanceof BedQualityResult[])) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
162 logger.warn("Invalid result object.");
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
163 return;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
164 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
165 results = (BedQualityResult[])d;
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
166 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
167
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
168 protected void writeCSVHeader(CSVWriter writer) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
169 logger.debug("writeCSVHeader()");
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
170
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
171 List<String> header = new LinkedList<String>();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
172 if (results != null) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
173 header.add(msg(CSV_HEADER_KM, "km"));
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
174 for (int i = 0; i < results.length; i++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
175 DateFormat df = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy");
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
176 String d1 = df.format(results[i].getDateRange().getFrom());
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
177 String d2 = df.format(results[i].getDateRange().getTo());
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
178 BedloadDiameterResult[] loads = results[i].getBedloadResults();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
179 BedDiameterResult[] beds = results[i].getBedResults();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
180 BedParametersResult[] params = results[i].getParameters();
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
181 for (int j = 0; j < loads.length; j++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
182 header.add(msg(CSV_HEADER_BEDLOAD, CSV_HEADER_BEDLOAD) +
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
183 " - " +
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
184 msg(loads[j].getType().toString(),
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
185 loads[j].getType().toString()) + " - " +
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
186 d1 + "-" + d2);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
187 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
188 for (int j = 0; j < beds.length; j++) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
189 header.add(msg(CSV_HEADER_BED_CAP, CSV_HEADER_BED_CAP) + " - " +
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
190 msg(beds[j].getType().toString(),
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
191 beds[j].getType().toString()) + " - " +
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
192 d1 + "-" + d2);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
193 header.add(msg(CSV_HEADER_BED_SUB, CSV_HEADER_BED_SUB) + " - " +
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
194 msg(beds[j].getType().toString(),
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
195 beds[j].getType().toString()) + " - " +
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
196 d1 + "-" + d2);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
197 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
198 if (params.length > 0) {
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
199 header.add(
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
200 msg(CSV_HEADER_DENSITY_CAP, CSV_HEADER_DENSITY_CAP));// +
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
201 //" - " + d1 + "-" + d2);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
202 header.add(
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
203 msg(CSV_HEADER_DENSITY_SUB, CSV_HEADER_DENSITY_SUB)); //+
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
204 //" - " + d1 + "-" + d2);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
205 header.add(
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
206 msg(CSV_HEADER_POROSITY_CAP, CSV_HEADER_POROSITY_CAP)); //+
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
207 //" - " + d1 + "-" + d2);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
208 header.add(
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
209 msg(CSV_HEADER_POROSITY_SUB, CSV_HEADER_POROSITY_SUB));// +
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
210 //" - " + d1 + "-" + d2);
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
211 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
212 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
213 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
214 writer.writeNext(header.toArray(new String[header.size()]));
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
215 }
e7f99e30997c Added CSV export to bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
216 }

http://dive4elements.wald.intevation.org