Skip to content
Snippets Groups Projects
Commit 8a176a19 authored by Bhabesh Bhabani Mukhopadhyay's avatar Bhabesh Bhabani Mukhopadhyay
Browse files

Applying spraying date

#VIPSUTV-207 : Spraying dates accepted and implemented
parent 08d6009d
Branches
Tags
No related merge requests found
......@@ -75,6 +75,8 @@ public class AlternariaModel extends I18nImpl implements Model{
public final static int THRESHOLD_DSV_MAX = 30; // Threshold Maximum for DSV
public final static int THRESHOLD_DSV_BASE = 5; // Threshold Maximum for DSV
public final static String YES = "Y"; // Spray Date
public final static String NO = "N";
private final ModelUtil modelUtil;
......@@ -117,7 +119,17 @@ public class AlternariaModel extends I18nImpl implements Model{
{
Result result = new ResultImpl();
accumulatedDSV = accumulatedDSV + dataMatrix.getParamIntValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE);
if(dataMatrix.getParamStringValueForDate(currentDate, DataMatrix.SPRAYING_DATE).equals(YES))
{
accumulatedDSV = 0;
}
else
{
accumulatedDSV = accumulatedDSV + dataMatrix.getParamIntValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE);
}
result.setValidTimeStart(currentDate);
result.setWarningStatus(getWarningStatus(accumulatedDSV));
......@@ -363,6 +375,7 @@ public class AlternariaModel extends I18nImpl implements Model{
config.getConfigParameter("observations")
, new TypeReference<List<WeatherObservation>>(){}
);
List<Date> sprayingDates = null;
List<WeatherObservation> altenariaWeatherLIstHourly_tm = new ArrayList<WeatherObservation>();
List<WeatherObservation> altenariaWeatherLIstHourly_lw = new ArrayList<WeatherObservation>();
......@@ -375,6 +388,14 @@ public class AlternariaModel extends I18nImpl implements Model{
// Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
//System.out.println("TimeZone=" + this.timeZone);
sprayingDates = (null == mapper.convertValue(config.getConfigParameter(DataMatrix.SPRAYING_DATES), new TypeReference<List<Date>>(){}))
? null
: mapper.convertValue(config.getConfigParameter(DataMatrix.SPRAYING_DATES), new TypeReference<List<Date>>(){});
int count = 0;
Collections.sort(observations);
for(WeatherObservation weatherObj: observations)
......@@ -382,6 +403,7 @@ public class AlternariaModel extends I18nImpl implements Model{
weatherObj.setTimeMeasured(wUtil.pragmaticAdjustmentToMidnight(weatherObj.getTimeMeasured(), timeZone));
//System.out.println(" weatherObj : "+weatherObj);
Date sprayDate = null;
switch(weatherObj.getElementMeasurementTypeId())
{
......@@ -482,15 +504,32 @@ public class AlternariaModel extends I18nImpl implements Model{
}
if(null != sprayingDates && sprayingDates.size() != 0)
{
for (Date spDate:sprayingDates)
{
spDate = trimmedDate(spDate, timeZone);
if(
(null != spDate && (null != dateHourlyTm_previousDay ) && (null != dateHourlyLw_previousDay))
&&
(
( spDate.compareTo(dateHourlyTm_previousDay)== 0 || spDate.before(dateHourlyTm_previousDay) )
|| ( spDate.compareTo(dateHourlyLw_previousDay)== 0 || spDate.before(dateHourlyLw_previousDay) )
)
)
{
sprayDate = trimmedDate(spDate, timeZone);
}
}
}
//Setting DSV values to dataMatrix
setDSV(
dataMatrix
setDSV(dataMatrix
, dateHourlyTm_previousDay
, DataMatrix.TEMPERATURE_MEAN
, dateHourlyLw_previousDay
, DataMatrix.LEAF_WETNESS_DURATION
, sprayDate
);
dateHourlyTm_previousDay = dateHourlyTm_currentDay;
......@@ -574,12 +613,7 @@ public class AlternariaModel extends I18nImpl implements Model{
* @param lwFlag
*/
private void setDSV(
DataMatrix dataMatrix
, Date tmDate
, String tmFlag
, Date lwDate
, String lwFlag
)
DataMatrix dataMatrix, Date tmDate, String tmFlag, Date lwDate, String lwFlag, Date sprayDate)
{
int resultDSV_tm = 0;
int resultDSV_lw = 0;
......@@ -594,9 +628,25 @@ public class AlternariaModel extends I18nImpl implements Model{
getLeafWetnessHour(dataMatrix,tmDate,lwFlag)
);
dataMatrix.setParamStringValueForDate(tmDate, DataMatrix.SPRAYING_DATE, NO);
dataMatrix.setParamIntValueForDate(tmDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE, resultDSV_tm);
if(null != sprayDate )
{
if (tmDate.compareTo(sprayDate)== 0 || sprayDate.before(tmDate))
{
dataMatrix.setParamStringValueForDate(sprayDate, DataMatrix.SPRAYING_DATE, YES);
}
else if(null == sprayDate || sprayDate.after(tmDate))
{
dataMatrix.setParamStringValueForDate(sprayDate, DataMatrix.SPRAYING_DATE, NO);
}
}
resultDSV_lw = getDSV_DAILY(
getMeanTeamperature(dataMatrix,lwDate,tmFlag)
......@@ -604,8 +654,28 @@ public class AlternariaModel extends I18nImpl implements Model{
getLeafWetnessHour(dataMatrix,lwDate,lwFlag)
);
dataMatrix.setParamStringValueForDate(lwDate, DataMatrix.SPRAYING_DATE, NO);
dataMatrix.setParamIntValueForDate(lwDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE, resultDSV_lw);
if(null != sprayDate)
{
if ((lwDate.compareTo(sprayDate)== 0) || sprayDate.before(lwDate))
{
dataMatrix.setParamStringValueForDate(sprayDate, DataMatrix.SPRAYING_DATE, YES);
}
else if(null == sprayDate || sprayDate.after(lwDate))
{
dataMatrix.setParamStringValueForDate(sprayDate, DataMatrix.SPRAYING_DATE, NO);
}
}
}
}
......
......@@ -48,5 +48,8 @@ public class DataMatrix extends DateMap{
public final static String LEAF_WETNESS_DURATION = "BT"; // Leaf wetness 2 m, minutes per hour
public final static String TEMPERATURE_MEAN = "TM"; // Mean Temperature
public final static String DAILY_DISEASE_SEVERITY_VALUE = "DSV"; // Daily Disease Severity Value
public final static String SPRAYING_DATES = "sprayingDates";// Spraying dates
public final static String SPRAYING_DATE = "sprayingDate"; // Spray Date
}
......@@ -58,6 +58,7 @@ public class AlternariaModelTest {
public void testGetResult() throws Exception {
System.out.println("getResult");
ModelConfiguration config = this.getConfiguration("/weatherdata_leaf_wetness_temperature.json");
config.setConfigParameter("sprayingDates", this.getConfigurationSprayingDates("/reset_dates.json"));
AlternariaModel instance = new AlternariaModel();
instance.setConfiguration(config);
List<Result> result = instance.getResult();
......@@ -235,15 +236,18 @@ public class AlternariaModelTest {
public void testSetConfiguration() throws Exception {
System.out.println("setConfiguration");
ModelConfiguration config = this.getConfiguration("/weatherdata_leaf_wetness_temperature.json");
config.setConfigParameter("sprayingDates", this.getConfigurationSprayingDates("/reset_dates.json"));
AlternariaModel instance = new AlternariaModel();
instance.setConfiguration(config);
assertNotNull(instance);
}
private ModelConfiguration getConfiguration(String fileName)
private ModelConfiguration getConfiguration(String fileName)
{
List<Date> sprayingDates = new ArrayList<Date>();
try {
ModelConfiguration config = new ModelConfiguration();
config.setModelId(AlternariaModel.MODEL_ID.toString());
......@@ -285,6 +289,15 @@ public class AlternariaModelTest {
fail("Data input from file is not a JSON array");
}
config.setConfigParameter("observations", observations);
try{
}
catch(Exception ex)
{
}
return config;
......@@ -293,4 +306,48 @@ public class AlternariaModelTest {
return null;
}
}
private List<Date> getConfigurationSprayingDates(String fileName)
{
try {
List<Date> sprayingDates = new ArrayList<Date>();
BufferedInputStream inputStream = new BufferedInputStream(this.getClass().getResourceAsStream(fileName));
JsonFactory f = new MappingJsonFactory();
JsonParser jp = f.createParser(inputStream);
JsonNode all = jp.readValueAsTree();
ObjectMapper mapper = new ObjectMapper();
Date firstDate = null;
Date lastDate = null;
if(all.isArray())
{
for(JsonNode node : all){
Date timeMeasuredForSpray = (Date)mapper.convertValue(node, new TypeReference<Date>(){});
//System.out.println("Spraying Date : "+timeMeasuredForSpray);
if(timeMeasuredForSpray != null )
{
sprayingDates.add(timeMeasuredForSpray);
}
}
}
else
{
fail("Data input from file is not a JSON array for list of spraying dates");
}
return sprayingDates;
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
}
}
[
"2019-07-01T22:00:00Z",
"2019-08-11T22:00:00Z"
]
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment