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

Fixed tests, synchronized JS and Java model algorithm

parent ee8c7435
Branches
Tags
No related merge requests found
......@@ -94,8 +94,7 @@ public class FallArmywormModelJ2V8Adapter extends I18nImpl implements Model{
r.setValidTimeEnd(mapper.convertValue((String)resultObject.getString("validTimeEnd"), Date.class));
V8Object allValues = resultObject.getObject("allValues");
for(String key: allValues.getKeys())
{ System.out.println("key=" + key);
{
String keyWithoutNS = key.split("\\.")[key.split("\\.").length - 1];
String nameSpace = key.split("\\.").length == 1 ? FallArmywormModelJ2V8Adapter.MODEL_ID.toString() : key.split("\\.")[0];
r.setValue(nameSpace, keyWithoutNS, String.valueOf(allValues.get(key)));
......@@ -106,24 +105,11 @@ public class FallArmywormModelJ2V8Adapter extends I18nImpl implements Model{
}
resultArray.release();
String[] keysLeft = this.runtime.getKeys();
System.out.println("Still keeping " + keysLeft[0]);
//this.releaseAll();
this.runtime.release();
return retVal;
}
private void releaseAll()
{
for(String key: this.runtime.getKeys())
{
System.out.println("Trying to release " + key +", which is a " + V8.getStringRepresentation(this.runtime.getType(key)));
((V8Object)this.runtime.get(key)).release();
}
}
public ModelId getModelId() {
return MODEL_ID;
}
......
......@@ -33,9 +33,9 @@ var observations25kmLast3Months = 0;
//var TM_UPPER_THRESHOLD = 26.0;
//var UNFAVOURABLE_TEMP_RISK_REDUCTION = 40/100; // 40% reduction if unfavourable temperature
var RISK_THRESHOLD_HIGH = 100;
var RISK_THRESHOLD_HIGH = 50;
var OBSERVATIONS_10KM_ABSCENCE_RISK_REDUCTION = 10/100; // 10% risk reduction if no observations within 10km
var OBSERVATIONS_25KM_ABSCENCE_RISK_REDUCTION = 60/100; // 60% risk reduction if no observations within 25km
var OBSERVATIONS_25KM_ABSCENCE_RISK_REDUCTION = 70/100; // 60% risk reduction if no observations within 25km
var INTERCROPPING_RISK_REDUCTION = {
"NONE": 0/100,
"OTHER": 10/100,
......
......@@ -2,12 +2,12 @@
* Copyright (c) 2019 NIBIO <http://www.nibio.no/>.
*
* This file is part of FallArmywormModel.
* FallArmywormModel is free software: you can redistribute it and/or modify
* FallArmywormModelGraalVMAdapter 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.
*
* FallArmywormModel is distributed in the hope that it will be useful,
* FallArmywormModelGraalVMAdapter 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.
......@@ -18,7 +18,6 @@
*/
package no.nibio.vips.model.fallarmywormmodel;
import no.nibio.vips.model.fallarmywormmodel.FallArmywormModel;
import java.util.List;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.Result;
......@@ -35,9 +34,9 @@ import static org.junit.Assert.*;
*
* @author treinar
*/
public class FallArmywormModelJSAdapterTest {
public class FallArmywormModelGraalVMAdapterTest {
public FallArmywormModelJSAdapterTest() {
public FallArmywormModelGraalVMAdapterTest() {
}
@BeforeClass
......@@ -72,7 +71,7 @@ public class FallArmywormModelJSAdapterTest {
config.setConfigParameter("intercroppingType", "BEANS/DESMODIUM");
config.setConfigParameter("observations10kmLast3Months", 0);
config.setConfigParameter("observations25kmLast3Months", 0);
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
instance.setConfiguration(config);
List<Result> result = instance.getResult();
assertNotNull(result);
......@@ -87,8 +86,8 @@ public class FallArmywormModelJSAdapterTest {
public void testGetModelId() {
System.out.println("getModelId");
FallArmywormModel instance = new FallArmywormModel();
String expResult = "FAWMODEL01";
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String expResult = "FAWMODEL02";
ModelId result = instance.getModelId();
assertEquals(expResult, result.toString());
......@@ -102,7 +101,7 @@ public class FallArmywormModelJSAdapterTest {
public void testGetModelName_0args() {
System.out.println("getModelName");
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String expResult = "Fall Armyworm Model";
String result = instance.getModelName();
assertEquals(expResult, result);
......@@ -117,7 +116,7 @@ public class FallArmywormModelJSAdapterTest {
System.out.println("getModelName");
String language = "nb";
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String expResult = "Fall Armyworm-modell";
String result = instance.getModelName(language);
assertEquals(expResult, result);
......@@ -131,7 +130,7 @@ public class FallArmywormModelJSAdapterTest {
public void testGetLicense() {
System.out.println("getLicense");
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String expResult = "";
String result = instance.getLicense();
assertNotNull(result);
......@@ -146,7 +145,7 @@ public class FallArmywormModelJSAdapterTest {
public void testGetCopyright() {
System.out.println("getCopyright");
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String result = instance.getCopyright();
assertNotNull(result);
......@@ -160,7 +159,7 @@ public class FallArmywormModelJSAdapterTest {
public void testGetModelDescription_0args() {
System.out.println("getModelDescription");
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String result = instance.getModelDescription();
assertNotNull(result);
......@@ -174,7 +173,7 @@ public class FallArmywormModelJSAdapterTest {
System.out.println("getModelDescription");
String language = "nb";
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String result = instance.getModelDescription(language);
assertNotNull(result);
......@@ -188,7 +187,7 @@ public class FallArmywormModelJSAdapterTest {
public void testGetWarningStatusInterpretation_0args() {
System.out.println("getWarningStatusInterpretation");
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String result = instance.getWarningStatusInterpretation();
assertNotNull(result);
......@@ -202,7 +201,7 @@ public class FallArmywormModelJSAdapterTest {
System.out.println("getWarningStatusInterpretation");
String language = "nb";
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String result = instance.getWarningStatusInterpretation(language);
assertNotNull(result);
......@@ -216,7 +215,7 @@ public class FallArmywormModelJSAdapterTest {
public void testGetModelUsage_0args() {
System.out.println("getModelUsage");
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String result = instance.getModelUsage();
assertNotNull(result);
......@@ -231,7 +230,7 @@ public class FallArmywormModelJSAdapterTest {
System.out.println("getModelUsage");
String language = "nb";
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String result = instance.getModelUsage(language);
assertNotNull(result);
......@@ -244,7 +243,7 @@ public class FallArmywormModelJSAdapterTest {
public void testGetSampleConfig() {
System.out.println("getSampleConfig");
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
String result = instance.getSampleConfig();
assertNotNull(result);
......@@ -261,7 +260,7 @@ public class FallArmywormModelJSAdapterTest {
ModelConfiguration config = fr.getModelConfigurationWithWeatherData("/romeweather.json", "FAWMODEL01");
config.setConfigParameter("plantingDate", "2019-01-22+01");
config.setConfigParameter("timeZone", "Europe/Rome");
FallArmywormModel instance = new FallArmywormModel();
FallArmywormModelGraalVMAdapter instance = new FallArmywormModelGraalVMAdapter();
instance.setConfiguration(config);
}
......
......@@ -35,9 +35,9 @@ import static org.junit.Assert.*;
*
* @author treinar
*/
public class FallArmywormModelJV8AdapterTest {
public class FallArmywormModelJ2V8AdapterTest {
public FallArmywormModelJV8AdapterTest() {
public FallArmywormModelJ2V8AdapterTest() {
}
@BeforeClass
......
......@@ -18,7 +18,6 @@
*/
package no.nibio.vips.model.fallarmywormmodel;
import no.nibio.vips.model.fallarmywormmodel.FallArmywormModel;
import java.util.List;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.Result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment