Mercurial > dive4elements > river
changeset 9494:879c902c4a2d
Changed main value calculations from calendar year to Abflussjahr, modified time range determination accordingly
author | mschaefer |
---|---|
date | Mon, 24 Sep 2018 18:01:10 +0200 |
parents | 7c3d689294e8 |
children | bb278c927b66 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java |
diffstat | 2 files changed, 40 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java Fri Sep 21 18:19:41 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java Mon Sep 24 18:01:10 2018 +0200 @@ -61,12 +61,14 @@ throws MainValuesServiceException { // Query the gauge's daily Q values - final List<DailyDischargeValue> qdvs = DailyDischargeValue.getValues(gauge, startTime, endTime, OrderByField.DAY); + final Date qStartTime = DateUtils.getAbflussYear(startTime)[0]; + final List<DailyDischargeValue> qdvs = DailyDischargeValue.getValues(gauge, qStartTime, endTime, OrderByField.DAY); if (qdvs.isEmpty()) throw new MainValuesServiceException("no daily discharge values for gauge " + gauge.getName() + " in the requested time period"); // return; // Build yearly aggregates + final Date qYearEnd = DateUtils.getPreviousAbflussYear(endTime)[1]; final TDoubleArrayList mnqs = new TDoubleArrayList(); final TDoubleArrayList mqs = new TDoubleArrayList(); int mqcnt = 0; @@ -87,6 +89,8 @@ mqs.set(j, mqs.get(j) / mqcnt); j++; } + if (qdv.getDay().after(qYearEnd)) + break; // Start next year mnqs.add(qdv.getDischarge().doubleValue()); mhqs.add(qdv.getDischarge().doubleValue()); @@ -115,10 +119,12 @@ if (hsq2 != null) mainValues.add(hsq2); - // Query the gauge's daily Q values and build a list sorted by ascending Q + // Query the gauge's daily Q values from the first new year on, and build a list sorted by ascending Q final TDoubleArrayList qs = new TDoubleArrayList(); - for (final DailyDischargeValue qdv : qdvs) - qs.add(qdv.getDischarge().doubleValue()); + for (final DailyDischargeValue qdv : qdvs) { + if (qdv.getDay().compareTo(startTime) >= 0) + qs.add(qdv.getDischarge().doubleValue()); + } qs.sort(); // Step through the sorted Q list and get the duration discharges @@ -137,14 +143,22 @@ } /** - * Checks year equality of two dates (calendar year) + * Checks year equality of two dates (Abflussjahr) */ private boolean isSameQYear(final Date a, final Date b) { - final Calendar ca = Calendar.getInstance(); - ca.setTime(a); - final Calendar cb = Calendar.getInstance(); - cb.setTime(b); - return (ca.get(Calendar.YEAR) == cb.get(Calendar.YEAR)); + return (qYear(a) == qYear(b)); + } + + /** + * Gets the q year (Abflussjahr) of a date + */ + private int qYear(final Date day) { + final Calendar cal = Calendar.getInstance(); + cal.setTime(day); + if (cal.get(Calendar.MONTH) >= 10) + return cal.get(Calendar.YEAR) + 1; + else + return cal.get(Calendar.YEAR); } /**
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java Fri Sep 21 18:19:41 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java Mon Sep 24 18:01:10 2018 +0200 @@ -60,6 +60,10 @@ private static class GaugeInfo { protected final String errorMsg; protected final Gauge gauge; + /** + * New year of the first year for which the gauge has complete discharge data, including november+december of the year + * before + */ protected final Date startdate; protected final Date enddate; @@ -83,12 +87,13 @@ // Query the gauge's daily Q values String globalErrorMsg = ""; final List<GaugeInfoResult.GaugeInfo> gaugeResults = new ArrayList<>(); - Date min = startTime; + final Date qStartTime = DateUtils.getAbflussYear(startTime)[0]; + Date min = qStartTime; Date max = endTime; for (final Gauge gauge : gauges) { - final Date[] gaugeDates = DailyDischargeValue.getTimePeriod(gauge, startTime, endTime); + final Date[] gaugeDates = DailyDischargeValue.getTimePeriod(gauge, qStartTime, endTime); if (gaugeDates[0] == null) { final String msg = Resources.getMsg(meta, "bundu.wst_no_data_at_all", "bundu.wst_no_data_at_all", gauge.getName()); final GaugeInfoResult.GaugeInfo gi = new GaugeInfoResult.GaugeInfo(msg, gauge, null, null); @@ -98,24 +103,26 @@ continue; } + final Date gaugeCalcStartDate = DateUtils.getNextAbflussYear(gaugeDates[0])[0]; if (gaugeDates[0].getTime() > min.getTime()) - min = gaugeDates[0]; + min = gaugeCalcStartDate; if (gaugeDates[1].getTime() < max.getTime()) max = gaugeDates[1]; String errormsg = null; - if ((gaugeDates[1].getTime() < endTime.getTime()) || (gaugeDates[0].getTime() > startTime.getTime())) - errormsg = makeDoesNotCoverErrorMsg(gaugeDates[0], gaugeDates[1], meta); + if ((gaugeDates[1].getTime() < endTime.getTime()) || (gaugeDates[0].getTime() > qStartTime.getTime())) + errormsg = makeDoesNotCoverErrorMsg(DateUtils.getAbflussYearFromDate(gaugeCalcStartDate), DateUtils.getYearFromDate(gaugeDates[1]), meta); - gaugeResults.add(new GaugeInfoResult.GaugeInfo(errormsg, gauge, gaugeDates[0], gaugeDates[1])); + gaugeResults.add(new GaugeInfoResult.GaugeInfo(errormsg, gauge, DateUtils.getNextNewYear(gaugeCalcStartDate), gaugeDates[1])); } // common Range and correct errorMsg + min = DateUtils.getNextNewYear(min); final List<GaugeInfoResult.GaugeInfo> gaugeResultsSecondTurn = new ArrayList<>(); for (final GaugeInfoResult.GaugeInfo gi : gaugeResults) { gaugeResultsSecondTurn - .add(new GaugeInfoResult.GaugeInfo(gi.errorMsg, gi.gauge, gi.startdate != null ? min : null, gi.enddate != null ? max : null)); + .add(new GaugeInfoResult.GaugeInfo(gi.errorMsg, gi.gauge, gi.startdate != null ? min : null, gi.enddate != null ? max : null)); } if (globalErrorMsg.isEmpty() && (min.getTime() > max.getTime())) globalErrorMsg = getMsg(meta, "bundu.wst.gauge_timeranges_disjoint"); @@ -130,9 +137,9 @@ return result; } - private String makeDoesNotCoverErrorMsg(final Date start, final Date end, final CallMeta meta) { + private String makeDoesNotCoverErrorMsg(final int startYear, final int endYear, final CallMeta meta) { final String msgkey = "bundu.wst.range_does_not_cover"; - return Resources.getMsg(meta, msgkey, msgkey, DateUtils.getYearFromDate(start), DateUtils.getYearFromDate(end)); + return Resources.getMsg(meta, msgkey, msgkey, startYear, endYear); } @Override