Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • feature/vips-test
  • main
  • release
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.1.0
  • v1.1.1
  • v1.1.10
  • v1.1.11
  • v1.1.12
  • v1.1.13
  • v1.1.14
  • v1.1.15
  • v1.1.16
  • v1.1.17
  • v1.1.18
  • v1.1.19
  • v1.1.2
  • v1.1.20
  • v1.1.21
  • v1.1.22
  • v1.1.23
  • v1.1.3
  • v1.1.4
  • v1.1.5
  • v1.1.6
  • v1.1.7
  • v1.1.8
  • v1.1.9
30 results

Target

Select target project
  • VIPS/models/java/Model_ALTERNARIA
1 result
Select Git revision
  • feature/vips-test
  • main
  • release
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.1.0
  • v1.1.1
  • v1.1.10
  • v1.1.11
  • v1.1.12
  • v1.1.13
  • v1.1.14
  • v1.1.15
  • v1.1.16
  • v1.1.17
  • v1.1.18
  • v1.1.19
  • v1.1.2
  • v1.1.20
  • v1.1.21
  • v1.1.22
  • v1.1.23
  • v1.1.3
  • v1.1.4
  • v1.1.5
  • v1.1.6
  • v1.1.7
  • v1.1.8
  • v1.1.9
30 results
Show changes
Commits on Source (27)
target/ target/
.idea .idea
\ No newline at end of file .vscode
\ No newline at end of file
# AlternariaModel # AlternariaModel (TOMCAST)
<p><img src="src/main/resources/images/ef-20200421-altenaria.jpg" description="Photo: Bilde: S. Abrahamsen, NLR"/></p> <img src="src/main/resources/images/ef-20200421-altenaria.jpg" description="Photo: S. Abrahamsen, NLR"/>
<p>TOMCAST is based on a model that was originally developed for leaf spot diseases in tomato. The model that is used here is tested and adapted to be used against early blight in potato in Denmark (Alternaria solani). The model calculates daily risk values (DSV: Disease Severity Values) based on temperature and leaf wetness the previous day. DSV represents the risk of attack of early blight the previous 24 hours. Daily values of DSV are accumulated until a threshold value is reached, and treatment is recommended. When a spray is performed and entered into the model, accumulation of DSV is reset and starts over at 0.</p>
<p>The model will be evaluated in potato and carrots in Norway in 2020, and is only available for private warnings. Based on experience from other countries, the threshold for a warning to be issued is set to 20.</p>
<h3>When to initiate the model</h3>
<p>Potato plants vary in susceptibility during the season, and gradually become more susceptible. This means that the requirement for protection against early blight vary accordingly. The model is started when the first symptoms are visible, and first treatment is performed (below 0,1% attack).</p>
<h3>Interpretation of results</h3>
<p>The model will be green (no risk) until it reaches 15. From this value the warning will be yellow (possible risk) until the threshold is reached, and the warning turns red (risk of infection).</p>
### Development _Photo: S. Abrahamsen, NLR_
TOMCAST is based on a model that was originally developed for leaf spot diseases in tomato. The model that is used here is tested and adapted to be used against early blight in potato in Denmark (Alternaria solani). The model calculates daily risk values (DSV: Disease Severity Values) based on temperature and leaf wetness the previous day. DSV represents the risk of attack of early blight the previous 24 hours. Daily values of DSV are accumulated until a threshold value is reached, and treatment is recommended. When a spray is performed and entered into the model, accumulation of DSV is reset and starts over at 0.
## Configurable parameters
### Lower temperature threshold for DSV
Default value: 13.0 (as in the original TOMCAST model)
### DSV (Daily Severity Value) Threshold for high infection risk
Default value: 20
## When to initiate the model
Potato plants vary in susceptibility during the season, and gradually become more susceptible. This means that the requirement for protection against early blight vary accordingly. The model is started when the first symptoms are visible, and first treatment is performed (below 0,1% attack).
## Interpretation of results
The model will be green (no risk) until it reaches 15. From this value the warning will be yellow (possible risk) until the threshold is reached, and the warning turns red (risk of infection).
## Development
Requirements:
* Maven
* Java 11
Clone Gitlab repository Clone Gitlab repository
``` ```
$ git clone https://gitlab.nibio.no/VIPS/models/java/Model_ALTERNARIA.git $ git clone https://gitlab.nibio.no/VIPS/models/java/Model_ALTERNARIA.git
$ cd Model_ALTERNARIA $ cd Model_ALTERNARIA
```
Build
```
$ mvn install
``` ```
\ No newline at end of file
...@@ -5,19 +5,19 @@ ...@@ -5,19 +5,19 @@
<parent> <parent>
<groupId>no.nibio.vips</groupId> <groupId>no.nibio.vips</groupId>
<artifactId>vips-parent-pom</artifactId> <artifactId>vips-parent-pom</artifactId>
<version>1.0.0</version> <version>1.1.0</version>
</parent> </parent>
<groupId>no.nibio.vips.model</groupId> <groupId>no.nibio.vips.model</groupId>
<artifactId>AlternariaModel</artifactId> <artifactId>AlternariaModel</artifactId>
<version>1.1.7-SNAPSHOT</version> <version>1.1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>no.nibio.vips</groupId> <groupId>no.nibio.vips</groupId>
<artifactId>VIPSCommon</artifactId> <artifactId>VIPSCommon</artifactId>
<version>2.0.3</version> <version>2.1.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
......
...@@ -39,13 +39,17 @@ package no.nibio.vips.model.alternariamodel; ...@@ -39,13 +39,17 @@ package no.nibio.vips.model.alternariamodel;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Scanner;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -62,133 +66,139 @@ import no.nibio.vips.util.CommonNamespaces; ...@@ -62,133 +66,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 private Double THRESHOLD_DSV_MAX = 20.0; // 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
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));
result.setValue(NAME_MODEL_ID, DataMatrix.THRESHOLD_DSV_TEMP_MIN, String.valueOf(this.THRESHOLD_DSV_TEMP_MIN));
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);
} }
...@@ -196,64 +206,64 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -196,64 +206,64 @@ 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() {
{ return this.modelUtil.getTextFromFileInJar(this.getClass(), "/LICENSE_header.txt");
/**
* method name : getLicense
* @param :
* @return : java.lang.String
*
* 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.
*/
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);
} }
...@@ -261,507 +271,456 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -261,507 +271,456 @@ 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 *
* @return *
* @return a Json configuration example
*/ */
@Override @Override
public String getSampleConfig() public String getSampleConfig() {
{ return this.modelUtil.getTextFromFileInJar(this.getClass(), "/sample_config.json");
/**
* method name : getSampleConfig
* @param :
* @return : java.lang.String
*
* 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.
*/
return this.getText("sampleconfig", Model.DEFAULT_LANGUAGE);
} }
/** /**
* *
* @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>(); try
{
Date dateHourlyTm_currentDay = null; this.THRESHOLD_DSV_TEMP_MIN = config.getConfigParameter(DataMatrix.THRESHOLD_DSV_TEMP_MIN) != null ? modelUtil.getDouble(config.getConfigParameter(DataMatrix.THRESHOLD_DSV_TEMP_MIN)): this.THRESHOLD_DSV_TEMP_MIN;
Date dateHourlyTm_previousDay = null; this.THRESHOLD_DSV_MAX = config.getConfigParameter(DataMatrix.THRESHOLD_DSV_MAX) != null ? modelUtil.getDouble(config.getConfigParameter(DataMatrix.THRESHOLD_DSV_MAX)) : this.THRESHOLD_DSV_MAX;
Date dateHourlyLw_currentDay = null; }
Date dateHourlyLw_previousDay = null; catch(ClassCastException ex)
{
throw new ConfigValidationException(ex.getMessage());
}
Date dateHourlyTm_currentDay = null;
Date dateHourlyTm_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 >= 10 && temp <= 17) && (lw <= 6)) dsvResult = 0; if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw <= 6))
if ((temp >= 10 && temp <= 17) && (lw >= 7 && lw <= 15 )) dsvResult = 1; dsvResult = 0;
if ((temp >= 10 && temp <= 17) && (lw >= 16 && lw <= 20 )) dsvResult = 2; if ((temp >= this.THRESHOLD_DSV_TEMP_MIN && temp <= 17) && (lw >= 7 && lw <= 15))
if ((temp >= 10 && 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;
} }
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Organization : NIBIO, Ås * Organization : NIBIO, Ås
* Department : VIPS * Department : VIPS
* *
* Author : bhabesh * Author : bhabesh & Tor-Einar Skog
* *
* *
* File Name : DataMatrix.java * File Name : DataMatrix.java
...@@ -16,22 +16,23 @@ ...@@ -16,22 +16,23 @@
*/ */
/* /*
* *
*
Copyright (c) 2016 NIBIO <http://www.nibio.no/>. * Copyright (c) 2020-2024 NIBIO <http://www.nibio.no/>.
*
This file is part of AlternariaModel. * This file is part of AlternariaModel.
AlternariaModel is free software: you can redistribute it and/or modify *
it under the terms of the NIBIO Open Source License as published by * This program is free software: you can redistribute it and/or modify
NIBIO, either version 1 of the License, or (at your option) any * it under the terms of the GNU Affero General Public License as published by
later version. * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
AlternariaModel is distributed in the hope that it will be useful, *
but WITHOUT ANY WARRANTY; without even the implied warranty of * This program is distributed in the hope that it will be useful,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
NIBIO Open Source License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
You should have received a copy of the NIBIO Open Source License *
along with AlternariaModel. If not, see <http://www.nibio.no/licenses/>. * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
...@@ -42,6 +43,7 @@ import no.nibio.vips.util.DateMap; ...@@ -42,6 +43,7 @@ import no.nibio.vips.util.DateMap;
/** /**
* *
* @author bhabesh * @author bhabesh
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/ */
public class DataMatrix extends DateMap{ public class DataMatrix extends DateMap{
public final static String WET_HOUR = "WH"; // Leaf wetness 2 m, minutes per hour public final static String WET_HOUR = "WH"; // Leaf wetness 2 m, minutes per hour
...@@ -53,8 +55,8 @@ public class DataMatrix extends DateMap{ ...@@ -53,8 +55,8 @@ public class DataMatrix extends DateMap{
public final static String SPRAYING_DATE = "sprayingDate"; // Spray Date public final static String SPRAYING_DATE = "sprayingDate"; // Spray Date
public final static String THRESHOLD_DSV_BASE = "THRESHOLD_DSV_BASE"; // THRESHOLD_DSV_BASE public final static String THRESHOLD_DSV_BASE = "THRESHOLD_DSV_BASE"; // THRESHOLD_DSV_BASE
public final static String THRESHOLD_DSV_MAX = "THRESHOLD_DSV_MAX"; // THRESHOLD_DSV_MAX public final static String THRESHOLD_DSV_MAX = "thresholdDSVMax"; // THRESHOLD_DSV_MAX
public final static String THRESHOLD_DSV_TEMP_MIN = "thresholdDSVTempMin";
......
Copyright (C) 2024 Tor-Einar Skog <tor-einar.skog@nibio.no>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
...@@ -26,35 +26,3 @@ observations - list of weather data. The following parameters are required:\n\ ...@@ -26,35 +26,3 @@ observations - list of weather data. The following parameters are required:\n\
* TM - Average temperature (Degrees Celcius)\n\ * TM - Average temperature (Degrees Celcius)\n\
* BT - Leaf wetness (Minutes/hour) (IF you don't have leaf wetness, you must provide UM (relative humidity). Then we will calculate the leaf wetness.\n\ * BT - Leaf wetness (Minutes/hour) (IF you don't have leaf wetness, you must provide UM (relative humidity). Then we will calculate the leaf wetness.\n\
sprayingDate - (Optional) Farmers can choose multiple spraying dates (upto four spraying dates). sprayingDate - (Optional) Farmers can choose multiple spraying dates (upto four spraying dates).
license= Copyright (c) 2020 NIBIO <http://www.nibio.no/>. \n \nThis file is part of AlternariaModel. \nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU Affero General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU Affero General Public License for more details.\n\nYou should have received a copy of the GNU Affero General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.
sampleconfig={ \n\
\t "loginInfo": { \n\
\t\t "username": "example", \n\
\t\t "password": "example" \n\
\t }, \n\
\t "modelId": "ALTERNARIA", \n\
\t "configParameters": { \n\
\t "timeZone": "Europe/Oslo", \n\
\t "observations": [ \n\
\t { \n\
\t\t "elementMeasurementTypeId": "TM", \n\
\t\t "logIntervalId": 1, \n\
\t\t "timeMeasured": "2018-08-11T00:00:00+02:00", \n\
\t\t "value": 10.46 \n\
\t }, \n\
\t { \n\
\t\t "elementMeasurementTypeId": "BT", \n\
\t\t "logIntervalId": 1, \n\
\t\t "timeMeasured": "2018-08-11T00:00:00+02:00", \n\
\t\t "value": 60.0 \n\
\t } \n\
\t ], \n\
\t "sprayingDates": [ \n\
\t\t "2018-07-02T22:00:00Z", \n\
\t\t "2018-07-30T22:00:00Z", \n\
\t\t "2018-09-04T22:00:00Z" \n\
\t ] \n\
\t } \n\
} \n\
...@@ -19,4 +19,3 @@ name=TOMCAST (FAST - Dew) modell for Alternaria ...@@ -19,4 +19,3 @@ name=TOMCAST (FAST - Dew) modell for Alternaria
description= <p>{{filename="/images/ef-20200421-altenaria.jpg" description="Photo: Bilde: S. Abrahamsen, NLR"}}</p>\n<p>TOMCAST er basert p&aring; en modell utviklet for varsling av bladflekksjukdommer i tomat. Versjonen som blir brukt her er testet og tilpasset t&oslash;rrflekksjuke i potet (Alternaria solani) i Danmark. Modellen beregner daglige risikoverdier (DSV: Disease Severity Value) basert p&aring; temperatur og bladfuktighet siste d&oslash;gn. DSV representerer risikoen for angrep av t&oslash;rrflekksjuke siste d&oslash;gn. Daglige DSV-verdier blir summert frem til en terskel er n&aring;dd og behandling er anbefalt. Modellen er laget slik at akkumulering av DSV nullstilles n&aring;r spr&oslash;yting gjennomf&oslash;res, og akkumulering starter p&aring; nytt fra 0.</p>\n<p>Modellen er under utpr&oslash;ving i 2020, og vil bli testet b&aring;de i gulrot og i potet. Det vil kun v&aelig;re mulig &aring; starte private varler for denne modellen. Basert p&aring; erfaringer fra andre land er terskelverdien for r&oslash;dt varsel satt til 20.</p>\n<h3>Oppstart av varsel</h3>\n<p>Potetplanter varierer i mottakelighet for t&oslash;rrflekksjuke gjennom sesongen, og de blir gradvis mer og mer mottakelige. Dette betyr at behovet for beskyttelse ogs&aring; varierer tilsvarende. Modellen startes n&aring;r man ser de f&oslash;rste symptomene p&aring; t&oslash;rrflekksjuke og gjennomf&oslash;rer f&oslash;rste behandling (under 0,1% angrep).</p>\n<h3>Tolking av varsel</h3>\n<p>Modellen vil vise gr&oslash;nt (ingen fare) frem til den akkumulerte risikoverdien er 15. Fra denne verdien frem til terskelverdien (20) vil varselet v&aelig;re gult (mulig fare), og deretter g&aring; over til r&oslash;dt (fare).</p> description= <p>{{filename="/images/ef-20200421-altenaria.jpg" description="Photo: Bilde: S. Abrahamsen, NLR"}}</p>\n<p>TOMCAST er basert p&aring; en modell utviklet for varsling av bladflekksjukdommer i tomat. Versjonen som blir brukt her er testet og tilpasset t&oslash;rrflekksjuke i potet (Alternaria solani) i Danmark. Modellen beregner daglige risikoverdier (DSV: Disease Severity Value) basert p&aring; temperatur og bladfuktighet siste d&oslash;gn. DSV representerer risikoen for angrep av t&oslash;rrflekksjuke siste d&oslash;gn. Daglige DSV-verdier blir summert frem til en terskel er n&aring;dd og behandling er anbefalt. Modellen er laget slik at akkumulering av DSV nullstilles n&aring;r spr&oslash;yting gjennomf&oslash;res, og akkumulering starter p&aring; nytt fra 0.</p>\n<p>Modellen er under utpr&oslash;ving i 2020, og vil bli testet b&aring;de i gulrot og i potet. Det vil kun v&aelig;re mulig &aring; starte private varler for denne modellen. Basert p&aring; erfaringer fra andre land er terskelverdien for r&oslash;dt varsel satt til 20.</p>\n<h3>Oppstart av varsel</h3>\n<p>Potetplanter varierer i mottakelighet for t&oslash;rrflekksjuke gjennom sesongen, og de blir gradvis mer og mer mottakelige. Dette betyr at behovet for beskyttelse ogs&aring; varierer tilsvarende. Modellen startes n&aring;r man ser de f&oslash;rste symptomene p&aring; t&oslash;rrflekksjuke og gjennomf&oslash;rer f&oslash;rste behandling (under 0,1% angrep).</p>\n<h3>Tolking av varsel</h3>\n<p>Modellen vil vise gr&oslash;nt (ingen fare) frem til den akkumulerte risikoverdien er 15. Fra denne verdien frem til terskelverdien (20) vil varselet v&aelig;re gult (mulig fare), og deretter g&aring; over til r&oslash;dt (fare).</p>
statusInterpretation=Modellen vil vise gr\u00f8nt (ingen fare) frem til den akkumulerte risikoverdien er 15. Fra denne verdien frem til terskelverdien (20) vil varselet v\u00e6re gult (mulig fare), og deretter g\u00e5 over til r\u00f8dt (fare). statusInterpretation=Modellen vil vise gr\u00f8nt (ingen fare) frem til den akkumulerte risikoverdien er 15. Fra denne verdien frem til terskelverdien (20) vil varselet v\u00e6re gult (mulig fare), og deretter g\u00e5 over til r\u00f8dt (fare).
usage=TODO usage=TODO
license=Copyright (c) 2020 NIBIO <http://www.nibio.no/>. \n \nThis file is part of AlternariaModel. \nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU Affero General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU Affero General Public License for more details.\n\nYou should have received a copy of the GNU Affero General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.
{
"loginInfo": {
"username": "example",
"password": "example"
},
"modelId": "ALTERNARIA",
"configParameters": {
"sprayingDates": [
"2018-07-02T22:00:00Z",
"2018-07-30T22:00:00Z",
"2018-09-04T22:00:00Z"
],
"thresholdDSVTempMin": "10.0",
"thresholdDSVMax": "20.0",
"timeZone": "Europe/Oslo",
"observations": [
{
"elementMeasurementTypeId": "TM",
"logIntervalId": 1,
"timeMeasured": "2018-08-11T00:00:00+02:00",
"value": 10.46
},
{
"elementMeasurementTypeId": "BT",
"logIntervalId": 1,
"timeMeasured": "2018-08-11T00:00:00+02:00",
"value": 60
}
]
}
}
\ No newline at end of file
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright (c) 2020 NIBIO <http://www.nibio.no/>.
* To change this template file, choose Tools | Templates
* and open the template in the editor. This file is part of AlternariaModel.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package no.nibio.vips.model.alternariamodel; package no.nibio.vips.model.alternariamodel;
...@@ -25,6 +37,7 @@ import org.junit.jupiter.api.AfterAll; ...@@ -25,6 +37,7 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.DynamicTest.stream;
/** /**
* *
...@@ -104,6 +117,90 @@ public class AlternariaModelTest { ...@@ -104,6 +117,90 @@ public class AlternariaModelTest {
*/ */
}
@org.junit.jupiter.api.Test
public void testGetResultWithThresholdDSVTempMin() throws Exception {
System.out.println("getResultWithThresholdDSVTempMin");
ModelConfiguration config = this.getConfiguration(getWeatherDataFile());
config.setConfigParameter("sprayingDates", this.getConfigurationSprayingDates(getResetDataFile()));
config.setConfigParameter(DataMatrix.THRESHOLD_DSV_TEMP_MIN, 10.0);
AlternariaModel instance = new AlternariaModel();
instance.setConfiguration(config);
List<Result> result = instance.getResult();
assertNotNull(result);
config.setConfigParameter(DataMatrix.THRESHOLD_DSV_TEMP_MIN, "10.0");
instance.setConfiguration(config);
result = instance.getResult();
assertNotNull(result);
/*
for(Result res:result)
{
// LOGGER.log(Level.INFO, res.toString());
System.out.println(res.toString());
}*/
config.setConfigParameter(DataMatrix.THRESHOLD_DSV_TEMP_MIN, "13.0");
//System.out.println(config.toJSON());
instance.setConfiguration(config);
result = instance.getResult();
assertNotNull(result);
/*
for(Result res:result)
{
// LOGGER.log(Level.INFO, res.toString());
System.out.println(res.toString());
} */
}
@org.junit.jupiter.api.Test
public void testGetResultWithThresholdDSVMax() throws Exception {
System.out.println("getResultWithThresholdDSVMax");
ModelConfiguration config = this.getConfiguration(getWeatherDataFile());
config.setConfigParameter("sprayingDates", this.getConfigurationSprayingDates(getResetDataFile()));
config.setConfigParameter(DataMatrix.THRESHOLD_DSV_MAX, 21);
AlternariaModel instance = new AlternariaModel();
instance.setConfiguration(config);
List<Result> result = instance.getResult();
assertNotNull(result);
config.setConfigParameter(DataMatrix.THRESHOLD_DSV_MAX, "21");
instance.setConfiguration(config);
result = instance.getResult();
assertNotNull(result);
/*
for(Result res:result)
{
// LOGGER.log(Level.INFO, res.toString());
System.out.println(res.toString());
}*/
config.setConfigParameter(DataMatrix.THRESHOLD_DSV_MAX, "13.0");
//System.out.println(config.toJSON());
instance.setConfiguration(config);
result = instance.getResult();
assertNotNull(result);
/*
for(Result res:result)
{
// LOGGER.log(Level.INFO, res.toString());
System.out.println(res.toString());
} */
} }
/** /**
...@@ -149,9 +246,8 @@ public class AlternariaModelTest { ...@@ -149,9 +246,8 @@ public class AlternariaModelTest {
public void testGetLicense() { public void testGetLicense() {
System.out.println("getLicense"); System.out.println("getLicense");
AlternariaModel instance = new AlternariaModel(); AlternariaModel instance = new AlternariaModel();
String expResult = "";
String result = instance.getLicense(); String result = instance.getLicense();
assertNotNull(result); assertTrue(result.contains("GNU Affero"));
} }
/** /**
...@@ -251,15 +347,13 @@ public class AlternariaModelTest { ...@@ -251,15 +347,13 @@ public class AlternariaModelTest {
/** /**
* Test of getSampleConfig method, of class AlternariaModel. * Test of getSampleConfig method, of class AlternariaModel.
* TODO - Recheck the functionality
*/ */
@org.junit.jupiter.api.Test @org.junit.jupiter.api.Test
public void testGetSampleConfig() { public void testGetSampleConfig() {
System.out.println("getSampleConfig"); System.out.println("getSampleConfig");
AlternariaModel instance = new AlternariaModel(); AlternariaModel instance = new AlternariaModel();
String expResult = "";
String result = instance.getSampleConfig(); String result = instance.getSampleConfig();
assertNotNull(result); assertTrue(result.contains("configParameters"));
} }
/** /**
......