# HG changeset patch # User gernotbelger # Date 1547117799 -3600 # Node ID c57caff9b00b496615bcbae08a21efdcc989af76 # Parent d116a791b1f8e7a64fbe53a775a4a86973bf8fb9 Punkt 10.6 CSV-Ausgabe Abflusszeitreihenlänge diff -r d116a791b1f8 -r c57caff9b00b artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java Thu Jan 10 09:07:16 2019 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java Thu Jan 10 11:56:39 2019 +0100 @@ -29,6 +29,8 @@ import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult; import org.dive4elements.river.artifacts.model.river.RiverInfoProvider; import org.dive4elements.river.artifacts.resources.Resources; +import org.dive4elements.river.artifacts.services.DynamicMainValuesTimeRangeDeterminationService; +import org.dive4elements.river.artifacts.services.DynamicMainValuesTimeRangeDeterminationService.GaugeInfoResult; import org.dive4elements.river.artifacts.sinfo.tkhstate.BedHeightsFinder; import org.dive4elements.river.artifacts.sinfo.tkhstate.WinfoArtifactWrapper; import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; @@ -85,6 +87,11 @@ this.missKmFrom = access.getMissingVolFrom(); this.missKmTo = access.getMissingVolTo(); + final GaugeInfoResult gi = DynamicMainValuesTimeRangeDeterminationService + .getCommonTimeRangeForGauges(river.determineGauges(access.getLowerKm(), access.getUpperKm()), startYear, endYear, this.context.getMeta()); + final int globalAdjustedEndYear = gi.getGlobalEndYear(); + final int globalAdjustedStartYear = gi.getGlobalStartYear(); + final BezugswstCalculationResults results = new BezugswstCalculationResults(calcModeLabel, user, riverInfo, access.getRange(), access.isCalculateMissingVolume()); @@ -135,7 +142,7 @@ final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder(winfo, this.context); final String qtext = descBuilder.getMetadataQ(); final BezugswstMainCalculationResult result = new BezugswstMainCalculationResult("bundu-bzws", this.rows, bedHeightsFinder.getInfo(), wstInfo, - access.getFunction(), preprocessing, startYear, endYear, ud, qtext, wqkms, this.missKmFrom, this.missKmTo); + access.getFunction(), preprocessing, globalAdjustedStartYear, globalAdjustedEndYear, ud, qtext, wqkms, this.missKmFrom, this.missKmTo); results.addResult(result, problems); // Create the missing volume results diff -r d116a791b1f8 -r c57caff9b00b artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java Thu Jan 10 09:07:16 2019 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java Thu Jan 10 11:56:39 2019 +0100 @@ -48,13 +48,25 @@ } } - private static class GaugeInfoResult { + public static class GaugeInfoResult { protected final String globalErrorMsg; protected final List gaugeInfos; + private final Date globalStartDate; + private final Date globalEndDate; - protected GaugeInfoResult(final List gaugeInfos, final String globalErrorMsg) { + protected GaugeInfoResult(final List gaugeInfos, final String globalErrorMsg, final Date min, final Date max) { this.gaugeInfos = gaugeInfos; this.globalErrorMsg = globalErrorMsg; + this.globalStartDate = min; + this.globalEndDate = max; + } + + public int getGlobalEndYear() { + return getYearFromDate(this.globalEndDate); + } + + public int getGlobalStartYear() { + return getYearFromDate(this.globalStartDate); } private static class GaugeInfo { @@ -81,9 +93,10 @@ * * @throws ServiceException */ - private GaugeInfoResult getCommonTimeRangeForGauges(final List gauges, final Date startTime, final Date endTime, final CallMeta meta) - throws ServiceException { + public static GaugeInfoResult getCommonTimeRangeForGauges(final List gauges, final int startYear, final int endYear, final CallMeta meta) { + final Date startTime = getStartDateFromYear(startYear); + final Date endTime = getEndDateFromYear(endYear); // Query the gauge's daily Q values String globalErrorMsg = ""; final List gaugeResults = new ArrayList<>(); @@ -122,7 +135,7 @@ final List 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"); @@ -132,12 +145,12 @@ if (!globalErrorMsg.isEmpty()) globalErrorMsg = new StringBuilder().append(globalErrorMsg).append("\n").append(getMsg(meta, "bundu.wst.gauge_no_ud_calc_available")).toString(); - final GaugeInfoResult result = new GaugeInfoResult(gaugeResultsSecondTurn, globalErrorMsg); + final GaugeInfoResult result = new GaugeInfoResult(gaugeResultsSecondTurn, globalErrorMsg, min, max); return result; } - private String makeDoesNotCoverErrorMsg(final int startYear, final int endYear, final CallMeta meta) { + private static 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, startYear, endYear); } @@ -147,8 +160,8 @@ try { final River river = AbstractMainValuesService.getRequestedRiver(data, "/art:" + ROOT_NODE + "/art:river/text()"); final List gauges = getRequestedGauges(data, river, callMeta); - final Date start = getRequestedStartYear(data, "/art:" + ROOT_NODE + "/art:startYear/text()"); - final Date end = getRequestedEndYear(data, "/art:" + ROOT_NODE + "/art:endYear/text()"); + final int start = getRequestedStartYear(data, "/art:" + ROOT_NODE + "/art:startYear/text()"); + final int end = getRequestedEndYear(data, "/art:" + ROOT_NODE + "/art:endYear/text()"); final GaugeInfoResult result = getCommonTimeRangeForGauges(gauges, start, end, callMeta); @@ -160,7 +173,7 @@ } } - public static final Date getRequestedEndYear(final Document data, final String XPATH_END_YEAR) throws MainValuesServiceException { + public static final int getRequestedEndYear(final Document data, final String XPATH_END_YEAR) throws MainValuesServiceException { final String endStr = XMLUtils.xpathString(data, XPATH_END_YEAR, ArtifactNamespaceContext.INSTANCE); @@ -168,13 +181,7 @@ throw new MainValuesServiceException("no end year"); // should not happen try { - final int year = Integer.parseInt(endStr); - - // FIXME: timezone? probably must match timezone of database - final Calendar cal = Calendar.getInstance(); - cal.clear(); - cal.set(year, 11, 31); - return cal.getTime(); + return Integer.parseInt(endStr); } catch (final NumberFormatException e) { e.printStackTrace(); @@ -182,7 +189,7 @@ } } - public static final Date getRequestedStartYear(final Document data, final String XPATH_START_YEAR) throws MainValuesServiceException { + public static final int getRequestedStartYear(final Document data, final String XPATH_START_YEAR) throws MainValuesServiceException { final String startStr = XMLUtils.xpathString(data, XPATH_START_YEAR, ArtifactNamespaceContext.INSTANCE); @@ -190,13 +197,7 @@ throw new MainValuesServiceException("no start year");// should not happen try { - final int year = Integer.parseInt(startStr); - - // FIXME: timezone? probably must match timezone of database - final Calendar cal = Calendar.getInstance(); - cal.clear(); - cal.set(year, 0, 1); - return cal.getTime(); + return Integer.parseInt(startStr); } catch (final NumberFormatException e) { e.printStackTrace(); @@ -204,6 +205,30 @@ } } + private static Integer getYearFromDate(final Date date) { + // FIXME: timezone? probably must match timezone of database + final Calendar cal = Calendar.getInstance(); + cal.clear(); + cal.setTime(date); + return cal.get(Calendar.YEAR); + } + + private static Date getEndDateFromYear(final int year) { + // FIXME: timezone? probably must match timezone of database + final Calendar cal = Calendar.getInstance(); + cal.clear(); + cal.set(year, 11, 31); + return cal.getTime(); + } + + private static Date getStartDateFromYear(final int year) { + // FIXME: timezone? probably must match timezone of database + final Calendar cal = Calendar.getInstance(); + cal.clear(); + cal.set(year, 0, 1); + return cal.getTime(); + } + private Document buildDocument(final GaugeInfoResult result, final GlobalContext context, final CallMeta meta) { final Document doc = XMLUtils.newDocument();