Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalculation.java @ 9533:d9fda7af24ca
No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
author | mschaefer |
---|---|
date | Thu, 04 Oct 2018 12:48:57 +0200 |
parents | 853f2dafc16e |
children | 0c114309d2a0 |
comparison
equal
deleted
inserted
replaced
9532:8e6b9cb9486a | 9533:d9fda7af24ca |
---|---|
22 import org.dive4elements.river.artifacts.common.GeneralResultType; | 22 import org.dive4elements.river.artifacts.common.GeneralResultType; |
23 import org.dive4elements.river.artifacts.common.ResultRow; | 23 import org.dive4elements.river.artifacts.common.ResultRow; |
24 import org.dive4elements.river.artifacts.model.Calculation; | 24 import org.dive4elements.river.artifacts.model.Calculation; |
25 import org.dive4elements.river.artifacts.model.CalculationResult; | 25 import org.dive4elements.river.artifacts.model.CalculationResult; |
26 import org.dive4elements.river.artifacts.model.DateRange; | 26 import org.dive4elements.river.artifacts.model.DateRange; |
27 import org.dive4elements.river.artifacts.model.river.RiverInfoProvider; | |
28 import org.dive4elements.river.artifacts.resources.Resources; | 27 import org.dive4elements.river.artifacts.resources.Resources; |
29 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; | 28 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
30 import org.dive4elements.river.artifacts.sinfo.common.GaugeDischargeValuesFinder; | 29 import org.dive4elements.river.artifacts.sinfo.common.GaugeDischargeValuesFinder; |
31 import org.dive4elements.river.artifacts.sinfo.common.GaugeMainValueFinder; | 30 import org.dive4elements.river.artifacts.sinfo.common.GaugeMainValueFinder; |
32 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | 31 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
33 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; | 32 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; |
34 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | 33 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
35 import org.dive4elements.river.backend.utils.DateUtil; | 34 import org.dive4elements.river.backend.utils.DateUtil; |
36 import org.dive4elements.river.model.Gauge; | |
37 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; | 35 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; |
38 import org.dive4elements.river.model.River; | 36 import org.dive4elements.river.model.River; |
39 import org.dive4elements.river.model.sinfo.CollisionAggregateValue; | 37 import org.dive4elements.river.model.sinfo.CollisionAggregateValue; |
40 import org.dive4elements.river.model.sinfo.CollisionValue; | 38 import org.dive4elements.river.model.sinfo.CollisionValue; |
41 | 39 |
86 } | 84 } |
87 final CollisionCalcOverviewResult overviewResult = new CollisionCalcOverviewResult(access.getYearsHeader(), (access.getYears() == null), years, | 85 final CollisionCalcOverviewResult overviewResult = new CollisionCalcOverviewResult(access.getYearsHeader(), (access.getYears() == null), years, |
88 overViewRows); | 86 overViewRows); |
89 results.addResult(overviewResult, problems); | 87 results.addResult(overviewResult, problems); |
90 | 88 |
91 // create q-for-w-finders for all gauges of the calculation km range | 89 // calculate secondary results for each year |
92 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange); | 90 final Map<String, GaugeDischargeValuesFinder> qFinders = new HashMap<>(); |
93 final Map<Gauge, GaugeDischargeValuesFinder> qFinders = new HashMap<>(); | 91 final Map<String, GaugeMainValueFinder> zoneFinders = new HashMap<>(); |
94 final Map<Gauge, GaugeMainValueFinder> zoneFinders = new HashMap<>(); | |
95 for (final Gauge gauge : river.determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble())) { | |
96 qFinders.put(gauge, GaugeDischargeValuesFinder.loadValues(gauge, problems)); | |
97 zoneFinders.put(gauge, GaugeMainValueFinder.loadValues(MainValueTypeKey.Q, gauge, problems)); | |
98 } | |
99 final Collection<ResultRow> detailsRows = new ArrayList<>(); | 92 final Collection<ResultRow> detailsRows = new ArrayList<>(); |
100 | |
101 // calculate secondary results for each year | |
102 for (final Integer year : detailYears) | 93 for (final Integer year : detailYears) |
103 calculateDetails(detailsRows, infoProvider, access.getLowerKm(), access.getUpperKm(), year, qFinders, zoneFinders); | 94 calculateDetails(detailsRows, river, access.getLowerKm(), access.getUpperKm(), year, qFinders, zoneFinders, problems); |
104 final CollisionCalcDetailResult detailResult = new CollisionCalcDetailResult("Details", detailsRows); | 95 final CollisionCalcDetailResult detailResult = new CollisionCalcDetailResult("Details", detailsRows); |
105 results.addResult(detailResult, problems); | 96 results.addResult(detailResult, problems); |
106 | 97 |
107 return new CalculationResult(results, problems); | 98 return new CalculationResult(results, problems); |
108 } | 99 } |
143 } | 134 } |
144 | 135 |
145 /** | 136 /** |
146 * Calculates the collision details for a km range of a river and a year, and adds them to a ResultRow collection | 137 * Calculates the collision details for a km range of a river and a year, and adds them to a ResultRow collection |
147 */ | 138 */ |
148 private void calculateDetails(final Collection<ResultRow> rows, final RiverInfoProvider riverInfo, final double fromKm, final double toKm, | 139 private void calculateDetails(final Collection<ResultRow> rows, final River river, final double fromKm, final double toKm, |
149 final int year, final Map<Gauge, GaugeDischargeValuesFinder> qFinders, final Map<Gauge, GaugeMainValueFinder> zoneFinders) { | 140 final int year, final Map<String, GaugeDischargeValuesFinder> qFinders, final Map<String, GaugeMainValueFinder> zoneFinders, |
150 for (final CollisionValue collision : CollisionValue.getValues(riverInfo.getRiver(), fromKm, toKm, DateUtil.getStartDateFromYear(year), | 141 final Calculation problems) { |
142 | |
143 for (final CollisionValue collision : CollisionValue.getValues(river, fromKm, toKm, DateUtil.getStartDateFromYear(year), | |
151 DateUtil.getEndDateFromYear(year))) { | 144 DateUtil.getEndDateFromYear(year))) { |
152 final Gauge gauge = riverInfo.getGauge(collision.getStation(), true); | 145 final String gaugeName = collision.getGaugeName(); |
153 final double q = qFinders.get(gauge).getDischarge(collision.getGaugeW()); | 146 final double q = getQ(qFinders, gaugeName, collision.getGaugeW().doubleValue(), river, problems); |
154 final double qOut = Double.isInfinite(q) ? Double.NaN : q; | 147 final double qOut = Double.isInfinite(q) ? Double.NaN : q; |
148 final String zone = getZone(zoneFinders, gaugeName, q, river, problems); | |
155 rows.add(ResultRow.create().putValue(GeneralResultType.station, collision.getStation()) | 149 rows.add(ResultRow.create().putValue(GeneralResultType.station, collision.getStation()) |
156 .putValue(GeneralResultType.dateShort, collision.getEventDate()).putValue(SInfoResultType.collisionGaugeW, collision.getGaugeW()) | 150 .putValue(GeneralResultType.dateShort, collision.getEventDate()) |
157 .putValue(GeneralResultType.gaugeLabelCm, collision.getGaugeName()).putValue(SInfoResultType.dischargeLong, qOut) | 151 .putValue(SInfoResultType.collisionGaugeW, collision.getGaugeW()) |
158 .putValue(SInfoResultType.dischargeZone, zoneFinders.get(gauge).findZoneName(q))); | 152 .putValue(GeneralResultType.gaugeLabelCm, gaugeName) |
153 .putValue(SInfoResultType.dischargeLong, qOut) | |
154 .putValue(SInfoResultType.dischargeZone, zone)); | |
159 } | 155 } |
160 } | 156 } |
157 | |
158 /** | |
159 * Gets the discharge of a gauge and a W | |
160 */ | |
161 private double getQ(final Map<String, GaugeDischargeValuesFinder> qFinders, final String gaugeName, final double w, | |
162 final River river, final Calculation problems) { | |
163 // Find the gauge and load its discharge table, if not already in the map | |
164 final String gnKey = gaugeName.toLowerCase(); | |
165 if (!qFinders.containsKey(gnKey)) | |
166 qFinders.put(gnKey, GaugeDischargeValuesFinder.loadValues(river, gaugeName, problems)); | |
167 // Interpolate W. | |
168 if (qFinders.get(gnKey) == null) | |
169 return Double.NaN; | |
170 return qFinders.get(gnKey).getDischarge(w); | |
171 } | |
172 | |
173 /** | |
174 * Gets the main value zone name of a gauge and a Q | |
175 */ | |
176 private String getZone(final Map<String, GaugeMainValueFinder> zoneFinders, final String gaugeName, final double q, | |
177 final River river, final Calculation problems) { | |
178 // Find the gauge and load its main value list, if not already in the map | |
179 final String gnKey = gaugeName.toLowerCase(); | |
180 if (!zoneFinders.containsKey(gnKey)) | |
181 zoneFinders.put(gnKey, GaugeMainValueFinder.loadValues(MainValueTypeKey.Q, river, gaugeName, problems)); | |
182 // Build the zone name | |
183 if (zoneFinders.get(gnKey) == null) | |
184 return ""; | |
185 return zoneFinders.get(gnKey).findZoneName(q); | |
186 } | |
161 } | 187 } |