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

Added configurable model parameters

parent 65fd6f5f
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,8 @@
package no.nibio.vips.model.yellowstemborertempmodel;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -60,13 +62,13 @@ public class YellowStemborerTempModel extends I18nImpl implements Model {
// Threshold values
// MUST BE ADJUSTED!!!!!!
private final Double dd_lower = 0.0;
private final Double dd_upper = 40.0;
// TODO: ADJUST with actual biologically sensible defaults
private Double dd_lower = 0.0;
private Double dd_upper = 40.0;
private final Double THRESHOLD_1 = 260.0; // Egg to larvae
private final Double THRESHOLD_2 = 360.0; // Larvae to pupa
private final Double THRESHOLD_3 = 560.0; // Pupa to adult
private Double THRESHOLD_1 = 260.0; // Egg to larvae
private Double THRESHOLD_2 = 360.0; // Larvae to pupa
private Double THRESHOLD_3 = 560.0; // Pupa to adult
public YellowStemborerTempModel()
{
......@@ -238,7 +240,35 @@ public class YellowStemborerTempModel extends I18nImpl implements Model {
@Override
public void setConfiguration(ModelConfiguration config) throws ConfigValidationException {
// Adjusting defaults
try
{
if(config.getConfigParameter("THRESHOLD_1") != null)
{
this.THRESHOLD_1 = this.modelUtil.getDouble(config.getConfigParameter("THRESHOLD_1"));
}
if(config.getConfigParameter("THRESHOLD_2") != null)
{
this.THRESHOLD_2 = this.modelUtil.getDouble(config.getConfigParameter("THRESHOLD_2"));
}
if(config.getConfigParameter("THRESHOLD_3") != null)
{
this.THRESHOLD_3 = this.modelUtil.getDouble(config.getConfigParameter("THRESHOLD_3"));
}
if(config.getConfigParameter("dd_lower") != null)
{
this.dd_lower = this.modelUtil.getDouble(config.getConfigParameter("dd_lower"));
}
if(config.getConfigParameter("dd_upper") != null)
{
this.dd_upper = this.modelUtil.getDouble(config.getConfigParameter("dd_upper"));
}
}
catch(ClassCastException ex)
{
throw new ConfigValidationException(ex.getMessage());
}
// Init data matrix
this.dataMatrix = new DataMatrix();
......@@ -250,7 +280,6 @@ public class YellowStemborerTempModel extends I18nImpl implements Model {
try
{
this.biofixDate = format.parse((String) config.getConfigParameter("biofixDate"));
System.out.println("BiofixDate=" + this.biofixDate);
}
catch(ParseException ex)
{
......@@ -328,5 +357,7 @@ public class YellowStemborerTempModel extends I18nImpl implements Model {
today = cal.getTime();
}
}
}
......@@ -5,6 +5,7 @@
*/
package no.nibio.vips.model.yellowstemborertempmodel;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.Result;
......@@ -53,14 +54,21 @@ public class YellowStemborerTempModelTest {
ModelConfiguration config = wfr.getModelConfigurationWithWeatherData("/test_data_2019.json", YellowStemborerTempModel.MODEL_ID.toString());
config.setConfigParameter("timeZone", "GMT+05:30");
config.setConfigParameter("biofixDate", "2019-01-05");
config.setConfigParameter("THRESHOLD_1", 290.0);
config.setConfigParameter("THRESHOLD_2", 390.0);
config.setConfigParameter("THRESHOLD_3", 590);
config.setConfigParameter("dd_lower", 15);
config.setConfigParameter("dd_upper", 31.1);
// Print the config
//System.out.println(config.toJSON());
System.out.println(config.toJSON());
YellowStemborerTempModel instance = new YellowStemborerTempModel();
instance.setConfiguration(config);
List<Result> result = instance.getResult();
assertNotNull(result);
// Print the result
//ObjectMapper mapper = new ObjectMapper();
//System.out.println(mapper.writeValueAsString(result));
//result.forEach(r->System.out.println(r));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment