Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcOverviewResult.java @ 9204:4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
author | mschaefer |
---|---|
date | Mon, 02 Jul 2018 17:40:39 +0200 |
parents | a4121ec450d6 |
children | 3dae6b78e1da |
rev | line source |
---|---|
9150 | 1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.sinfo.collision; | |
11 | |
12 import java.util.ArrayList; | |
13 import java.util.Collection; | |
14 | |
15 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; | |
16 import org.dive4elements.river.artifacts.common.ExportContextCSV; | |
9195 | 17 import org.dive4elements.river.artifacts.common.ExportContextPDF; |
9150 | 18 import org.dive4elements.river.artifacts.common.GeneralResultType; |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
19 import org.dive4elements.river.artifacts.common.IResultType; |
9150 | 20 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
21 import org.dive4elements.river.artifacts.common.ResultRow; | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
9150 | 23 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
24 | |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
25 import gnu.trove.TDoubleArrayList; |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
26 |
9150 | 27 /** |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
28 * Contains the results of a {@link CollisionCalculation}. |
9150 | 29 * |
30 * @author Gernot Belger | |
31 */ | |
9195 | 32 final public class CollisionCalcOverviewResult extends AbstractCalculationExportableResult { |
9150 | 33 |
34 private static final long serialVersionUID = 1L; | |
35 | |
36 private static final String JASPER_FILE = "/jasper/templates/sinfo.collision.overview.jrxml"; | |
37 | |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
38 private final int[] singleYears; |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
39 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
40 public CollisionCalcOverviewResult(final String label, final int[] singleYears, final Collection<ResultRow> rows) { |
9150 | 41 super(label, rows); |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
42 this.singleYears = singleYears; |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
43 } |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
44 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
45 public int[] getSingleYears() { |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
46 return this.singleYears; |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
47 } |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
48 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
49 @Override |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
50 public double[][] getStationPoints(final IResultType type, final int index) { |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
51 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
52 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
53 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
54 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
55 for (final ResultRow row : this.rows) { |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
56 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
57 if ((this.singleYears == null) || (Integer.valueOf(row.getValue(SInfoResultType.years).toString()) == this.singleYears[index])) { |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
58 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
59 final double station = row.getDoubleValue(GeneralResultType.station); |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
60 final double value = row.getDoubleValue(type); |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
61 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
62 xPoints.add(station); |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
63 yPoints.add(value); |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
64 } |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
65 } |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
66 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
67 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; |
9150 | 68 } |
69 | |
70 @Override | |
9195 | 71 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { |
9172 | 72 // do nothing so far |
9150 | 73 } |
74 | |
75 @Override | |
9195 | 76 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) { |
9171 | 77 final int colSize = 3; |
78 exportContextCSV.writeTitleForTabs("sinfo.export.csv.title.collison.overview", 3); // Voraussetzung für Tabs ist, dass der Titel vor den Headern | |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
79 // geschrieben wird. |
9171 | 80 // Das ist etwas doof. |
9150 | 81 |
9171 | 82 final Collection<String> header = new ArrayList<>(colSize); |
9150 | 83 |
84 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
85 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.years)); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
86 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.collisionCount)); |
9150 | 87 |
9171 | 88 exportContextCSV.writeCSVLine(header.toArray(new String[colSize])); |
9150 | 89 } |
90 | |
91 @Override | |
9195 | 92 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
93 return formatRow(exportContextCSV, row); | |
9150 | 94 } |
95 | |
96 @Override | |
9195 | 97 protected String[] formatPDFRow(final ExportContextPDF exportContextPDF, final ResultRow row) { |
98 | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
99 final Collection<String> lines = new ArrayList<>(3); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
100 |
9195 | 101 lines.add(exportContextPDF.formatRowValue(row, GeneralResultType.station)); |
102 lines.add(exportContextPDF.formatRowValue(row, SInfoResultType.years)); | |
103 lines.add(exportContextPDF.formatRowValue(row, SInfoResultType.collisionCount)); | |
104 | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
105 return lines.toArray(new String[lines.size()]); |
9150 | 106 } |
107 | |
9195 | 108 private String[] formatRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
9150 | 109 |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
110 final Collection<String> lines = new ArrayList<>(3); |
9150 | 111 |
112 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
113 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.years)); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
114 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.collisionCount)); |
9150 | 115 |
116 return lines.toArray(new String[lines.size()]); | |
117 } | |
118 | |
119 @Override | |
120 protected String getJasperFile() { | |
121 return JASPER_FILE; | |
122 } | |
123 | |
124 @Override | |
9195 | 125 protected void addJRTableHeader(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) { |
9150 | 126 |
127 /* column headings */ | |
9195 | 128 exportContext.addJRMetadata(source, "station_header", GeneralResultType.station); |
129 exportContext.addJRMetadata(source, "collision_years_header", SInfoResultType.years); | |
130 exportContext.addJRMetadata(source, "collision_count_header", SInfoResultType.collisionCount); | |
9150 | 131 } |
132 } |