annotate flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedQualityExporter.java @ 3880:e7f99e30997c

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

http://dive4elements.wald.intevation.org