annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java @ 9298:0b1a51b0c42e

Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
author mschaefer
date Wed, 25 Jul 2018 11:33:48 +0200
parents 7100a555607c
children 740d65e4aa14
rev   line source
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
2 * Software engineering by
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
5 *
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
9 */
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
10 package org.dive4elements.river.artifacts.sinfo.flood_duration;
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
11
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
12 import java.text.NumberFormat;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
13 import java.util.ArrayList;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
14 import java.util.Collection;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
15 import java.util.Collections;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
16 import java.util.List;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
17
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
18 import org.apache.commons.collections.Predicate;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
19 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
20 import org.dive4elements.river.artifacts.common.AbstractExportContext;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
21 import org.dive4elements.river.artifacts.common.ExportContextCSV;
9195
a4121ec450d6 'ca.'-issue
gernotbelger
parents: 9176
diff changeset
22 import org.dive4elements.river.artifacts.common.ExportContextPDF;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
23 import org.dive4elements.river.artifacts.common.GeneralResultType;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
24 import org.dive4elements.river.artifacts.common.IResultType;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
25 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
26 import org.dive4elements.river.artifacts.common.ResultRow;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
27 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
28 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
29 import org.dive4elements.river.model.Attribute.AttributeKey;
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
30
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
31 import gnu.trove.TDoubleArrayList;
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
32
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
33 /**
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
34 * Contains the result of a {@link FloodDurationCalculation}.
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
35 *
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
36 * @author Gernot Belger
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
37 */
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
38 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult {
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
39
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
40 private final static class RiversidePredicate implements Predicate {
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
41
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
42 private final AttributeKey riverside;
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
43
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
44 public RiversidePredicate(final AttributeKey riverside) {
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
45 this.riverside = riverside;
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
46 }
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
47
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
48 @Override
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
49 public boolean evaluate(final Object object) {
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
50 final ResultRow row = (ResultRow) object;
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
51
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
52 return row.getValue(SInfoResultType.riverside) == this.riverside;
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
53 }
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
54 }
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
55
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
56 private static final long serialVersionUID = 1L;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
57
9285
9b16f58c62a7 Small cleanup/renames
mschaefer
parents: 9265
diff changeset
58 private final String[] waterlevelLabels;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
59
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
60 private final int maxWaterlevelPdf = 3;
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
61
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
62 public interface ValueGetter {
9215
0fc9c82e744e work on collison, flood_duration
gernotbelger
parents: 9208
diff changeset
63 double getValue(DurationWaterlevel waterlevel);
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
64 }
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
65
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
66 private enum ExportMode {
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
67 pdf, csv
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
68 }
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
69
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
70 public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows) {
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
71 super(label, rows);
9285
9b16f58c62a7 Small cleanup/renames
mschaefer
parents: 9265
diff changeset
72 this.waterlevelLabels = mainvalueLabels;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
73 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
74
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
75 /**
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
76 * Collection of the result rows containing only the rows describing an infrastructure
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
77 */
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
78 // FIXME: bad to override, instead make new method 'getInfrastructureRows' or similar?
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
79 @Override
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
80 public Collection<ResultRow> getRows() {
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
81
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
82 final Collection<ResultRow> rows = super.getRows();
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
83
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
84 final List<ResultRow> infrasOnlyRows = new ArrayList<>();
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
85 for (final ResultRow row : rows) {
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
86 if (row.getValue(SInfoResultType.infrastructuretype) != null)
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
87 infrasOnlyRows.add(row);
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
88 }
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
89 return Collections.unmodifiableCollection(infrasOnlyRows);
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
90 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
91
9298
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
92 /**
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
93 * Collection of all result rows
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
94 */
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
95 public Collection<ResultRow> getAllRows() {
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
96
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
97 return super.getRows();
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
98 }
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
99
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
100 @Override
9195
a4121ec450d6 'ca.'-issue
gernotbelger
parents: 9176
diff changeset
101 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) {
9294
7a8b9331a946 Moved waterlevel metadata block to global metadata, because its only written once
gernotbelger
parents: 9285
diff changeset
102 /* nothing to do, as we never have several results, everything is written into the general header */
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
103 }
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
104
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
105 @Override
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
106 protected String getJasperFile() {
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
107 if (this.getWaterlevelCount() <= 1)
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
108 return "/jasper/templates/sinfo.floodduration.jrxml";
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
109
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
110 return "/jasper/templates/sinfo.floodduration2.jrxml";
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
111 }
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
112
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
113 protected String[] formatRow(final AbstractExportContext exportContextCSV, final ResultRow row, final ExportMode mode) {
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
114
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
115 final Collection<String> lines = new ArrayList<>(10);
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
116
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
117 lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
118 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.riverside));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
119 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
120 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
121 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
122 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
123
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
124 final List<DurationWaterlevel> waterlevelList = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel);
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
125 if (waterlevelList != null) {
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
126 final NumberFormat wFormatter = exportContextCSV.getFlowDepthFormatter();
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
127 final NumberFormat qFormatter = exportContextCSV.getQFormatter();
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
128
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
129 for (int i = 0; i < waterlevelList.size(); i++) {
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
130
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
131 if (i == this.maxWaterlevelPdf && mode == ExportMode.pdf)
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
132 break;
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
133
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
134 final DurationWaterlevel item = waterlevelList.get(i);
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
135 lines.add(item.getWFormatted(wFormatter));
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
136 lines.add(item.getFloodDurDaysPerYearFormatted());
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
137 lines.add(item.getQFormatted(qFormatter));
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
138 lines.add(item.getBezeichnung());
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
139 }
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
140 }
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
141
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
142 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
143 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
144
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
145 return lines.toArray(new String[lines.size()]);
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
146 }
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
147
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
148 @Override
9195
a4121ec450d6 'ca.'-issue
gernotbelger
parents: 9176
diff changeset
149 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
150
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
151 final Collection<String> header = new ArrayList<>(20);
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
152
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
153 header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station));
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
154 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.riverside));
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
155 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.floodDuration));
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
156 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit()));
9297
7100a555607c Small fixes of the S-Info flood duration outputs
mschaefer
parents: 9294
diff changeset
157 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, river.getWstUnit()));
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
158 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype));
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
159
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
160 // add dynamic headers
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
161 final int waterlevelCount = // results.
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
162 getWaterlevelCount();
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
163 for (int i = 0; i < waterlevelCount; i++) {
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
164 final String appendIndex = "_" + Integer.toString(i + 1);
9297
7100a555607c Small fixes of the S-Info flood duration outputs
mschaefer
parents: 9294
diff changeset
165 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderWCsv(), appendIndex, river.getWstUnit()));
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
166 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderFloodDurPerYearCsv(), appendIndex));
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
167 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderQ(), appendIndex));
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
168 header.add(exportContextCSV.msg(DurationWaterlevel.getHeaderBezeichnCsv(), appendIndex));
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
169 }
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
170
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
171 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel));
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
172 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location));
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
173
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
174 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
175 }
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
176
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
177 public List<Double> getValidDurationChartKilometers() {
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
178 return getValues(GeneralResultType.station);
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
179 }
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
180
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
181 @Override
9195
a4121ec450d6 'ca.'-issue
gernotbelger
parents: 9176
diff changeset
182 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
183
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
184 return this.formatRow(exportContextCSV, row, ExportMode.csv);
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
185 }
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
186
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
187 @Override
9195
a4121ec450d6 'ca.'-issue
gernotbelger
parents: 9176
diff changeset
188 protected String[] formatPDFRow(final ExportContextPDF exportContextPDF, final ResultRow row) {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
189
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
190 return this.formatRow(exportContextPDF, row, ExportMode.pdf);
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
191 }
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
192
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
193 @Override
9195
a4121ec450d6 'ca.'-issue
gernotbelger
parents: 9176
diff changeset
194 protected void addJRTableHeader(final ExportContextPDF exportContextPDF, final MetaAndTableJRDataSource source) {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
195
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
196 /* column headings */
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
197 exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station);
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
198 exportContextPDF.addJRMetadata(source, "riverside_header", SInfoResultType.riverside);
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
199 exportContextPDF.addJRMetadata(source, "inundationduration_header", SInfoResultType.floodDuration);
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
200 exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge);
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9195
diff changeset
201 exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeight);
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
202 exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype);
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
203
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
204 for (int i = 1; i <= this.getWaterlevelCount(); i++) {
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
205
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
206 final String appendIndex = "_" + Integer.toString(i);
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
207 exportContextPDF.addJRMetadata(source, getPdfHeader("w", i), exportContextPDF.msg(DurationWaterlevel.getHeaderWPdf(), appendIndex));
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
208 exportContextPDF.addJRMetadata(source, getPdfHeader("duration", i),
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
209 exportContextPDF.msg(DurationWaterlevel.getHeaderFloodDurPerYearPdf(), appendIndex));
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
210 exportContextPDF.addJRMetadata(source, getPdfHeader("q", i), exportContextPDF.msg(DurationWaterlevel.getHeaderQ(), appendIndex));
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
211 exportContextPDF.addJRMetadata(source, getPdfHeader("bezeichnung", i),
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
212 exportContextPDF.msg(DurationWaterlevel.getHeaderBezeichnPdf(), appendIndex));
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
213 }
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
214
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
215 exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel);
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9170
diff changeset
216 exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location);
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9145
diff changeset
217 }
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
218
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
219 private final String getPdfHeader(final String rootStr, final int index) {
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
220 final String hd = "_header";
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
221 final StringBuilder builder = new StringBuilder();
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
222 return builder.append(rootStr).append("_").append(index).append(hd).toString();
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
223 }
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
224
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
225 public final int getWaterlevelCount() {
9285
9b16f58c62a7 Small cleanup/renames
mschaefer
parents: 9265
diff changeset
226 return (this.waterlevelLabels != null) ? this.waterlevelLabels.length : 0;
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
227 }
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
228
9285
9b16f58c62a7 Small cleanup/renames
mschaefer
parents: 9265
diff changeset
229 public String getWaterlevelLabel(final int j) {
9b16f58c62a7 Small cleanup/renames
mschaefer
parents: 9265
diff changeset
230 if (this.waterlevelLabels != null && j < this.waterlevelLabels.length)
9b16f58c62a7 Small cleanup/renames
mschaefer
parents: 9265
diff changeset
231 return this.waterlevelLabels[j];
9205
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
232 return "";
3dae6b78e1da inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents: 9202
diff changeset
233 }
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
234
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
235 /**
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
236 * Gets the longitudinal section of a result value type for one river side
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
237 */
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
238 public final double[][] getInfrastructurePoints(final IResultType type, final AttributeKey riverside) {
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
239 return getPoints(GeneralResultType.station, type, new RiversidePredicate(riverside));
9229
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
240 }
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
241
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
242 /**
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
243 * Gets a longitudinal section of W, Q, or flood duration of one of the waterlevels
0dcd1cd41915 Different themes/facets for left bank and right bank infrastructures in S-Info flood durations, some fixmes done
mschaefer
parents: 9217
diff changeset
244 */
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
245 public final double[][] getMainValueDurationPoints(final ValueGetter valuegetter, final int dataIndex) {
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
246
9298
0b1a51b0c42e Included the infrastructure-less stations in the S-Info flood duration long. sections, and the selected wspls in their w/q duration curves
mschaefer
parents: 9297
diff changeset
247 final Collection<ResultRow> rows = getAllRows();
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
248
9265
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
249 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size());
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
250 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size());
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
251
e5367900dd6d Small cleanup concerning getPoints
gernotbelger
parents: 9236
diff changeset
252 for (final ResultRow row : rows) {
9208
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
253
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
254 final double station = row.getDoubleValue(GeneralResultType.station);
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
255
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
256 final List<DurationWaterlevel> waterlevels = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel);
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
257 final DurationWaterlevel waterlevel = waterlevels.get(dataIndex);
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
258
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
259 final Double value = valuegetter.getValue(waterlevel);
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
260
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
261 xPoints.add(station);
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
262 yPoints.add(value);
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
263 }
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
264
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
265 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
53cc5b496692 funcion replaced by interface
gernotbelger
parents: 9205
diff changeset
266 }
9145
e6b63b2b41b9 sinfo.flood_duration pdf, csv, ui
gernotbelger
parents:
diff changeset
267 }

http://dive4elements.wald.intevation.org