diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AltenariaModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AltenariaModelPreprocessor.java index 94f36d73d24184244692d1f3901c7591386ddf2f..3ff54e4be9fd052b98124645378a67d6542ea4d5 100644 --- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AltenariaModelPreprocessor.java +++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AltenariaModelPreprocessor.java @@ -20,6 +20,8 @@ Error reading included file Templates/Classes/Templates/Licenses/license-nibio_o package no.nibio.vips.logic.scheduling.model.preprocessor; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -28,12 +30,15 @@ import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.TimeZone; +import java.util.logging.Level; +import java.util.logging.Logger; import no.nibio.vips.entity.ModelConfiguration; import no.nibio.vips.entity.WeatherObservation; import no.nibio.vips.logic.entity.ForecastConfiguration; import no.nibio.vips.logic.entity.PointOfInterestWeatherStation; import no.nibio.vips.logic.scheduling.model.ModelRunPreprocessor; import no.nibio.vips.logic.scheduling.model.PreprocessorException; +import no.nibio.vips.logic.util.SessionControllerGetter; import no.nibio.vips.logic.util.SystemTime; import no.nibio.vips.model.ConfigValidationException; import no.nibio.vips.util.WeatherElements; @@ -47,7 +52,7 @@ import no.nibio.vips.util.weather.WeatherDataSourceUtil; * @author bhabesh */ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ - + public final Logger LOGGER = Logger.getLogger(this.getClass().getName()); private final boolean DEBUG = false; /** @@ -62,9 +67,19 @@ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ @Override public ModelConfiguration getModelConfiguration(ForecastConfiguration configuration) throws PreprocessorException { + String ALTERNARIA_SPRAYING_DATES_01 = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName("ALTERNARIA", "sprayingDate01"); + String ALTERNARIA_SPRAYING_DATES_02 = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName("ALTERNARIA", "sprayingDate02"); + String ALTERNARIA_SPRAYING_DATES_03 = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName("ALTERNARIA", "sprayingDate03"); + String ALTERNARIA_SPRAYING_DATES_04 = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName("ALTERNARIA", "sprayingDate04"); + + String paramConfigValue = null; + List<Date> lstSprayingDates = new ArrayList(){}; + PointOfInterestWeatherStation weatherStation = (PointOfInterestWeatherStation) configuration.getWeatherStationPointOfInterestId(); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); // What timezone is the calculation for TimeZone timeZone = TimeZone.getTimeZone(weatherStation.getTimeZone()); + format.setTimeZone(timeZone); // Getting date three days after "today" Calendar cal = Calendar.getInstance(timeZone); cal.setTime(SystemTime.getSystemTime()); @@ -79,6 +94,11 @@ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ WeatherDataSourceUtil wdsUtil = new WeatherDataSourceUtil(); List<WeatherObservation> observations; + Date paramSprayingDate01 = null; + Date paramSprayingDate02 = null; + Date paramSprayingDate03 = null; + Date paramSprayingDate04 = null; + try { observations = wdsUtil.getWeatherObservations( weatherStation, @@ -115,6 +135,58 @@ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ } } */ + + + + try + { + if( + null != configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_01) + && ! configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_01).trim().equals("") + ) + { + paramConfigValue = configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_01); + paramSprayingDate01 = format.parse(paramConfigValue); + lstSprayingDates.add(paramSprayingDate01); + } + + if( + null != configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_02) + && ! configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_02).trim().equals("") + ) + { + paramConfigValue = configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_02); + paramSprayingDate02 = format.parse(paramConfigValue); + lstSprayingDates.add(paramSprayingDate02); + } + + if( + null != configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_03) + && ! configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_03).trim().equals("") + ) + { + paramConfigValue = configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_03); + paramSprayingDate03 = format.parse(paramConfigValue); + lstSprayingDates.add(paramSprayingDate03); + } + + if( + null != configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_04) + && ! configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_04).trim().equals("") + ) + { + paramConfigValue = configuration.getForecastModelConfigurationValue(ALTERNARIA_SPRAYING_DATES_04); + paramSprayingDate04 = format.parse(paramConfigValue); + lstSprayingDates.add(paramSprayingDate04); + } + + + + } + catch(ParseException ex) + { + throw new PreprocessorException("Could not parse date for Spraying Date for Alternaria. Given string was: "+ paramConfigValue); + } Collections.sort(observations); @@ -139,7 +211,7 @@ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ if(DEBUG) { - System.out.println("Finished getting weather data at " + new Date().toString()); + LOGGER.log(Level.CONFIG, "Finished getting weather data at "+new Date().toString()); } try { observations = validateAndSanitizeObservations(observations, startDate); @@ -149,15 +221,21 @@ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ } if(DEBUG) { - System.out.println("Observations=" + observations.toString()); + LOGGER.log(Level.CONFIG, "Observations=" + observations.toString()); } - + + + // TODO: weather data validation retVal.setModelId(this.getModelId()); retVal.setConfigParameter("timeZone", timeZone.getID()); retVal.setConfigParameter("observations", observations); - + + //retVal.setConfigParameter("sprayingDates", format.format(paramSprayingDate)); + + retVal.setConfigParameter("sprayingDates", lstSprayingDates); + return retVal; } @@ -174,7 +252,7 @@ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ private List<WeatherObservation> validateAndSanitizeObservations(List<WeatherObservation> observations, Date firstTimeStamp) throws ConfigValidationException, WeatherObservationListException { if(DEBUG) { - System.out.println("validateAndSanitizeObservations"); + LOGGER.log(Level.CONFIG, "validateAndSanitizeObservations"); } WeatherUtil wUtil = new WeatherUtil(); @@ -240,8 +318,7 @@ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ // Holes in series if(DEBUG) { - System.out.println("checkForAndFixHourlyTimeSeriesHoles"); - //System.out.println(wUtil.dumpWeatherObservationList(RR)); + LOGGER.log(Level.CONFIG, "checkForAndFixHourlyTimeSeriesHoles"); } @@ -260,7 +337,7 @@ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ null ); - System.out.println("Value of relative Humidity : "+UM); + // Fallback if missing leaf wetness: If we have relative humidity. leaf wetness may be calculated if((BT.size() != TM.size()) && (UM.size() == TM.size())) @@ -274,8 +351,7 @@ public class AltenariaModelPreprocessor extends ModelRunPreprocessor{ } else { - System.out.println("TM starts " + TM.get(0).getTimeMeasured() + ", ends " + TM.get(TM.size()-1).getTimeMeasured()); - //System.out.println("UM starts " + UM.get(0).getTimeMeasured() + ", ends " + UM.get(UM.size()-1).getTimeMeasured()); + LOGGER.log(Level.WARNING, "TM starts " + TM.get(0).getTimeMeasured() + ", ends " + TM.get(TM.size()-1).getTimeMeasured()); throw new ConfigValidationException("Incorrect number of weather data. TM.size() = " + TM.size() + ", BT.size()=" + BT.size() + ", RR.size()=" + RR.size() + ", UM.size()=" + UM.size() ); } } diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties index 37f6cb51a729d50eb3bbd296c354d66e619ad6fe..47c784160720a85231a4a58d826283552cf62518 100755 --- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties +++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties @@ -59,7 +59,7 @@ approvalApplication=Role description pleaseSelect=Please select passwordsDoNotMatch=Passwords do not match missingValues=Missing values -fieldIsRequired=Field is required +sprayingDate=Field is required exceedsMaxLengthOf=Exceeds max length of {0} invalidFormat=Invalid format organizationId=VIPS system @@ -490,3 +490,10 @@ locationIsPublic=Location is public maskObservationWith=Mask observation with deletePoi=Delete point of interest deletePoiPreviewExplanation=The point of interest that you want to delete has the resources below connected to it. When you delete the POI, you also delete these resources. +#Spraying Date +sprayingDates=Spraying Date +ALTERNARIA=Alternaria Model +sprayingDate01=Spraying Date 01 +sprayingDate02=Spraying Date 02 +sprayingDate03=Spraying Date 03 +sprayingDate04=Spraying Date 04 diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties index 53cb3d7d4bad5ce955e41cf5be4a285e5c9badeb..8e83eeecc51a90e927e3a9ff885c2dda26e6ec90 100755 --- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties +++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties @@ -490,3 +490,10 @@ locationIsPublic=Location is public maskObservationWith=Mask observation with deletePoi=Delete point of interest deletePoiPreviewExplanation= +#Spraying Date +sprayingDates=Spraying Date +ALTERNARIA=Alternaria Model +sprayingDate01=Spraying Date 01 +sprayingDate02=Spraying Date 02 +sprayingDate03=Spraying Date 03 +sprayingDate04=Spraying Date 04 diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties index 2ec31284a14ffe5f3d3077a1236159d0f4c9ebcc..87d78654041203f42ba401b6b6c1dbf325512117 100755 --- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties +++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties @@ -489,3 +489,10 @@ locationIsPublic=Location is public maskObservationWith=Mask observation with deletePoi=Delete point of interest deletePoiPreviewExplanation= +#Spraying Date +sprayingDates=Spraying Date +ALTERNARIA=Alternaria Model +sprayingDate01=Spraying Date 01 +sprayingDate02=Spraying Date 02 +sprayingDate03=Spraying Date 03 +sprayingDate04=Spraying Date 04 diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties index a287d25dfb13e98e0de96eb7a9850d97cb45a111..73aa5f5a63792d550aa3d9eed0bd7b64d4e19d50 100755 --- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties +++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties @@ -490,3 +490,10 @@ locationIsPublic=Lokaliteten kan vises offentlig maskObservationWith=Masker observasjonen med deletePoi=Slett sted deletePoiPreviewExplanation=Stedet du \u00f8nsker \u00e5 slette har knyttet til seg de ressursene som er nevnt nedenfor. N\u00e5r du sletter stedet, vil ogs\u00e5 disse ressursene bli slettet. +#Spraying Date +sprayingDates=Spraying Date +ALTERNARIA=Alternaria Model +sprayingDate01=Spraying Date 01 +sprayingDate02=Spraying Date 02 +sprayingDate03=Spraying Date 03 +sprayingDate04=Spraying Date 04 diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties index 42d27b048f77754edf471e80804098813aeab032..2e8771c73221a83589debb65f62566f088e3729b 100755 --- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties +++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties @@ -490,3 +490,10 @@ locationIsPublic=Location is public maskObservationWith=Mask observation with deletePoi=Delete point of interest deletePoiPreviewExplanation= +#Spraying Date +sprayingDates=Spraying Date +ALTERNARIA=Alternaria Model +sprayingDate01=Spraying Date 01 +sprayingDate02=Spraying Date 02 +sprayingDate03=Spraying Date 03 +sprayingDate04=Spraying Date 04 diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_zh_CN.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_zh_CN.properties index 66f1011fec6990220ed23fb980ca76ebc33abb42..2de07aa6639aa529ec7981a3a9009268a583d56f 100755 --- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_zh_CN.properties +++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_zh_CN.properties @@ -487,3 +487,10 @@ locationIsPublic=Location is public maskObservationWith=Mask observation with deletePoi=Delete point of interest deletePoiPreviewExplanation= +#Spraying Date +sprayingDates=Spraying Date +ALTERNARIA=Alternaria Model +sprayingDate01=Spraying Date 01 +sprayingDate02=Spraying Date 02 +sprayingDate03=Spraying Date 03 +sprayingDate04=Spraying Date 04 diff --git a/src/main/webapp/formdefinitions/models/ALTERNARIA.json b/src/main/webapp/formdefinitions/models/ALTERNARIA.json index dca095a7c82f1088d5192e42f0d6a3e072890a3a..f65768d9b5b42757927f41f5d0c05012930d4c41 100644 --- a/src/main/webapp/formdefinitions/models/ALTERNARIA.json +++ b/src/main/webapp/formdefinitions/models/ALTERNARIA.json @@ -17,5 +17,30 @@ "along with VIPSLogic. If not, see <http://www.nibio.no/licenses/>. " ], "_comment" : "Structure of the specific fields for ALTERNARIA", - "fields": [] + "fields": [ + { + "name" : "sprayingDate01", + "dataType" : "DATE", + "dateFormat" : "yyyy-MM-dd", + "required" : false + }, + { + "name" : "sprayingDate02", + "dataType" : "DATE", + "dateFormat" : "yyyy-MM-dd", + "required" : false + }, + { + "name" : "sprayingDate03", + "dataType" : "DATE", + "dateFormat" : "yyyy-MM-dd", + "required" : false + }, + { + "name" : "sprayingDate04", + "dataType" : "DATE", + "dateFormat" : "yyyy-MM-dd", + "required" : false + } + ] }