Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9205:3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
author | gernotbelger |
---|---|
date | Mon, 02 Jul 2018 19:01:09 +0200 |
parents | b4402594213b |
children | 0fc9c82e744e |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java Mon Jul 02 17:40:39 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java Mon Jul 02 19:01:09 2018 +0200 @@ -32,6 +32,7 @@ import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; import org.dive4elements.river.artifacts.sinfo.common.WQBaseTableFinder; import org.dive4elements.river.artifacts.sinfo.flood_duration.RiversideRadioChoice.RiversideChoiceKey; +import org.dive4elements.river.exports.WaterlevelDescriptionBuilder; import org.dive4elements.river.model.Attribute.AttributeKey; import org.dive4elements.river.model.Gauge; import org.dive4elements.river.model.MainValueType.MainValueTypeKey; @@ -53,7 +54,6 @@ private final CallContext context; - public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) { this.context = context; this.riverInfoProvider = riverInfoProvider; @@ -97,10 +97,12 @@ final WQBaseTableFinder wqFinder = WQBaseTableFinder.loadValues(this.riverInfoProvider.getRiver(), calcRange.getMinimumDouble(), calcRange.getMaximumDouble(), problems); + final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder(winfo, this.context); + // Calculate the durations and create the result rows for (int i = 0; i <= stationsSorted.length - 1; i++) { final Gauge gauge = this.riverInfoProvider.getGauge(stationsSorted[i], true); - final ResultRow row = createRow(stationsSorted[i], gauge, wqkmsArray, durFinders.get(gauge), i); + final ResultRow row = createRow(descBuilder, stationsSorted[i], gauge, wqkmsArray, durFinders.get(gauge), i); if (allStations.containsKey(stationsSorted[i]) && (allStations.get(stationsSorted[i]) != null)) calculateInfrastructure(row, gauge, allStations.get(stationsSorted[i]), wqFinder, durFinders); this.rows.add(row); @@ -190,7 +192,9 @@ /** * Determines the discharge state labels for the selected Q or W values */ + // FIXME: use WaterlevelDescriptionBuilder instead! private String[] findMainValueLabels(final WQKms[] wqkmsArray, final double[] qs, final Gauge gauge, final Calculation problems) { + final String[] mainValueLabels = new String[wqkmsArray.length]; if (wqkmsArray.length >= 1) { // Labels like Q=123 or W=123 @@ -208,44 +212,46 @@ /** * Create a result row for a station and its gauge, and add w-q-values as selected + * + * @param descBuilder */ - private ResultRow createRow(final Double station, final Gauge gauge, final WQKms[] wqkmsArray, + private ResultRow createRow(final WaterlevelDescriptionBuilder descBuilder, final Double station, final Gauge gauge, final WQKms[] wqkmsArray, final GaugeDurationValuesFinder durationFinder, final int kmIndex) { final ResultRow row = ResultRow.create(); row.putValue(GeneralResultType.station, station); row.putValue(SInfoResultType.infrastructuretype, null); // is replaced later for an infrastructure row.putValue(SInfoResultType.floodDuration, Double.NaN); // is replaced later for an infrastructure - row.putValue(SInfoResultType.gaugeLabel, gauge.getName()); + + // row.putValue(SInfoResultType.gaugeLabel, gauge.getName()); + final String gaugeLabel = this.riverInfoProvider.findGauge(station); + row.putValue(SInfoResultType.gaugeLabel, gaugeLabel); + final String location = this.riverInfoProvider.getLocation(station); row.putValue(SInfoResultType.location, location); - if (wqkmsArray.length >= 1) { - assert (wqkmsArray[0].getKm(kmIndex) == station.doubleValue()); - row.putValue(SInfoResultType.waterlevel1, wqkmsArray[0].getW(kmIndex)); - row.putValue(SInfoResultType.discharge1, wqkmsArray[0].getQ(kmIndex)); - row.putValue(SInfoResultType.mainValue1Duration, underflowDaysToOverflowDays(durationFinder.getDuration(wqkmsArray[0].getQ(kmIndex)))); - if (wqkmsArray.length >= 2) { - assert (wqkmsArray[1].getKm(kmIndex) == station.doubleValue()); - row.putValue(SInfoResultType.waterlevel2, wqkmsArray[1].getW(kmIndex)); - row.putValue(SInfoResultType.discharge2, wqkmsArray[1].getQ(kmIndex)); - row.putValue(SInfoResultType.mainValue2Duration, underflowDaysToOverflowDays(durationFinder.getDuration(wqkmsArray[1].getQ(kmIndex)))); - if (wqkmsArray.length >= 3) { - assert (wqkmsArray[2].getKm(kmIndex) == station.doubleValue()); - row.putValue(SInfoResultType.waterlevel3, wqkmsArray[2].getW(kmIndex)); - row.putValue(SInfoResultType.discharge3, wqkmsArray[2].getQ(kmIndex)); - row.putValue(SInfoResultType.mainValue3Duration, underflowDaysToOverflowDays(durationFinder.getDuration(wqkmsArray[2].getQ(kmIndex)))); - } - } + final List<DurationWaterlevel> waterlevels = new ArrayList<>(wqkmsArray.length); + + for (final WQKms wqKm : wqkmsArray) { + assert (wqKm.getKm(kmIndex) == station.doubleValue()); + + final int overflowDays = (int) Math.round(underflowDaysToOverflowDays(durationFinder.getDuration(wqKm.getQ(kmIndex)))); + + final String waterlevelLabel = descBuilder.getDesc(wqKm); + + final DurationWaterlevel dw = new DurationWaterlevel(wqKm.getW(kmIndex), overflowDays, wqKm.getQ(kmIndex), waterlevelLabel); + waterlevels.add(dw); } + row.putValue(SInfoResultType.customMultiRowColWaterlevel, waterlevels); + return row; } /** * Calculate the result row fields for one infrastructure */ - private void calculateInfrastructure(final ResultRow row, final Gauge gauge, final InfrastructureValue infrastructure, - final WQBaseTableFinder wqFinder, final Map<Gauge, GaugeDurationValuesFinder> durFinders) { + private void calculateInfrastructure(final ResultRow row, final Gauge gauge, final InfrastructureValue infrastructure, final WQBaseTableFinder wqFinder, + final Map<Gauge, GaugeDurationValuesFinder> durFinders) { final double q = wqFinder.getDischarge(infrastructure.getStation(), infrastructure.getHeight()); final double qOut = Double.isInfinite(q) ? Double.NaN : q;