Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcOverviewResult.java @ 9205:3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
author | gernotbelger |
---|---|
date | Mon, 02 Jul 2018 19:01:09 +0200 |
parents | 4f411c6ee3ae |
children | e5367900dd6d |
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 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9204
diff
changeset
|
49 public double[][] getStationPointsByYear(final IResultType type, final int year) { |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
50 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
51 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
|
52 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
|
53 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
54 for (final ResultRow row : this.rows) { |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
55 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9204
diff
changeset
|
56 if ((this.singleYears == null) || (Integer.valueOf(row.getValue(SInfoResultType.years).toString()) == year)) { |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
57 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
58 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
|
59 final double value = row.getDoubleValue(type); |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
60 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
61 xPoints.add(station); |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
62 yPoints.add(value); |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
63 } |
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 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; |
9150 | 67 } |
68 | |
69 @Override | |
9195 | 70 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { |
9172 | 71 // do nothing so far |
9150 | 72 } |
73 | |
74 @Override | |
9195 | 75 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) { |
9171 | 76 final int colSize = 3; |
77 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
|
78 // geschrieben wird. |
9171 | 79 // Das ist etwas doof. |
9150 | 80 |
9171 | 81 final Collection<String> header = new ArrayList<>(colSize); |
9150 | 82 |
83 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
84 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.years)); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
85 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.collisionCount)); |
9150 | 86 |
9171 | 87 exportContextCSV.writeCSVLine(header.toArray(new String[colSize])); |
9150 | 88 } |
89 | |
90 @Override | |
9195 | 91 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
92 return formatRow(exportContextCSV, row); | |
9150 | 93 } |
94 | |
95 @Override | |
9195 | 96 protected String[] formatPDFRow(final ExportContextPDF exportContextPDF, final ResultRow row) { |
97 | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
98 final Collection<String> lines = new ArrayList<>(3); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
99 |
9195 | 100 lines.add(exportContextPDF.formatRowValue(row, GeneralResultType.station)); |
101 lines.add(exportContextPDF.formatRowValue(row, SInfoResultType.years)); | |
102 lines.add(exportContextPDF.formatRowValue(row, SInfoResultType.collisionCount)); | |
103 | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
104 return lines.toArray(new String[lines.size()]); |
9150 | 105 } |
106 | |
9195 | 107 private String[] formatRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
9150 | 108 |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
109 final Collection<String> lines = new ArrayList<>(3); |
9150 | 110 |
111 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
112 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.years)); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
113 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.collisionCount)); |
9150 | 114 |
115 return lines.toArray(new String[lines.size()]); | |
116 } | |
117 | |
118 @Override | |
119 protected String getJasperFile() { | |
120 return JASPER_FILE; | |
121 } | |
122 | |
123 @Override | |
9195 | 124 protected void addJRTableHeader(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) { |
9150 | 125 |
126 /* column headings */ | |
9195 | 127 exportContext.addJRMetadata(source, "station_header", GeneralResultType.station); |
128 exportContext.addJRMetadata(source, "collision_years_header", SInfoResultType.years); | |
129 exportContext.addJRMetadata(source, "collision_count_header", SInfoResultType.collisionCount); | |
9150 | 130 } |
131 } |