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

Format code

parent 014662d5
Branches
Tags
No related merge requests found
...@@ -62,134 +62,139 @@ import no.nibio.vips.util.CommonNamespaces; ...@@ -62,134 +62,139 @@ import no.nibio.vips.util.CommonNamespaces;
import no.nibio.vips.util.ModelUtil; import no.nibio.vips.util.ModelUtil;
import no.nibio.vips.util.WeatherUtil; import no.nibio.vips.util.WeatherUtil;
/** /**
* *
* @author bhabesh * @author bhabesh
*/ */
public class AlternariaModel extends I18nImpl implements Model{ public class AlternariaModel extends I18nImpl implements Model {
public final static Logger LOGGER = Logger.getLogger(AlternariaModel.class.getName()); public final static Logger LOGGER = Logger.getLogger(AlternariaModel.class.getName());
public final static String NAME_MODEL_ID = "ALTERNARIA"; public final static String NAME_MODEL_ID = "ALTERNARIA";
public final static ModelId MODEL_ID = new ModelId(NAME_MODEL_ID); public final static ModelId MODEL_ID = new ModelId(NAME_MODEL_ID);
public final static int THRESHOLD_LW = 30; // Threshold for leave wetness public final static int THRESHOLD_LW = 30; // Threshold for leave wetness
public final static int THRESHOLD_DSV_MAX = 20; // Threshold Minimum for DSV public final static int THRESHOLD_DSV_MAX = 20; // Threshold Minimum for DSV
public final static int THRESHOLD_DSV_DIFF_MIN_MAX = 5; // Threshold Maximum for DSV public final static int THRESHOLD_DSV_DIFF_MIN_MAX = 5; // Threshold Maximum for DSV
private Double THRESHOLD_DSV_TEMP_MIN = 13.0; // Minimum temp for getting a DSV value private Double THRESHOLD_DSV_TEMP_MIN = 13.0; // Minimum temp for getting a DSV value
public final static String YES = "Y"; // Spray Date public final static String YES = "Y"; // Spray Date
public final static String NO = "N"; public final static String NO = "N";
private final ModelUtil modelUtil;
private final ModelUtil modelUtil; private DataMatrix dataMatrix;
private DataMatrix dataMatrix;
private TimeZone timeZone;
private TimeZone timeZone;
public AlternariaModel() {
public AlternariaModel()
{
super("no.nibio.vips.model.alternariamodel.texts"); super("no.nibio.vips.model.alternariamodel.texts");
this.modelUtil = new ModelUtil(); this.modelUtil = new ModelUtil();
} }
@Override @Override
public List<Result> getResult() throws ModelExcecutionException public List<Result> getResult() throws ModelExcecutionException {
{
/** /**
* method name : getResult * method name : getResult
* @param : *
* @return : java.util.List<no.nibio.vips.entity.Result> * @param :
* @return : java.util.List<no.nibio.vips.entity.Result>
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. // throw new UnsupportedOperationException("Not supported yet."); //To change
//TODO write proper list of result object // body of generated methods, choose Tools | Templates.
// TODO write proper list of result object
//Date currentDate = this.dataMatrix.getFirstDateWithParameterValue(DataMatrix.LEAF_WETNESS_DURATION);
List<Result> results = new ArrayList<>(); // Date currentDate =
// this.dataMatrix.getFirstDateWithParameterValue(DataMatrix.LEAF_WETNESS_DURATION);
Date currentDate = this.dataMatrix.getFirstDateWithParameterValue(DataMatrix.TEMPERATURE_MEAN); List<Result> results = new ArrayList<>();
Date endDate = this.dataMatrix.getLastDateWithParameterValue(DataMatrix.TEMPERATURE_MEAN);
DecimalFormat dFormat = new DecimalFormat("###.##"); Date currentDate = this.dataMatrix.getFirstDateWithParameterValue(DataMatrix.TEMPERATURE_MEAN);
DecimalFormat iFormat = new DecimalFormat("###"); Date endDate = this.dataMatrix.getLastDateWithParameterValue(DataMatrix.TEMPERATURE_MEAN);
Calendar cal = Calendar.getInstance(timeZone); DecimalFormat dFormat = new DecimalFormat("###.##");
int accumulatedDSV = 0; DecimalFormat iFormat = new DecimalFormat("###");
Calendar cal = Calendar.getInstance(timeZone);
while(currentDate.before(endDate)) int accumulatedDSV = 0;
{
Result result = new ResultImpl(); while (currentDate.before(endDate)) {
Result result = new ResultImpl();
if(null == dataMatrix.getParamStringValueForDate(currentDate, DataMatrix.SPRAYING_DATE))
{ if (null == dataMatrix.getParamStringValueForDate(currentDate, DataMatrix.SPRAYING_DATE)) {
// DO Nothing -- Consider same accumulatedDSV // DO Nothing -- Consider same accumulatedDSV
} } else {
else if (dataMatrix.getParamStringValueForDate(currentDate, DataMatrix.SPRAYING_DATE).equals(YES)) {
{ accumulatedDSV = 0;
if(dataMatrix.getParamStringValueForDate(currentDate, DataMatrix.SPRAYING_DATE).equals(YES)) } else
{
accumulatedDSV = 0; {
} accumulatedDSV = accumulatedDSV
else + dataMatrix.getParamIntValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE);
}
{ }
accumulatedDSV = accumulatedDSV + dataMatrix.getParamIntValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE);
} result.setValidTimeStart(currentDate);
} result.setWarningStatus(getWarningStatus(accumulatedDSV));
result.setValue(CommonNamespaces.NS_WEATHER, DataMatrix.TEMPERATURE_MEAN,
result.setValidTimeStart(currentDate); dFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.TEMPERATURE_MEAN)));
result.setWarningStatus(getWarningStatus(accumulatedDSV)); result.setValue(NAME_MODEL_ID, DataMatrix.WET_HOUR, iFormat
.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.LEAF_WETNESS_DURATION)));
result.setValue(CommonNamespaces.NS_WEATHER, DataMatrix.TEMPERATURE_MEAN, dFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.TEMPERATURE_MEAN))); result.setValue(NAME_MODEL_ID, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE_SUM, iFormat.format(accumulatedDSV));
result.setValue(NAME_MODEL_ID, DataMatrix.WET_HOUR, iFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.LEAF_WETNESS_DURATION))); result.setValue(NAME_MODEL_ID, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE, iFormat.format(
result.setValue(NAME_MODEL_ID, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE_SUM, iFormat.format(accumulatedDSV)); this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE)));
result.setValue(NAME_MODEL_ID, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE, iFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE)));
result.setValue(NAME_MODEL_ID, DataMatrix.THRESHOLD_DSV_BASE,
result.setValue(NAME_MODEL_ID, DataMatrix.THRESHOLD_DSV_BASE, String.valueOf(THRESHOLD_DSV_MAX - THRESHOLD_DSV_DIFF_MIN_MAX)); String.valueOf(THRESHOLD_DSV_MAX - THRESHOLD_DSV_DIFF_MIN_MAX));
result.setValue(NAME_MODEL_ID, DataMatrix.THRESHOLD_DSV_MAX, String.valueOf(THRESHOLD_DSV_MAX)); result.setValue(NAME_MODEL_ID, DataMatrix.THRESHOLD_DSV_MAX, String.valueOf(THRESHOLD_DSV_MAX));
results.add(result); results.add(result);
cal.setTime(currentDate); cal.setTime(currentDate);
cal.add(Calendar.DATE, 1); cal.add(Calendar.DATE, 1);
currentDate = cal.getTime(); currentDate = cal.getTime();
} }
//LOGGER.log(Level.INFO, "DataMatrix-Value 03: "+dataMatrix); // LOGGER.log(Level.INFO, "DataMatrix-Value 03: "+dataMatrix);
return results; return results;
} }
@Override @Override
public ModelId getModelId() public ModelId getModelId() {
{
/** /**
* method name : getModelId * method name : getModelId
* @param : *
* @return : no.nibio.vips.model.ModelId * @param :
* @return : no.nibio.vips.model.ModelId
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. // throw new UnsupportedOperationException("Not supported yet."); //To change
// body of generated methods, choose Tools | Templates.
return AlternariaModel.MODEL_ID; return AlternariaModel.MODEL_ID;
} }
@Override @Override
public String getModelName() public String getModelName() {
{
/** /**
* method name : getModelName * method name : getModelName
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return this.getModelName(Model.DEFAULT_LANGUAGE); return this.getModelName(Model.DEFAULT_LANGUAGE);
} }
...@@ -197,64 +202,76 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -197,64 +202,76 @@ public class AlternariaModel extends I18nImpl implements Model{
/** /**
* *
* @param language * @param language
* @return * @return
*/ */
@Override @Override
public String getModelName(String language) public String getModelName(String language) {
{
/** /**
* method name : getModelName * method name : getModelName
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return this.getText("name", language); return this.getText("name", language);
} }
@Override @Override
public String getLicense() public String getLicense() {
{
/** /**
* method name : getLicense * method name : getLicense
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return this.getText("license", Model.DEFAULT_LANGUAGE); return this.getText("license", Model.DEFAULT_LANGUAGE);
} }
@Override @Override
public String getCopyright() public String getCopyright() {
{
/** /**
* method name : getCopyright * method name : getCopyright
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return "(c) 2020 NIBIO (http://www.nibio.no/). Contact: post@nibio.no"; return "(c) 2020 NIBIO (http://www.nibio.no/). Contact: post@nibio.no";
} }
@Override @Override
public String getModelDescription() public String getModelDescription() {
{
/** /**
* method name : getModelDescription * method name : getModelDescription
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return this.getModelDescription(Model.DEFAULT_LANGUAGE); return this.getModelDescription(Model.DEFAULT_LANGUAGE);
} }
...@@ -262,105 +279,122 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -262,105 +279,122 @@ public class AlternariaModel extends I18nImpl implements Model{
/** /**
* *
* @param language * @param language
* @return * @return
*/ */
@Override @Override
public String getModelDescription(String language) public String getModelDescription(String language) {
{
/** /**
* method name : getModelDescription * method name : getModelDescription
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
try try {
{ return this.modelUtil.getTextWithBase64EncodedImages(this.getText("description", language),
return this.modelUtil.getTextWithBase64EncodedImages(this.getText("description", language), this.getClass()); this.getClass());
} } catch (IOException ex) {
catch (IOException ex)
{
return this.getText("description", language); return this.getText("description", language);
} }
} }
@Override @Override
public String getWarningStatusInterpretation() public String getWarningStatusInterpretation() {
{
/** /**
* method name : getWarningStatusInterpretation * method name : getWarningStatusInterpretation
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return this.getWarningStatusInterpretation(Model.DEFAULT_LANGUAGE); return this.getWarningStatusInterpretation(Model.DEFAULT_LANGUAGE);
} }
@Override @Override
public String getWarningStatusInterpretation(String language) public String getWarningStatusInterpretation(String language) {
{
/** /**
* method name : getWarningStatusInterpretation * method name : getWarningStatusInterpretation
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return this.getText("statusInterpretation", language); return this.getText("statusInterpretation", language);
} }
@Override @Override
public String getModelUsage() public String getModelUsage() {
{
/** /**
* method name : getModelUsage * method name : getModelUsage
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return this.getModelUsage(Model.DEFAULT_LANGUAGE); return this.getModelUsage(Model.DEFAULT_LANGUAGE);
} }
@Override @Override
public String getModelUsage(String language) public String getModelUsage(String language) {
{
/** /**
* method name : getModelUsage * method name : getModelUsage
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return this.getText("usage", language); return this.getText("usage", language);
} }
/** /**
* TODO * TODO
* @return *
* @return
*/ */
@Override @Override
public String getSampleConfig() public String getSampleConfig() {
{
/** /**
* method name : getSampleConfig * method name : getSampleConfig
* @param : *
* @return : java.lang.String * @param :
* @return : java.lang.String
* *
* purpose : * purpose :
* *
* date : Expression date is undefined on line 20, column 19 in Templates/Classes/Code/GeneratedMethodBody. Expression time is undefined on line 20, column 27 in Templates/Classes/Code/GeneratedMethodBody. * date : Expression date is undefined on line 20, column 19 in
* Templates/Classes/Code/GeneratedMethodBody. Expression time is
* undefined on line 20, column 27 in
* Templates/Classes/Code/GeneratedMethodBody.
*/ */
return this.getText("sampleconfig", Model.DEFAULT_LANGUAGE); return this.getText("sampleconfig", Model.DEFAULT_LANGUAGE);
} }
...@@ -368,401 +402,335 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -368,401 +402,335 @@ public class AlternariaModel extends I18nImpl implements Model{
/** /**
* *
* @param config * @param config
* @throws ConfigValidationException * @throws ConfigValidationException
*/ */
@Override @Override
public void setConfiguration(ModelConfiguration config) throws ConfigValidationException public void setConfiguration(ModelConfiguration config) throws ConfigValidationException {
{
List<WeatherObservation> altenariaWeatherListDaily = new ArrayList<WeatherObservation>();
List<WeatherObservation> altenariaWeatherListDaily = new ArrayList<WeatherObservation>(); dataMatrix = new DataMatrix();
ObjectMapper mapper = new ObjectMapper();
dataMatrix = new DataMatrix(); timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
ObjectMapper mapper = new ObjectMapper();
timeZone = TimeZone.getTimeZone((String)config.getConfigParameter("timeZone")); WeatherUtil weatherUtil = new WeatherUtil();
List<WeatherObservation> observations = modelUtil
.extractWeatherObservationList(config.getConfigParameter("observations"));
WeatherUtil weatherUtil = new WeatherUtil(); List<Date> sprayingDates = null;
List<WeatherObservation> observations = modelUtil.extractWeatherObservationList(config.getConfigParameter("observations")); List<WeatherObservation> altenariaWeatherLIstHourly_tm = new ArrayList<WeatherObservation>();
List<Date> sprayingDates = null; List<WeatherObservation> altenariaWeatherLIstHourly_lw = new ArrayList<WeatherObservation>();
List<WeatherObservation> altenariaWeatherLIstHourly_tm = new ArrayList<WeatherObservation>();
List<WeatherObservation> altenariaWeatherLIstHourly_lw = new ArrayList<WeatherObservation>(); Date dateHourlyTm_currentDay = null;
Date dateHourlyTm_previousDay = null;
Date dateHourlyTm_currentDay = null; Date dateHourlyLw_currentDay = null;
Date dateHourlyTm_previousDay = null; Date dateHourlyLw_previousDay = null;
Date dateHourlyLw_currentDay = null;
Date dateHourlyLw_previousDay = null;
WeatherUtil wUtil = new WeatherUtil(); WeatherUtil wUtil = new WeatherUtil();
// Setting timezone // Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone")); this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
sprayingDates = (null == mapper.convertValue(config.getConfigParameter(DataMatrix.SPRAYING_DATES), new TypeReference<List<Date>>(){})) sprayingDates = (null == mapper.convertValue(config.getConfigParameter(DataMatrix.SPRAYING_DATES),
? null new TypeReference<List<Date>>() {
: 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;
int count = 0;
Collections.sort(observations); Collections.sort(observations);
for(WeatherObservation weatherObj: observations) for (WeatherObservation weatherObj : observations) {
{
weatherObj.setTimeMeasured(wUtil.pragmaticAdjustmentToMidnight(weatherObj.getTimeMeasured(), timeZone));
Date sprayDate = null;
switch(weatherObj.getElementMeasurementTypeId())
{
case DataMatrix.TEMPERATURE_MEAN:
dateHourlyTm_currentDay = trimmedDate(weatherObj.getTimeMeasured(),timeZone);
if(weatherObj.getLogIntervalId().equals(WeatherObservation.LOG_INTERVAL_ID_1H))
{
WeatherObservation altanariaWeatherBO_tm_hourly = weatherObj;
if (
(null != dateHourlyTm_currentDay )
&& (null != dateHourlyTm_previousDay)
&& dateHourlyTm_currentDay.after (
dateHourlyTm_previousDay
)
)
{
double counterTMHourly = 0;
//TODO calculation of accumulation value and add to daily
for(WeatherObservation wo: altenariaWeatherLIstHourly_tm)
{
counterTMHourly = counterTMHourly + wo.getValue();
} weatherObj.setTimeMeasured(wUtil.pragmaticAdjustmentToMidnight(weatherObj.getTimeMeasured(), timeZone));
//average value of temperature for a day
dataMatrix.setParamDoubleValueForDate ( dateHourlyTm_previousDay
, DataMatrix.TEMPERATURE_MEAN
, (
counterTMHourly
/
altenariaWeatherLIstHourly_tm.size()
)
);
//discard old value for next day and start fresh
altenariaWeatherLIstHourly_tm = new ArrayList<WeatherObservation>();
}
altenariaWeatherLIstHourly_tm.add(altanariaWeatherBO_tm_hourly); Date sprayDate = null;
}
switch (weatherObj.getElementMeasurementTypeId()) {
case DataMatrix.TEMPERATURE_MEAN:
dateHourlyTm_currentDay = trimmedDate(weatherObj.getTimeMeasured(), timeZone);
if (weatherObj.getLogIntervalId().equals(WeatherObservation.LOG_INTERVAL_ID_1H)) {
WeatherObservation altanariaWeatherBO_tm_hourly = weatherObj;
if ((null != dateHourlyTm_currentDay)
&& (null != dateHourlyTm_previousDay)
&& dateHourlyTm_currentDay.after(
dateHourlyTm_previousDay)) {
double counterTMHourly = 0;
// TODO calculation of accumulation value and add to daily
for (WeatherObservation wo : altenariaWeatherLIstHourly_tm) {
counterTMHourly = counterTMHourly + wo.getValue();
if(weatherObj.getLogIntervalId().equals(WeatherObservation.LOG_INTERVAL_ID_1D))
{
if (
(null == dataMatrix.getParamDoubleValueForDate(dateHourlyTm_currentDay, DataMatrix.TEMPERATURE_MEAN) )
||
((dataMatrix.getParamDoubleValueForDate(dateHourlyTm_currentDay, DataMatrix.TEMPERATURE_MEAN)).intValue() == 0)
)
{
dataMatrix.setParamDoubleValueForDate (
weatherObj.getTimeMeasured() //TODO - Might be the date need to be trimmed
, DataMatrix.TEMPERATURE_MEAN
, weatherObj.getValue()
);
} }
// average value of temperature for a day
dataMatrix.setParamDoubleValueForDate(dateHourlyTm_previousDay, DataMatrix.TEMPERATURE_MEAN,
(counterTMHourly
/
altenariaWeatherLIstHourly_tm.size()));
// discard old value for next day and start fresh
altenariaWeatherLIstHourly_tm = new ArrayList<WeatherObservation>();
} }
break;
case DataMatrix.LEAF_WETNESS_DURATION:
dateHourlyLw_currentDay = trimmedDate(weatherObj.getTimeMeasured(),timeZone);
if(weatherObj.getLogIntervalId().equals(WeatherObservation.LOG_INTERVAL_ID_1H))
{
WeatherObservation altanariaWeatherBO_lw_hourly = weatherObj;
if(
null != dateHourlyLw_currentDay
&& null != dateHourlyLw_previousDay
&& dateHourlyLw_currentDay.after(dateHourlyLw_previousDay)
)
{
int counterLwHourly = 0;
for(WeatherObservation wo: altenariaWeatherLIstHourly_lw)
{
if(wo.getValue() >= THRESHOLD_LW )
{
counterLwHourly = counterLwHourly + 1;
}
}
dataMatrix.setParamIntValueForDate( altenariaWeatherLIstHourly_tm.add(altanariaWeatherBO_tm_hourly);
dateHourlyLw_previousDay }
, DataMatrix.LEAF_WETNESS_DURATION
, counterLwHourly if (weatherObj.getLogIntervalId().equals(WeatherObservation.LOG_INTERVAL_ID_1D)) {
); if ((null == dataMatrix.getParamDoubleValueForDate(dateHourlyTm_currentDay,
DataMatrix.TEMPERATURE_MEAN))
altenariaWeatherLIstHourly_lw = new ArrayList<WeatherObservation>(); ||
((dataMatrix.getParamDoubleValueForDate(dateHourlyTm_currentDay,
DataMatrix.TEMPERATURE_MEAN)).intValue() == 0)) {
dataMatrix.setParamDoubleValueForDate(
weatherObj.getTimeMeasured() // TODO - Might be the date need to be trimmed
, DataMatrix.TEMPERATURE_MEAN, weatherObj.getValue());
}
}
break;
case DataMatrix.LEAF_WETNESS_DURATION:
dateHourlyLw_currentDay = trimmedDate(weatherObj.getTimeMeasured(), timeZone);
if (weatherObj.getLogIntervalId().equals(WeatherObservation.LOG_INTERVAL_ID_1H)) {
WeatherObservation altanariaWeatherBO_lw_hourly = weatherObj;
if (null != dateHourlyLw_currentDay
&& null != dateHourlyLw_previousDay
&& dateHourlyLw_currentDay.after(dateHourlyLw_previousDay)) {
int counterLwHourly = 0;
for (WeatherObservation wo : altenariaWeatherLIstHourly_lw) {
if (wo.getValue() >= THRESHOLD_LW) {
counterLwHourly = counterLwHourly + 1;
}
} }
altenariaWeatherLIstHourly_lw.add(altanariaWeatherBO_lw_hourly); dataMatrix.setParamIntValueForDate(
dateHourlyLw_previousDay, DataMatrix.LEAF_WETNESS_DURATION, counterLwHourly);
altenariaWeatherLIstHourly_lw = new ArrayList<WeatherObservation>();
} }
break;
}
if(null != sprayingDates && sprayingDates.size() != 0) altenariaWeatherLIstHourly_lw.add(altanariaWeatherBO_lw_hourly);
{ }
for (Date spDate:sprayingDates)
{ break;
spDate = trimmedDate(spDate, timeZone);
if( }
(null != spDate && (null != dateHourlyTm_previousDay ) && (null != dateHourlyLw_previousDay))
&& if (null != sprayingDates && sprayingDates.size() != 0) {
( for (Date spDate : sprayingDates) {
( spDate.compareTo(dateHourlyTm_previousDay)== 0 || spDate.before(dateHourlyTm_previousDay) ) spDate = trimmedDate(spDate, timeZone);
|| ( spDate.compareTo(dateHourlyLw_previousDay)== 0 || spDate.before(dateHourlyLw_previousDay) ) if ((null != spDate && (null != dateHourlyTm_previousDay) && (null != dateHourlyLw_previousDay))
) &&
) ((spDate.compareTo(dateHourlyTm_previousDay) == 0
{ || spDate.before(dateHourlyTm_previousDay))
sprayDate = trimmedDate(spDate, timeZone); || (spDate.compareTo(dateHourlyLw_previousDay) == 0
} || spDate.before(dateHourlyLw_previousDay)))) {
sprayDate = trimmedDate(spDate, timeZone);
}
}
} }
} // Setting DSV values to dataMatrix
//Setting DSV values to dataMatrix setDSV(dataMatrix, dateHourlyTm_previousDay, DataMatrix.TEMPERATURE_MEAN, dateHourlyLw_previousDay,
setDSV(dataMatrix DataMatrix.LEAF_WETNESS_DURATION, sprayDate);
, dateHourlyTm_previousDay
, DataMatrix.TEMPERATURE_MEAN
, dateHourlyLw_previousDay
, DataMatrix.LEAF_WETNESS_DURATION
, sprayDate
);
dateHourlyTm_previousDay = dateHourlyTm_currentDay; dateHourlyTm_previousDay = dateHourlyTm_currentDay;
dateHourlyLw_previousDay = dateHourlyLw_currentDay; dateHourlyLw_previousDay = dateHourlyLw_currentDay;
} }
//LOGGER.log(Level.INFO, dataMatrix.toString()); // LOGGER.log(Level.INFO, dataMatrix.toString());
} }
/** /**
* method name : getDSV * method name : getDSV
*
* @param temp * @param temp
* @param lw * @param lw
* @return * @return
* purpose : DSV (Daily Severity Value) calculation based on mean temperature * purpose : DSV (Daily Severity Value) calculation based on mean
* and Leaf Wetness * temperature
* and Leaf Wetness
*/ */
public int getDSV_DAILY(double temp, int lw ) public int getDSV_DAILY(double temp, int lw) {
{
int dsvResult = 0; int dsvResult = 0;
if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw <= 6)) dsvResult = 0; if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw <= 6))
if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw >= 7 && lw <= 15 )) dsvResult = 1; dsvResult = 0;
if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw >= 16 && lw <= 20 )) dsvResult = 2; if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw >= 7 && lw <= 15))
if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw > 21 )) dsvResult = 3; dsvResult = 1;
if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw >= 16 && lw <= 20))
if ((temp >= 18 && temp <= 20) && (lw <= 3 )) dsvResult = 0; dsvResult = 2;
if ((temp >= 18 && temp <= 20) && (lw >= 4 && lw <= 8 )) dsvResult = 1; if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw > 21))
if ((temp >= 18 && temp <= 20) && (lw >= 9 && lw <= 15)) dsvResult = 2; dsvResult = 3;
if ((temp >= 18 && temp <= 20) && (lw >= 16 && lw <= 22)) dsvResult = 3;
if ((temp >= 18 && temp <= 20) && (lw >= 23)) dsvResult = 4; if ((temp >= 18 && temp <= 20) && (lw <= 3))
dsvResult = 0;
if ((temp >= 21 && temp <= 25) && (lw <= 2 )) dsvResult = 0; if ((temp >= 18 && temp <= 20) && (lw >= 4 && lw <= 8))
if ((temp >= 21 && temp <= 25) && (lw >= 3 && lw <= 5 )) dsvResult = 1; dsvResult = 1;
if ((temp >= 21 && temp <= 25) && (lw >= 6 && lw <= 12)) dsvResult = 2; if ((temp >= 18 && temp <= 20) && (lw >= 9 && lw <= 15))
if ((temp >= 21 && temp <= 25) && (lw >= 13 && lw <= 20)) dsvResult = 3; dsvResult = 2;
if ((temp >= 21 && temp <= 25) && (lw >= 21)) dsvResult = 4; if ((temp >= 18 && temp <= 20) && (lw >= 16 && lw <= 22))
dsvResult = 3;
if ((temp >= 26 && temp <= 29) && (lw <= 3)) dsvResult = 0; if ((temp >= 18 && temp <= 20) && (lw >= 23))
if ((temp >= 26 && temp <= 29) && (lw >= 4 && lw <= 8)) dsvResult = 1; dsvResult = 4;
if ((temp >= 26 && temp <= 29) && (lw >= 9 && lw <= 15)) dsvResult = 2;
if ((temp >= 26 && temp <= 29) && (lw >= 16 && lw <= 22)) dsvResult = 3; if ((temp >= 21 && temp <= 25) && (lw <= 2))
if ((temp >= 26 && temp <= 29) && (lw >= 23 )) dsvResult = 4; dsvResult = 0;
if ((temp >= 21 && temp <= 25) && (lw >= 3 && lw <= 5))
dsvResult = 1;
if ((temp >= 21 && temp <= 25) && (lw >= 6 && lw <= 12))
dsvResult = 2;
if ((temp >= 21 && temp <= 25) && (lw >= 13 && lw <= 20))
dsvResult = 3;
if ((temp >= 21 && temp <= 25) && (lw >= 21))
dsvResult = 4;
if ((temp >= 26 && temp <= 29) && (lw <= 3))
dsvResult = 0;
if ((temp >= 26 && temp <= 29) && (lw >= 4 && lw <= 8))
dsvResult = 1;
if ((temp >= 26 && temp <= 29) && (lw >= 9 && lw <= 15))
dsvResult = 2;
if ((temp >= 26 && temp <= 29) && (lw >= 16 && lw <= 22))
dsvResult = 3;
if ((temp >= 26 && temp <= 29) && (lw >= 23))
dsvResult = 4;
return dsvResult; return dsvResult;
} }
/** /**
* Get a trimmed date without hour,minute,second,milli second * Get a trimmed date without hour,minute,second,milli second
*
* @param date * @param date
* @return * @return
*/ */
private Date trimmedDate(Date date, TimeZone timezone) private Date trimmedDate(Date date, TimeZone timezone) {
{ Date resultDate = date;
Date resultDate = date; Calendar calendar = Calendar.getInstance();
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(timezone); calendar.setTimeZone(timezone);
calendar.setTime(resultDate); calendar.setTime(resultDate);
calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE,0); calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND,0); calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND,0); calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime(); return calendar.getTime();
} }
/** /**
* Set DSV values to the DataMatrix in HashMap * Set DSV values to the DataMatrix in HashMap
*
* @param dataMatrix * @param dataMatrix
* @param tmDate * @param tmDate
* @param tmFlag * @param tmFlag
* @param lwDate * @param lwDate
* @param lwFlag * @param lwFlag
*/ */
private void setDSV( private void setDSV(
DataMatrix dataMatrix, Date tmDate, String tmFlag, Date lwDate, String lwFlag, Date sprayDate) DataMatrix dataMatrix, Date tmDate, String tmFlag, Date lwDate, String lwFlag, Date sprayDate) {
{ int resultDSV_tm = 0;
int resultDSV_tm = 0; int resultDSV_lw = 0;
int resultDSV_lw = 0;
if ((null != tmDate) && (null != lwDate)) {
if((null != tmDate) && (null != lwDate)) resultDSV_tm = getDSV_DAILY(
{ getMeanTeamperature(dataMatrix, tmDate, tmFlag),
getLeafWetnessHour(dataMatrix, tmDate, lwFlag));
resultDSV_tm = getDSV_DAILY(
getMeanTeamperature(dataMatrix,tmDate,tmFlag) dataMatrix.setParamStringValueForDate(tmDate, DataMatrix.SPRAYING_DATE, NO);
, dataMatrix.setParamIntValueForDate(tmDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE, resultDSV_tm);
getLeafWetnessHour(dataMatrix,tmDate,lwFlag) 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(tmDate, DataMatrix.SPRAYING_DATE, NO); dataMatrix.setParamStringValueForDate(sprayDate, 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))
{ resultDSV_lw = getDSV_DAILY(
dataMatrix.setParamStringValueForDate(sprayDate, DataMatrix.SPRAYING_DATE, YES); getMeanTeamperature(dataMatrix, lwDate, tmFlag),
} getLeafWetnessHour(dataMatrix, lwDate, lwFlag));
else if(null == sprayDate || sprayDate.after(tmDate))
{ dataMatrix.setParamStringValueForDate(lwDate, DataMatrix.SPRAYING_DATE, NO);
dataMatrix.setParamStringValueForDate(sprayDate, 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);
}
}
resultDSV_lw = getDSV_DAILY(
getMeanTeamperature(dataMatrix,lwDate,tmFlag)
,
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);
}
}
} }
} }
/** /**
* *
* @param dataMatrix * @param dataMatrix
* @param tmDate * @param tmDate
* @param tmFlag * @param tmFlag
* @return * @return
*/ */
private double getMeanTeamperature ( DataMatrix dataMatrix private double getMeanTeamperature(DataMatrix dataMatrix, Date tmDate, String tmFlag) {
, Date tmDate return (null == dataMatrix.getParamDoubleValueForDate(tmDate, tmFlag))
, String tmFlag ? 0.0
) : dataMatrix.getParamDoubleValueForDate(tmDate, tmFlag);
{
return (null == dataMatrix.getParamDoubleValueForDate(tmDate, tmFlag))
? 0.0
: dataMatrix.getParamDoubleValueForDate(tmDate, tmFlag);
} }
/** /**
* *
* @param dataMatrix * @param dataMatrix
* @param lwDate * @param lwDate
* @param lwFlag * @param lwFlag
* @return * @return
*/ */
private int getLeafWetnessHour( private int getLeafWetnessHour(
DataMatrix dataMatrix DataMatrix dataMatrix, Date lwDate, String lwFlag) {
, Date lwDate return (null == dataMatrix.getParamIntValueForDate(lwDate, lwFlag))
, String lwFlag ? 0
) : dataMatrix.getParamIntValueForDate(lwDate, lwFlag);
{
return (null == dataMatrix.getParamIntValueForDate(lwDate, lwFlag))
? 0
: dataMatrix.getParamIntValueForDate(lwDate, lwFlag);
} }
private Integer getWarningStatus(Integer accumulatedDSV)
{
Integer result = 0;
/*
Hint of warning system
1 = Missing data (Blue) - OK
2 = No Risk (Green) – From 0 to DSV-threshold minus 5 private Integer getWarningStatus(Integer accumulatedDSV) {
Integer result = 0;
3 = Possible Risk (Yellow) – From DSV-threshold minus 5 to DSV-threshold /*
* Hint of warning system
* 1 = Missing data (Blue) - OK
*
* 2 = No Risk (Green) – From 0 to DSV-threshold minus 5
*
* 3 = Possible Risk (Yellow) – From DSV-threshold minus 5 to DSV-threshold
*
* 4 = High Risk (Red) – {Above DSV-threshold
*/
4 = High Risk (Red) – {Above DSV-threshold if (accumulatedDSV >= 0) {
*/ if (accumulatedDSV >= THRESHOLD_DSV_MAX) {
if (accumulatedDSV >= 0)
{
if(accumulatedDSV >= THRESHOLD_DSV_MAX)
{
result = Result.WARNING_STATUS_HIGH_RISK; result = Result.WARNING_STATUS_HIGH_RISK;
} } else {
else
{
// e.g. 20 -- 30 // e.g. 20 -- 30
if((accumulatedDSV < THRESHOLD_DSV_MAX) && (accumulatedDSV >= (THRESHOLD_DSV_MAX - THRESHOLD_DSV_DIFF_MIN_MAX)) ) if ((accumulatedDSV < THRESHOLD_DSV_MAX)
{ && (accumulatedDSV >= (THRESHOLD_DSV_MAX - THRESHOLD_DSV_DIFF_MIN_MAX))) {
result = Result.WARNING_STATUS_MINOR_RISK; result = Result.WARNING_STATUS_MINOR_RISK;
} } else {
else if (accumulatedDSV < (THRESHOLD_DSV_MAX - THRESHOLD_DSV_DIFF_MIN_MAX)) {
{
if(accumulatedDSV < (THRESHOLD_DSV_MAX - THRESHOLD_DSV_DIFF_MIN_MAX))
{
result = Result.WARNING_STATUS_NO_RISK; result = Result.WARNING_STATUS_NO_RISK;
} }
} }
} }
} else {
result = Result.WARNING_STATUS_NO_WARNING_MISSING_DATA;
} }
else
{
result = Result.WARNING_STATUS_NO_WARNING_MISSING_DATA;
}
return result; return result;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment