Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalculation.java @ 9613:f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
author | mschaefer |
---|---|
date | Tue, 08 Oct 2019 15:03:24 +0200 |
parents | 8b457ca70512 |
children | 1d4262a68f1f |
rev | line source |
---|---|
9067 | 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 | |
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; |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
14 import java.util.Date; |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
15 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
|
16 import java.util.List; |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
17 import java.util.Map; |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
18 import java.util.Map.Entry; |
9487
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
19 import java.util.NavigableSet; |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
20 import java.util.TreeMap; |
9487
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
21 import java.util.TreeSet; |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
9067
diff
changeset
|
22 |
9067 | 23 import org.apache.commons.lang.math.DoubleRange; |
24 import org.dive4elements.artifacts.CallContext; | |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
9067
diff
changeset
|
25 import org.dive4elements.river.artifacts.common.GeneralResultType; |
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
9067
diff
changeset
|
26 import org.dive4elements.river.artifacts.common.ResultRow; |
9067 | 27 import org.dive4elements.river.artifacts.model.Calculation; |
28 import org.dive4elements.river.artifacts.model.CalculationResult; | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
29 import org.dive4elements.river.artifacts.model.DateRange; |
9067 | 30 import org.dive4elements.river.artifacts.resources.Resources; |
31 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; | |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9157
diff
changeset
|
32 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
|
33 import org.dive4elements.river.artifacts.sinfo.common.GaugeMainValueFinder; |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
34 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
9067 | 35 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; |
36 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
37 import org.dive4elements.river.backend.utils.DateUtil; |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
38 import org.dive4elements.river.model.DischargeTable; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
39 import org.dive4elements.river.model.Gauge; |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
9157
diff
changeset
|
40 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; |
9067 | 41 import org.dive4elements.river.model.River; |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
42 import org.dive4elements.river.model.sinfo.CollisionAggregateValue; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
43 import org.dive4elements.river.model.sinfo.CollisionValue; |
9067 | 44 |
45 class CollisionCalculation { | |
46 | |
47 // private static Logger log = Logger.getLogger(FloodDurationCalculation.class); | |
48 | |
49 private final CallContext context; | |
50 | |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
51 private CollisionAccess access; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
52 private River river; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
53 private List<DateRange> years; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
54 private Calculation problems; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
55 private int qfinderProblemCount; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
56 |
9067 | 57 public CollisionCalculation(final CallContext context) { |
58 this.context = context; | |
59 } | |
60 | |
61 public CalculationResult calculate(final SINFOArtifact sinfo) { | |
62 | |
63 final String user = CalculationUtils.findArtifactUser(this.context, sinfo); | |
64 | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
65 // access input data |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
66 this.access = new CollisionAccess(sinfo); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
67 this.river = this.access.getRiver(); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
68 final RiverInfo riverInfo = new RiverInfo(this.river); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
69 final DoubleRange calcRange = this.access.getRange(); |
9067 | 70 |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
71 // calculate results for each year or epoch |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
72 this.problems = new Calculation(); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
73 this.qfinderProblemCount = 0; |
9067 | 74 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); |
75 | |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
76 final CollisionCalculationResults results = new CollisionCalculationResults(calcModeLabel, user, riverInfo, calcRange, this.access.getYearsHeader()); |
9067 | 77 |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
9067
diff
changeset
|
78 final Collection<ResultRow> overViewRows = new ArrayList<>(); |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
79 |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
80 this.years = new ArrayList<>(); |
9487
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
81 final NavigableSet<Integer> detailYears = new TreeSet<>(); |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
82 if (this.access.getYears() != null) { |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
83 for (final int year : this.access.getYears()) { |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
84 calculateOverview(overViewRows, year, year, false); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
85 this.years.add(new DateRange(DateUtil.getStartDateFromYear(year), DateUtil.getEndDateFromYear(year))); |
9487
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
86 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
|
87 } |
9318
7b2b086e45f0
collision pdf details, ResultType refactoring, bezugswst result
gernotbelger
parents:
9204
diff
changeset
|
88 } else { |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
89 for (final DateRange dr : this.access.getEpochs()) { |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
90 calculateOverview(overViewRows, dr.getFromYear(), dr.getToYear(), true); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
91 this.years.add(dr); |
9487
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
92 detailYearsAdd(detailYears, dr); |
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
93 } |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
94 } |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
95 final CollisionCalcOverviewResult overviewResult = new CollisionCalcOverviewResult(this.access.getYearsHeader(), (this.access.getYears() == null), |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
96 this.years, overViewRows); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
97 results.addResult(overviewResult, this.problems); |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
98 |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
99 // calculate secondary results for each year |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
100 final Map<String, TreeMap<Date, GaugeDischargeValuesFinder>> qFinders = new HashMap<>(); |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
101 final Map<String, GaugeMainValueFinder> zoneFinders = new HashMap<>(); |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
9067
diff
changeset
|
102 final Collection<ResultRow> detailsRows = new ArrayList<>(); |
9487
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
103 for (final Integer year : detailYears) |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
104 calculateDetails(detailsRows, year, qFinders, zoneFinders); |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
9067
diff
changeset
|
105 final CollisionCalcDetailResult detailResult = new CollisionCalcDetailResult("Details", detailsRows); |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
106 results.addResult(detailResult, this.problems); |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
9067
diff
changeset
|
107 |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
108 return new CalculationResult(results, this.problems); |
9067 | 109 } |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
110 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
111 /** |
9487
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
112 * 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
|
113 */ |
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 } |
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
118 |
504f63512379
Sinfo collisions: calculation of multiple epochs, avoiding duplicate collision events in the details report
mschaefer
parents:
9318
diff
changeset
|
119 /** |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
120 * 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
|
121 * and adds them to a ResultRow collection |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
122 */ |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
123 private void calculateOverview(final Collection<ResultRow> rows, final int fromYear, final int toYear, final boolean isEpoch) { |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
124 for (final CollisionAggregateValue aggregate : CollisionAggregateValue.getValuesByKm(this.river, this.access.getLowerKm(), this.access.getUpperKm(), |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
125 fromYear, toYear)) { |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
126 rows.add(ResultRow.create().putValue(GeneralResultType.station, aggregate.getStation()) |
9582 | 127 .putValue(SInfoResultType.years, yearsToString(isEpoch, fromYear, toYear)).putValue(SInfoResultType.collisionCount, aggregate.getCount())); |
9157
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 */ |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
148 private void calculateDetails(final Collection<ResultRow> rows, final int year, final Map<String, TreeMap<Date, GaugeDischargeValuesFinder>> qFinders, |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
149 final Map<String, GaugeMainValueFinder> zoneFinders) { |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
150 |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
151 for (final CollisionValue collision : CollisionValue.getValues(this.river, this.access.getLowerKm(), this.access.getUpperKm(), |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
152 DateUtil.getStartDateFromYear(year), DateUtil.getEndDateFromYear(year))) { |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
153 final String gaugeName = collision.getGaugeName(); |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
154 final double q = getQ(qFinders, gaugeName, collision.getGaugeW().doubleValue(), collision.getEventDate()); |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
155 final double qOut = Double.isInfinite(q) ? Double.NaN : q; |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
156 final String zone = getZone(zoneFinders, gaugeName, q); |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
157 rows.add(ResultRow.create().putValue(GeneralResultType.station, collision.getStation()) |
9582 | 158 .putValue(GeneralResultType.dateShort, collision.getEventDate()).putValue(SInfoResultType.collisionGaugeW, collision.getGaugeW()) |
159 .putValue(GeneralResultType.gaugeLabel, gaugeName).putValue(SInfoResultType.dischargeLong, qOut) | |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
160 .putValue(SInfoResultType.dischargeZone, zone)); |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
161 } |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9150
diff
changeset
|
162 } |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
163 |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
164 /** |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
165 * Gets the discharge of a gauge and a W |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
166 */ |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
167 private double getQ(final Map<String, TreeMap<Date, GaugeDischargeValuesFinder>> qFinders, final String gaugeName, final double w, final Date when) { |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
168 // Find the gauge and load its discharge table, if not already in the map |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
169 final String gnKey = gaugeName.toLowerCase(); |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
170 if (!qFinders.containsKey(gnKey)) |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
171 addQFinders(qFinders, gaugeName); |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
172 // Interpolate W. |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
173 final GaugeDischargeValuesFinder qFinder = getQFinder(qFinders.get(gnKey), when); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
174 if (qFinder == null) { |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
175 this.qfinderProblemCount++; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
176 if (this.qfinderProblemCount == 1) |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
177 this.problems.addProblem("gauge_discharge_table.missing", gaugeName); |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
178 return Double.NaN; |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
179 } |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
180 return qFinder.getDischarge(w); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
181 } |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
182 |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
183 /** |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
184 * Add the discharge finders for a gauge and the active time period |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
185 */ |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
186 private void addQFinders(final Map<String, TreeMap<Date, GaugeDischargeValuesFinder>> qFinders, final String gaugeName) { |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
187 final String gnKey = gaugeName.toLowerCase(); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
188 final Gauge gauge = this.river.determineGaugeByName(gaugeName); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
189 if (gauge == null) { |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
190 qFinders.put(gnKey, new TreeMap<Date, GaugeDischargeValuesFinder>()); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
191 return; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
192 } |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
193 final List<DischargeTable> qtables = DischargeTable.fetchHistoricalDischargeTables(gauge, this.years.get(0).getFrom(), |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
194 this.years.get(this.years.size() - 1).getTo()); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
195 qFinders.put(gnKey, new TreeMap<Date, GaugeDischargeValuesFinder>()); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
196 for (final DischargeTable qtable : qtables) |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
197 qFinders.get(gnKey).put(qtable.getTimeInterval().getStartTime(), |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
198 GaugeDischargeValuesFinder.loadValues(qtable, this.river, gaugeName, this.problems)); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
199 } |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
200 |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
201 /** |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
202 * Searches a q values finder map for a date time |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
203 */ |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
204 private GaugeDischargeValuesFinder getQFinder(final TreeMap<Date, GaugeDischargeValuesFinder> qFinders, final Date when) { |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
205 if (qFinders.containsKey(when)) |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
206 return qFinders.get(when); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
207 final Entry<Date, GaugeDischargeValuesFinder> found = qFinders.floorEntry(when); |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
208 if (found == null) |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
209 return null; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
210 if ((found.getValue().getEndTime() != null) && found.getValue().getEndTime().before(when)) |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
211 return null; |
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
212 return found.getValue(); |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
213 } |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
214 |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
215 /** |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
216 * Gets the main value zone name of a gauge and a Q |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
217 */ |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
218 private String getZone(final Map<String, GaugeMainValueFinder> zoneFinders, final String gaugeName, final double q) { |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
219 // Find the gauge and load its main value list, if not already in the map |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
220 final String gnKey = gaugeName.toLowerCase(); |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
221 if (!zoneFinders.containsKey(gnKey)) |
9613
f2473dc34535
Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
mschaefer
parents:
9582
diff
changeset
|
222 zoneFinders.put(gnKey, GaugeMainValueFinder.loadValues(MainValueTypeKey.Q, this.river, gaugeName, this.problems, "GLQ")); |
9533
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
223 // Build the zone name |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
224 if (zoneFinders.get(gnKey) == null) |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
225 return ""; |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
226 return zoneFinders.get(gnKey).findZoneName(q); |
d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
mschaefer
parents:
9499
diff
changeset
|
227 } |
9067 | 228 } |