Skip to content
Snippets Groups Projects
Commit 6ba326d1 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Roughage: Custom growth start calc date [GROVFOR-10]

parent 8e05df6c
No related branches found
No related tags found
No related merge requests found
......@@ -104,6 +104,7 @@ public class RoughageService {
@QueryParam("wateringAffectsNormalData") String wateringAffectsNormalData,
@QueryParam("firstHarvest") String firstHarvestStr,
@QueryParam("secondHarvest") String secondHarvestStr,
@QueryParam("firstPossibleGrowthStartDate") String firstPossibleGrowthStartDateStr,
@QueryParam("soilType") Integer soilType,
@QueryParam("cloverShare") Integer cloverShare,
@QueryParam("userWeatherScenarios") String useWeatherScenarios,
......@@ -119,21 +120,23 @@ public class RoughageService {
TimeZone timeZone = TimeZone.getTimeZone(timeZoneStr);
Date firstHarvest = parseUtil.parseISODate(firstHarvestStr, timeZone);
Date secondHarvest = secondHarvestStr != null ? parseUtil.parseISODate(secondHarvestStr, timeZone) : null;
// Calculating start and end date of weather data retrieval
// Start is April 1st
Calendar cal = Calendar.getInstance(timeZone);
cal.setTime(firstHarvest);
cal.set(Calendar.MONTH, Calendar.MARCH);
cal.set(Calendar.DATE, 1);
// Calculating start and end date of weather data retrieval
// Start is March 1st unless specified otherwise
Date firstPossibleGrowthStartDate = firstPossibleGrowthStartDateStr != null ? parseUtil.parseISODate(firstPossibleGrowthStartDateStr, timeZone) : null;
WeatherUtil wUtil = new WeatherUtil();
Date marchFirst = wUtil.normalizeToExactDate(cal.getTime(), timeZone);
Calendar cal = Calendar.getInstance(timeZone);
if(firstPossibleGrowthStartDate == null) {
cal.setTime(firstHarvest);
cal.set(Calendar.MONTH, Calendar.MARCH);
cal.set(Calendar.DATE, 1);
firstPossibleGrowthStartDate = wUtil.normalizeToExactDate(cal.getTime(), timeZone);
}
// End date for weather data depends on season
// We try September 30th. If that's in the future,
// We add 10 days to today
Date dateOfLastWeatherData;
cal.setTime(marchFirst);
cal.setTime(firstPossibleGrowthStartDate);
cal.set(Calendar.MONTH, Calendar.SEPTEMBER);
cal.set(Calendar.DATE, 30);
Date endOfSeptember = cal.getTime();
......@@ -164,7 +167,7 @@ public class RoughageService {
WeatherElements.SOIL_TEMPERATURE_10CM_MEAN,
WeatherElements.POTENTIAL_EVAPORATION
},
marchFirst,
firstPossibleGrowthStartDate,
dateOfLastWeatherData
);
} catch (WeatherDataSourceException ex) {
......@@ -367,9 +370,10 @@ public class RoughageService {
config.setConfigParameter("observations", observations);
config.setConfigParameter("timeZone", timeZone.getID());
config.setConfigParameter("firstHarvest", firstHarvest);
config.setConfigParameter("firstPossibleGrowthStartDate", firstPossibleGrowthStartDate);
config.setConfigParameter("soilType", soilType);
config.setConfigParameter("cloverShare", cloverShare);
// Optional parameters
if(secondHarvest != null)
{
......@@ -426,7 +430,7 @@ public class RoughageService {
WeatherElements.SOIL_TEMPERATURE_10CM_MEAN,
WeatherElements.POTENTIAL_EVAPORATION
},
marchFirst,
firstPossibleGrowthStartDate,
//dateOfLastWeatherData
latestObsDate
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment