Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalcOverviewResult.java @ 9265:e5367900dd6d
Small cleanup concerning getPoints
Adding validStations as dataItem to flood duration calculation
Flood duration now km aware
author | gernotbelger |
---|---|
date | Tue, 17 Jul 2018 19:48:28 +0200 |
parents | 3dae6b78e1da |
children | d194c5b24bf8 |
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 | |
9265 | 15 import org.apache.commons.collections.Predicate; |
9150 | 16 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; |
17 import org.dive4elements.river.artifacts.common.ExportContextCSV; | |
9195 | 18 import org.dive4elements.river.artifacts.common.ExportContextPDF; |
9150 | 19 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
|
20 import org.dive4elements.river.artifacts.common.IResultType; |
9150 | 21 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
22 import org.dive4elements.river.artifacts.common.ResultRow; | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
23 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
9150 | 24 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
25 | |
26 /** | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
27 * Contains the results of a {@link CollisionCalculation}. |
9150 | 28 * |
29 * @author Gernot Belger | |
30 */ | |
9195 | 31 final public class CollisionCalcOverviewResult extends AbstractCalculationExportableResult { |
9150 | 32 |
33 private static final long serialVersionUID = 1L; | |
34 | |
35 private static final String JASPER_FILE = "/jasper/templates/sinfo.collision.overview.jrxml"; | |
36 | |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
37 private final int[] singleYears; |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
38 |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
39 public CollisionCalcOverviewResult(final String label, final int[] singleYears, final Collection<ResultRow> rows) { |
9150 | 40 super(label, rows); |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
41 this.singleYears = singleYears; |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
42 } |
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 public int[] getSingleYears() { |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
45 return this.singleYears; |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
46 } |
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
47 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9204
diff
changeset
|
48 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
|
49 |
9265 | 50 final Predicate filter = new Predicate() { |
51 @Override | |
52 public boolean evaluate(final Object object) { | |
53 final ResultRow row = (ResultRow) object; | |
54 return getSingleYears() == null || Integer.valueOf(row.getValue(SInfoResultType.years).toString()) == year; | |
55 } | |
56 }; | |
9204
4f411c6ee3ae
Individual facets/themes for single years i the S-Info collisions output
mschaefer
parents:
9195
diff
changeset
|
57 |
9265 | 58 return getPoints(GeneralResultType.station, type, filter); |
9150 | 59 } |
60 | |
61 @Override | |
9195 | 62 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { |
9172 | 63 // do nothing so far |
9150 | 64 } |
65 | |
66 @Override | |
9195 | 67 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) { |
9171 | 68 final int colSize = 3; |
69 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
|
70 // geschrieben wird. |
9171 | 71 // Das ist etwas doof. |
9150 | 72 |
9171 | 73 final Collection<String> header = new ArrayList<>(colSize); |
9150 | 74 |
75 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
76 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.years)); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
77 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.collisionCount)); |
9150 | 78 |
9171 | 79 exportContextCSV.writeCSVLine(header.toArray(new String[colSize])); |
9150 | 80 } |
81 | |
82 @Override | |
9195 | 83 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
84 return formatRow(exportContextCSV, row); | |
9150 | 85 } |
86 | |
87 @Override | |
9195 | 88 protected String[] formatPDFRow(final ExportContextPDF exportContextPDF, final ResultRow row) { |
89 | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
90 final Collection<String> lines = new ArrayList<>(3); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
91 |
9195 | 92 lines.add(exportContextPDF.formatRowValue(row, GeneralResultType.station)); |
93 lines.add(exportContextPDF.formatRowValue(row, SInfoResultType.years)); | |
94 lines.add(exportContextPDF.formatRowValue(row, SInfoResultType.collisionCount)); | |
95 | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
96 return lines.toArray(new String[lines.size()]); |
9150 | 97 } |
98 | |
9195 | 99 private String[] formatRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
9150 | 100 |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
101 final Collection<String> lines = new ArrayList<>(3); |
9150 | 102 |
103 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
104 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.years)); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
105 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.collisionCount)); |
9150 | 106 |
107 return lines.toArray(new String[lines.size()]); | |
108 } | |
109 | |
110 @Override | |
111 protected String getJasperFile() { | |
112 return JASPER_FILE; | |
113 } | |
114 | |
115 @Override | |
9195 | 116 protected void addJRTableHeader(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) { |
9150 | 117 |
118 /* column headings */ | |
9195 | 119 exportContext.addJRMetadata(source, "station_header", GeneralResultType.station); |
120 exportContext.addJRMetadata(source, "collision_years_header", SInfoResultType.years); | |
121 exportContext.addJRMetadata(source, "collision_count_header", SInfoResultType.collisionCount); | |
9150 | 122 } |
123 } |