comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalculation.java @ 9318:7b2b086e45f0

collision pdf details, ResultType refactoring, bezugswst result
author gernotbelger
date Fri, 27 Jul 2018 10:11:23 +0200
parents 4f411c6ee3ae
children 504f63512379
comparison
equal deleted inserted replaced
9317:61b5de0b673b 9318:7b2b086e45f0
67 final Collection<ResultRow> overViewRows = new ArrayList<>(); 67 final Collection<ResultRow> overViewRows = new ArrayList<>();
68 68
69 if (access.getYears() != null) { 69 if (access.getYears() != null) {
70 for (final int year : access.getYears()) 70 for (final int year : access.getYears())
71 calculateOverview(overViewRows, river, access.getLowerKm(), access.getUpperKm(), year, year, false); 71 calculateOverview(overViewRows, river, access.getLowerKm(), access.getUpperKm(), year, year, false);
72 } 72 } else {
73 else {
74 for (final DateRange dr : access.getEpochs()) 73 for (final DateRange dr : access.getEpochs())
75 calculateOverview(overViewRows, river, access.getLowerKm(), access.getUpperKm(), dr.getFromYear(), dr.getToYear(), true); 74 calculateOverview(overViewRows, river, access.getLowerKm(), access.getUpperKm(), dr.getFromYear(), dr.getToYear(), true);
76 } 75 }
77 final CollisionCalcOverviewResult overviewResult = new CollisionCalcOverviewResult(access.getYearsHeader(), access.getYears(), overViewRows); 76 final CollisionCalcOverviewResult overviewResult = new CollisionCalcOverviewResult(access.getYearsHeader(), access.getYears(), overViewRows);
78 results.addResult(overviewResult, problems); 77 results.addResult(overviewResult, problems);
89 88
90 // calculate secondary results for each year or epoch 89 // calculate secondary results for each year or epoch
91 if (access.getYears() != null) { 90 if (access.getYears() != null) {
92 for (final int year : access.getYears()) 91 for (final int year : access.getYears())
93 calculateDetails(detailsRows, infoProvider, access.getLowerKm(), access.getUpperKm(), year, year, qFinders, zoneFinders); 92 calculateDetails(detailsRows, infoProvider, access.getLowerKm(), access.getUpperKm(), year, year, qFinders, zoneFinders);
94 } 93 } else {
95 else {
96 for (final DateRange dr : access.getEpochs()) 94 for (final DateRange dr : access.getEpochs())
97 calculateDetails(detailsRows, infoProvider, access.getLowerKm(), access.getUpperKm(), dr.getFromYear(), dr.getToYear(), qFinders, zoneFinders); 95 calculateDetails(detailsRows, infoProvider, access.getLowerKm(), access.getUpperKm(), dr.getFromYear(), dr.getToYear(), qFinders, zoneFinders);
98 } 96 }
99 final CollisionCalcDetailResult detailResult = new CollisionCalcDetailResult("Details", detailsRows); 97 final CollisionCalcDetailResult detailResult = new CollisionCalcDetailResult("Details", detailsRows);
100 results.addResult(detailResult, problems); 98 results.addResult(detailResult, problems);
108 */ 106 */
109 private void calculateOverview(final Collection<ResultRow> rows, final River river, final double fromKm, final double toKm, final int fromYear, 107 private void calculateOverview(final Collection<ResultRow> rows, final River river, final double fromKm, final double toKm, final int fromYear,
110 final int toYear, final boolean isEpoch) { 108 final int toYear, final boolean isEpoch) {
111 for (final CollisionAggregateValue aggregate : CollisionAggregateValue.getValuesByKm(river, fromKm, toKm, fromYear, toYear)) { 109 for (final CollisionAggregateValue aggregate : CollisionAggregateValue.getValuesByKm(river, fromKm, toKm, fromYear, toYear)) {
112 rows.add(ResultRow.create().putValue(GeneralResultType.station, aggregate.getStation()) 110 rows.add(ResultRow.create().putValue(GeneralResultType.station, aggregate.getStation())
113 .putValue(SInfoResultType.years, (isEpoch? String.format("%d-%d", fromYear, toYear) : Integer.toString(fromYear))) 111 .putValue(SInfoResultType.years, (isEpoch ? String.format("%d-%d", fromYear, toYear) : Integer.toString(fromYear)))
114 .putValue(SInfoResultType.collisionCount, aggregate.getCount())); 112 .putValue(SInfoResultType.collisionCount, aggregate.getCount()));
115 } 113 }
116 } 114 }
117 115
118 /** 116 /**
119 * Calculates the collision details for a km range of a river and a year or year range (epoch), 117 * Calculates the collision details for a km range of a river and a year or year range (epoch),
120 * and adds them to a ResultRow collection 118 * and adds them to a ResultRow collection
121 */ 119 */
122 private void calculateDetails(final Collection<ResultRow> rows, final RiverInfoProvider riverInfo, final double fromKm, final double toKm, 120 private void calculateDetails(final Collection<ResultRow> rows, final RiverInfoProvider riverInfo, final double fromKm, final double toKm,
123 final int fromYear, final int toYear, final Map<Gauge, GaugeDischargeValuesFinder> qFinders, 121 final int fromYear, final int toYear, final Map<Gauge, GaugeDischargeValuesFinder> qFinders, final Map<Gauge, GaugeMainValueFinder> zoneFinders) {
124 final Map<Gauge, GaugeMainValueFinder> zoneFinders) {
125 for (final CollisionValue collision : CollisionValue.getValues(riverInfo.getRiver(), fromKm, toKm, DateUtil.getStartDateFromYear(fromYear), 122 for (final CollisionValue collision : CollisionValue.getValues(riverInfo.getRiver(), fromKm, toKm, DateUtil.getStartDateFromYear(fromYear),
126 DateUtil.getEndDateFromYear(toYear))) { 123 DateUtil.getEndDateFromYear(toYear))) {
127 final Gauge gauge = riverInfo.getGauge(collision.getStation(), true); 124 final Gauge gauge = riverInfo.getGauge(collision.getStation(), true);
128 final double q = qFinders.get(gauge).getDischarge(collision.getGaugeW()); 125 final double q = qFinders.get(gauge).getDischarge(collision.getGaugeW());
129 final double qOut = Double.isInfinite(q) ? Double.NaN : q; 126 final double qOut = Double.isInfinite(q) ? Double.NaN : q;
130 rows.add(ResultRow.create().putValue(GeneralResultType.station, collision.getStation()) 127 rows.add(ResultRow.create().putValue(GeneralResultType.station, collision.getStation())
131 .putValue(GeneralResultType.date, collision.getEventDate()) 128 .putValue(GeneralResultType.dateShort, collision.getEventDate()).putValue(SInfoResultType.collisionGaugeW, collision.getGaugeW())
132 .putValue(SInfoResultType.collisionGaugeW, collision.getGaugeW()) 129 .putValue(GeneralResultType.gaugeLabelCm, collision.getGaugeName()).putValue(SInfoResultType.dischargeLong, qOut)
133 .putValue(SInfoResultType.gaugeLabel, collision.getGaugeName())
134 .putValue(SInfoResultType.discharge, qOut)
135 .putValue(SInfoResultType.dischargeZone, zoneFinders.get(gauge).findZoneName(q))); 130 .putValue(SInfoResultType.dischargeZone, zoneFinders.get(gauge).findZoneName(q)));
136 } 131 }
137 } 132 }
138 } 133 }

http://dive4elements.wald.intevation.org