annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalculation.java @ 9487:504f63512379

Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
author mschaefer
date Tue, 18 Sep 2018 12:21:17 +0200
parents 7b2b086e45f0
children 853f2dafc16e
rev   line source
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
2 * Software engineering by
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
5 *
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
9 */
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
10 package org.dive4elements.river.artifacts.sinfo.collision;
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
11
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
12 import java.util.ArrayList;
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
13 import java.util.Collection;
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
14 import java.util.HashMap;
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
15 import java.util.List;
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
16 import java.util.Map;
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
17 import java.util.NavigableSet;
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
18 import java.util.TreeSet;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
19
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
20 import org.apache.commons.lang.math.DoubleRange;
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
21 import org.dive4elements.artifacts.CallContext;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
22 import org.dive4elements.river.artifacts.common.GeneralResultType;
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
23 import org.dive4elements.river.artifacts.common.ResultRow;
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
24 import org.dive4elements.river.artifacts.model.Calculation;
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
25 import org.dive4elements.river.artifacts.model.CalculationResult;
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
26 import org.dive4elements.river.artifacts.model.DateRange;
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
27 import org.dive4elements.river.artifacts.resources.Resources;
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
28 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9157
diff changeset
29 import org.dive4elements.river.artifacts.sinfo.common.GaugeDischargeValuesFinder;
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
30 import org.dive4elements.river.artifacts.sinfo.common.GaugeMainValueFinder;
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
31 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider;
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
32 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
33 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils;
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
34 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
35 import org.dive4elements.river.backend.utils.DateUtil;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
36 import org.dive4elements.river.model.Gauge;
9176
1614cb14308f Work on calculations for S-Info flood duration workflow
mschaefer
parents: 9157
diff changeset
37 import org.dive4elements.river.model.MainValueType.MainValueTypeKey;
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
38 import org.dive4elements.river.model.River;
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
39 import org.dive4elements.river.model.sinfo.CollisionAggregateValue;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
40 import org.dive4elements.river.model.sinfo.CollisionValue;
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
41
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
42 class CollisionCalculation {
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
43
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
44 // private static Logger log = Logger.getLogger(FloodDurationCalculation.class);
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
45
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
46 private final CallContext context;
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
47
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
48 public CollisionCalculation(final CallContext context) {
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
49 this.context = context;
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
50 }
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
51
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
52 public CalculationResult calculate(final SINFOArtifact sinfo) {
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
53
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
54 final String user = CalculationUtils.findArtifactUser(this.context, sinfo);
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
55
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
56 // access input data
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
57 final CollisionAccess access = new CollisionAccess(sinfo);
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
58 final River river = access.getRiver();
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
59 final RiverInfo riverInfo = new RiverInfo(river);
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
60
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
61 final DoubleRange calcRange = access.getRange();
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
62
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
63 // calculate results for each year or epoch
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
64 final Calculation problems = new Calculation();
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
65
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
66 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name());
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
67
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
68 final CollisionCalculationResults results = new CollisionCalculationResults(calcModeLabel, user, riverInfo, calcRange, access.getYearsHeader());
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
69
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
70 final Collection<ResultRow> overViewRows = new ArrayList<>();
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
71
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
72 final List<DateRange> years = new ArrayList<>();
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
73 final NavigableSet<Integer> detailYears = new TreeSet<>();
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
74 if (access.getYears() != null) {
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
75 for (final int year : access.getYears()) {
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
76 calculateOverview(overViewRows, river, access.getLowerKm(), access.getUpperKm(), year, year, false);
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
77 years.add(new DateRange(DateUtil.getStartDateFromYear(year), DateUtil.getEndDateFromYear(year)));
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
78 detailYears.add(Integer.valueOf(year));
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
79 }
9318
7b2b086e45f0 collision pdf details, ResultType refactoring, bezugswst result
gernotbelger
parents: 9204
diff changeset
80 } else {
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
81 for (final DateRange dr : access.getEpochs()) {
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
82 calculateOverview(overViewRows, river, access.getLowerKm(), access.getUpperKm(), dr.getFromYear(), dr.getToYear(), true);
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
83 years.add(dr);
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
84 detailYearsAdd(detailYears, dr);
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
85 }
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
86 }
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
87 final CollisionCalcOverviewResult overviewResult = new CollisionCalcOverviewResult(access.getYearsHeader(), (access.getYears() == null), years,
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
88 overViewRows);
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
89 results.addResult(overviewResult, problems);
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
90
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
91 // create q-for-w-finders for all gauges of the calculation km range
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
92 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange);
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
93 final Map<Gauge, GaugeDischargeValuesFinder> qFinders = new HashMap<>();
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
94 final Map<Gauge, GaugeMainValueFinder> zoneFinders = new HashMap<>();
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
95 for (final Gauge gauge : river.determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble())) {
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
96 qFinders.put(gauge, GaugeDischargeValuesFinder.loadValues(gauge, problems));
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
97 zoneFinders.put(gauge, GaugeMainValueFinder.loadValues(MainValueTypeKey.Q, gauge, problems));
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
98 }
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
99 final Collection<ResultRow> detailsRows = new ArrayList<>();
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
100
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
101 // calculate secondary results for each year
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
102 for (final Integer year : detailYears)
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
103 calculateDetails(detailsRows, infoProvider, access.getLowerKm(), access.getUpperKm(), year, qFinders, zoneFinders);
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
104 final CollisionCalcDetailResult detailResult = new CollisionCalcDetailResult("Details", detailsRows);
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
105 results.addResult(detailResult, problems);
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
106
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 9067
diff changeset
107 return new CalculationResult(results, problems);
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
108 }
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
109
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
110 /**
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
111 * Adds all years of an epoch to a set
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
112 */
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
113 private void detailYearsAdd(final NavigableSet<Integer> detailYears, final DateRange epoch) {
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
114 for (int year = epoch.getFromYear(); year <= epoch.getToYear(); year++)
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
115 detailYears.add(Integer.valueOf(year));
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
116 }
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
117
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
118 /**
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
119 * Calculates the collision counts for a km range of a river and a year or year range (epoch),
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
120 * and adds them to a ResultRow collection
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
121 */
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
122 private void calculateOverview(final Collection<ResultRow> rows, final River river, final double fromKm, final double toKm, final int fromYear,
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
123 final int toYear, final boolean isEpoch) {
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
124 for (final CollisionAggregateValue aggregate : CollisionAggregateValue.getValuesByKm(river, fromKm, toKm, fromYear, toYear)) {
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
125 rows.add(ResultRow.create().putValue(GeneralResultType.station, aggregate.getStation())
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
126 .putValue(SInfoResultType.years, yearsToString(isEpoch, fromYear, toYear))
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
127 .putValue(SInfoResultType.collisionCount, aggregate.getCount()));
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
128 }
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
129 }
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
130
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
131 /**
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
132 * Returns the string representation of a year or epoch
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
133 */
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
134 public static String yearsToString(final boolean isEpoch, final DateRange years) {
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
135 return yearsToString(isEpoch, years.getFromYear(), years.getToYear());
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
136 }
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
137
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
138 /**
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
139 * Returns the string representation of a year or epoch
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
140 */
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
141 public static String yearsToString(final boolean isEpoch, final int fromYear, final int toYear) {
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
142 return (isEpoch ? String.format("%d-%d", fromYear, toYear) : Integer.toString(fromYear));
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
143 }
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
144
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
145 /**
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
146 * Calculates the collision details for a km range of a river and a year, and adds them to a ResultRow collection
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
147 */
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
148 private void calculateDetails(final Collection<ResultRow> rows, final RiverInfoProvider riverInfo, final double fromKm, final double toKm,
9487
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
149 final int year, final Map<Gauge, GaugeDischargeValuesFinder> qFinders, final Map<Gauge, GaugeMainValueFinder> zoneFinders) {
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
150 for (final CollisionValue collision : CollisionValue.getValues(riverInfo.getRiver(), fromKm, toKm, DateUtil.getStartDateFromYear(year),
504f63512379 Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents: 9318
diff changeset
151 DateUtil.getEndDateFromYear(year))) {
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
152 final Gauge gauge = riverInfo.getGauge(collision.getStation(), true);
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
153 final double q = qFinders.get(gauge).getDischarge(collision.getGaugeW());
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
154 final double qOut = Double.isInfinite(q) ? Double.NaN : q;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
155 rows.add(ResultRow.create().putValue(GeneralResultType.station, collision.getStation())
9318
7b2b086e45f0 collision pdf details, ResultType refactoring, bezugswst result
gernotbelger
parents: 9204
diff changeset
156 .putValue(GeneralResultType.dateShort, collision.getEventDate()).putValue(SInfoResultType.collisionGaugeW, collision.getGaugeW())
7b2b086e45f0 collision pdf details, ResultType refactoring, bezugswst result
gernotbelger
parents: 9204
diff changeset
157 .putValue(GeneralResultType.gaugeLabelCm, collision.getGaugeName()).putValue(SInfoResultType.dischargeLong, qOut)
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9176
diff changeset
158 .putValue(SInfoResultType.dischargeZone, zoneFinders.get(gauge).findZoneName(q)));
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
159 }
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9150
diff changeset
160 }
9067
2ed3824a3d53 sinfo access collision, floodDuration
gernotbelger
parents:
diff changeset
161 }

http://dive4elements.wald.intevation.org