Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java @ 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 | 4cccbd32b680 |
children |
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); } /**