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

First commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 778 additions and 0 deletions
target/
classes/
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.license>nibio_open_source_license.ftl</netbeans.hint.license>
</properties>
</project-shared-configuration>
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>no.nibio.vips.model</groupId>
<artifactId>MamestraBrassicaeModel</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>no.nibio.vips.common</groupId>
<artifactId>VIPSCommon</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of MamestraBrassicaeModel.
* MamestraBrassicaeModel is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* MamestraBrassicaeModel 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
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with MamestraBrassicaeModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.mamestrabrassicaemodel;
import no.nibio.vips.util.DateMap;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class DataMatrix extends DateMap{
public final static String TMD = "TMD";
public final static String TJM10D = "TJM10D";
}
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of MamestraBrassicaeModel.
* MamestraBrassicaeModel is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* MamestraBrassicaeModel 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
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with MamestraBrassicaeModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.mamestrabrassicaemodel;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.Result;
import no.nibio.vips.entity.ResultImpl;
import no.nibio.vips.entity.WeatherObservation;
import no.nibio.vips.i18n.I18nImpl;
import no.nibio.vips.model.ConfigValidationException;
import no.nibio.vips.model.Model;
import no.nibio.vips.model.ModelExcecutionException;
import no.nibio.vips.model.ModelId;
import no.nibio.vips.util.CommonNamespaces;
import no.nibio.vips.util.InvalidAggregationTypeException;
import no.nibio.vips.util.ModelUtil;
import no.nibio.vips.util.WeatherElements;
import no.nibio.vips.util.WeatherObservationListException;
import no.nibio.vips.util.WeatherUtil;
/**
* Forecasting model for Mamestra brassicae (NO: Kålfly)
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class MamestraBrassicaeModel extends I18nImpl implements Model{
public final static ModelId MODEL_ID = new ModelId("MAMESTRABR");
private final ModelUtil modelUtil;
// Model constants
private final static Integer THRESHOLD_TMDD_PUPAE = 129;
private final static Integer THRESHOLD_TMDD_EGG_DEPOSIT = 56;
private final static Integer THRESHOLD_TMDD_EGG_HATCH = 75;
private final static Integer THRESHOLD_TMDD_LARVAE_1 = 66;
private final static Integer THRESHOLD_TMDD_LARVAE_2 = 49;
private final static Integer THRESHOLD_TMDD_LARVAE_3 = 53;
private final static Integer THRESHOLD_TMDD_LARVAE_4 = 67;
private final static Integer THRESHOLD_TMDD_LARVAE_5 = 62;
private final static Double T0_PUPAE = 7.5; // Day degree base temp phase 1
private final static Double T0_EGG_DEPOSIT = 5.0; // Day degree base temp phase 2
private final static Double T0_EGG_HATCH = 8.6; // Day degree base temp phase 3a
private final static Double T0_L1 = 7.7; // Day degree base temp phase 3b
private final static Double T0_L2 = 6.9; // Day degree base temp phase 4a
private final static Double T0_L3 = 6.3; // Day degree base temp phase 4b
private final static Double T0_L4 = 4.3; // Day degree base temp phase 5a
private final static Double T0_L5 = 6.0; // Day degree base temp phase 5b
// Collections
private List<WeatherObservation> TJM10;
private List<WeatherObservation> TM;
private DataMatrix dataMatrix;
// Other globals
private TimeZone timeZone;
public MamestraBrassicaeModel()
{
super("no.nibio.vips.model.mamestrabrassicaemodel.texts");
this.modelUtil = new ModelUtil();
}
@Override
public List<Result> getResult() throws ModelExcecutionException {
Double accumulatedDayDegrees = 0.0;
Date currentDate = this.dataMatrix.getFirstDateWithParameterValue(DataMatrix.TJM10D);
Date endDate = this.dataMatrix.getLastDateWithParameterValue(DataMatrix.TMD);
DecimalFormat dFormat = new DecimalFormat("###.##");
List<Result> retVal = new ArrayList<>();
Calendar cal = Calendar.getInstance(timeZone);
while(currentDate.before(endDate))
{
Double baseTemp = this.findT0(accumulatedDayDegrees);
Double todayTemp = accumulatedDayDegrees < THRESHOLD_TMDD_PUPAE ?
((WeatherObservation)this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.TJM10D)).getValue()
: ((WeatherObservation)this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.TMD)).getValue();
accumulatedDayDegrees += Math.max(0, todayTemp - baseTemp);
Result result = new ResultImpl();
result.setResultValidTime(currentDate);
result.setWarningStatus(this.getWarningStatus(accumulatedDayDegrees));
this.setAllThresholds(result);
result.setValue(this.getModelId().toString(),"TMDD", dFormat.format(accumulatedDayDegrees));
// Set input data
result.setValue(CommonNamespaces.NS_WEATHER, "TJM10D", dFormat.format(((WeatherObservation)this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.TJM10D)).getValue()));
result.setValue(CommonNamespaces.NS_WEATHER, "TMD", dFormat.format(((WeatherObservation)this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.TMD)).getValue()));
retVal.add(result);
cal.setTime(currentDate);
cal.add(Calendar.DATE, 1);
currentDate = cal.getTime();
}
return retVal;
}
@Override
public ModelId getModelId() {
return MamestraBrassicaeModel.MODEL_ID;
}
@Override
public String getModelName() {
return this.getModelName(Model.DEFAULT_LANGUAGE);
}
@Override
public String getModelName(String language) {
return this.getText("name", language);
}
@Override
public String getLicense() {
return "Copyright (c) 2016 NIBIO <http://www.nibio.no/>. \n" +
"\n" +
"This file is part of LygusRugulipennisModel. \n" +
"MamestraBrassicaeModel is free software: you can redistribute it and/or modify \n" +
"it under the terms of the NIBIO Open Source License as published by \n" +
"NIBIO, either version 1 of the License, or (at your option) any \n" +
"later version. \n" +
"\n" +
"MamestraBrassicaeModel is distributed in the hope that it will be useful, \n" +
"but WITHOUT ANY WARRANTY; without even the implied warranty of \n" +
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n" +
"NIBIO Open Source License for more details. \n" +
"" +
"You should have received a copy of the NIBIO Open Source License \n" +
"along with MamestraBrassicaeModel. If not, see <http://www.nibio.no/licenses/>. \n";
}
@Override
public String getCopyright() {
return "(c) 2016 NIBIO (http://www.nibio.no/). Contact: post@nibio.no";
}
@Override
public String getModelDescription() {
return this.getModelDescription(Model.DEFAULT_LANGUAGE);
}
@Override
public String getModelDescription(String language) {
try
{
return this.modelUtil.getTextWithBase64EncodedImages(this.getText("description", language), this.getClass());
}
catch(IOException ex)
{
return this.getText("description", language);
}
}
@Override
public String getWarningStatusInterpretation() {
return this.getWarningStatusInterpretation(Model.DEFAULT_LANGUAGE);
}
@Override
public String getWarningStatusInterpretation(String language) {
return this.getText("statusInterpretation", language);
}
@Override
public String getModelUsage() {
return this.getModelUsage(Model.DEFAULT_LANGUAGE);
}
@Override
public String getModelUsage(String language) {
return this.getText("usage", language);
}
@Override
public String getSampleConfig() {
return "{\n" +
"\t\"loginInfo\":{\n" +
"\t\t\"username\":\"example\",\n" +
"\t\t\"password\":\"example\"\n" +
"\t},\n" +
"\t\"modelId\":\"" + MODEL_ID.toString() + "\",\n" +
"\t\"configParameters\":{\n" +
"\t\t\"observations\":[\n" +
"\t\t{\n" +
"\t\t\t\t\"timeMeasured\": \"2015-01-01T00:00:00+02:00\",\n" +
"\t\t\t\t\"elementMeasurementTypeId\":\"TM\",\n" +
"\t\t\t\t\"logIntervalId\":2,\n" +
"\t\t\t\t\"value\":1.1\n" +
"\t\t},\n" +
"\t\t{\n" +
"\t\t\t\t\"timeMeasured\": \"2015-01-01T00:00:00+02:00\",\n" +
"\t\t\t\t\"elementMeasurementTypeId\":\"TJM10\",\n" +
"\t\t\t\t\"logIntervalId\":2,\n" +
"\t\t\t\t\"value\":0.9\n" +
"\t\t}\n" +
"\t\t]\n" +
"\t}\n" +
"}\n";
}
@Override
public void setConfiguration(ModelConfiguration config) throws ConfigValidationException {
// Initialize the weather data collections
this.TM = new ArrayList<>();
this.TJM10 = new ArrayList<>();
// Init data matrix
this.dataMatrix = new DataMatrix();
ObjectMapper mapper = new ObjectMapper();
// Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
//System.out.println("TimeZone=" + this.timeZone);
// Importing weather data, creating collections
// Can accept both hourly and daily data
WeatherUtil wUtil = new WeatherUtil();
List<WeatherObservation> observations = mapper.convertValue(config.getConfigParameter("observations"), new TypeReference<List<WeatherObservation>>(){});
for(WeatherObservation o:observations)
{
switch(o.getElementMeasurementTypeId())
{
case WeatherElements.TEMPERATURE_MEAN:
if(o.getLogIntervalId().equals(WeatherObservation.LOG_INTERVAL_ID_1H))
{
this.TM.add(o);
}else {
o.setTimeMeasured(wUtil.pragmaticAdjustmentToMidnight(o.getTimeMeasured(), timeZone));
this.dataMatrix.setParamValueForDate(o.getTimeMeasured(), DataMatrix.TMD, o);
}break;
case WeatherElements.SOIL_TEMPERATURE_10CM_MEAN:
if(o.getLogIntervalId().equals(WeatherObservation.LOG_INTERVAL_ID_1H))
{
this.TJM10.add(o);
}else {
o.setTimeMeasured(wUtil.pragmaticAdjustmentToMidnight(o.getTimeMeasured(), timeZone));
this.dataMatrix.setParamValueForDate(o.getTimeMeasured(), DataMatrix.TJM10D, o);
}break;
default:
// Keep calm and continue importing data
break;
}
}
// If we've received hourly weather data, create and store daily values
// Air temperature
if(dataMatrix.getFirstDateWithParameterValue(DataMatrix.TMD) == null)
{
try {
List<WeatherObservation> dailyTemperatures = new WeatherUtil().getAggregatedDailyValues(
this.TM,
this.timeZone,
15,
WeatherUtil.AGGREGATION_TYPE_AVERAGE);
for(WeatherObservation obs:dailyTemperatures)
{
this.dataMatrix.setParamValueForDate(obs.getTimeMeasured(), DataMatrix.TMD, obs);
}
} catch (WeatherObservationListException | InvalidAggregationTypeException ex) {
throw new ConfigValidationException(ex.getMessage());
}
}
// Soil temperature
if(dataMatrix.getFirstDateWithParameterValue(DataMatrix.TJM10D) == null)
{
try {
List<WeatherObservation> dailyTemperatures = new WeatherUtil().getAggregatedDailyValues(
this.TJM10,
this.timeZone,
15,
WeatherUtil.AGGREGATION_TYPE_AVERAGE);
if(dailyTemperatures != null)
{
for(WeatherObservation obs:dailyTemperatures)
{
this.dataMatrix.setParamValueForDate(obs.getTimeMeasured(), DataMatrix.TJM10D, obs);
}
}
} catch (WeatherObservationListException | InvalidAggregationTypeException ex) {
throw new ConfigValidationException(ex.getMessage());
}
}
if(this.dataMatrix.getFirstDateWithParameterValue(DataMatrix.TJM10D)
.after(this.dataMatrix.getLastDateWithParameterValue(DataMatrix.TMD))
)
{
throw new ConfigValidationException("Error with weather data. First day with soil temp = " +
this.dataMatrix.getFirstDateWithParameterValue(DataMatrix.TJM10D) + ", last day with air temp = " +
this.dataMatrix.getLastDateWithParameterValue(DataMatrix.TMD));
}
}
private Double findT0(Double accumulatedDayDegrees)
{
if(accumulatedDayDegrees < THRESHOLD_TMDD_PUPAE) return T0_PUPAE;
else if(accumulatedDayDegrees < THRESHOLD_TMDD_PUPAE + THRESHOLD_TMDD_EGG_DEPOSIT) return T0_EGG_DEPOSIT;
else if(accumulatedDayDegrees < THRESHOLD_TMDD_PUPAE + THRESHOLD_TMDD_EGG_DEPOSIT
+ THRESHOLD_TMDD_EGG_HATCH) return T0_EGG_HATCH;
else if(accumulatedDayDegrees < THRESHOLD_TMDD_PUPAE + THRESHOLD_TMDD_EGG_DEPOSIT
+ THRESHOLD_TMDD_EGG_HATCH + THRESHOLD_TMDD_LARVAE_1) return T0_L1;
else if(accumulatedDayDegrees < THRESHOLD_TMDD_PUPAE + THRESHOLD_TMDD_EGG_DEPOSIT
+ THRESHOLD_TMDD_EGG_HATCH + THRESHOLD_TMDD_LARVAE_1 + THRESHOLD_TMDD_LARVAE_2) return T0_L2;
else if(accumulatedDayDegrees < THRESHOLD_TMDD_PUPAE + THRESHOLD_TMDD_EGG_DEPOSIT
+ THRESHOLD_TMDD_EGG_HATCH + THRESHOLD_TMDD_LARVAE_1 + THRESHOLD_TMDD_LARVAE_2
+ THRESHOLD_TMDD_LARVAE_3) return T0_L3;
else if(accumulatedDayDegrees < THRESHOLD_TMDD_PUPAE + THRESHOLD_TMDD_EGG_DEPOSIT
+ THRESHOLD_TMDD_EGG_HATCH + THRESHOLD_TMDD_LARVAE_1 + THRESHOLD_TMDD_LARVAE_2
+ THRESHOLD_TMDD_LARVAE_3 + THRESHOLD_TMDD_LARVAE_4) return T0_L4;
else if(accumulatedDayDegrees < THRESHOLD_TMDD_LARVAE_1 + THRESHOLD_TMDD_LARVAE_2
+ THRESHOLD_TMDD_LARVAE_3 + THRESHOLD_TMDD_LARVAE_4 + THRESHOLD_TMDD_LARVAE_5) return T0_L5;
else return T0_L5;
}
private Integer getWarningStatus(Double accumulatedDayDegrees) {
if(accumulatedDayDegrees < THRESHOLD_TMDD_PUPAE)
{
return Result.WARNING_STATUS_NO_RISK;
}
else if(accumulatedDayDegrees <
THRESHOLD_TMDD_PUPAE
+ THRESHOLD_TMDD_EGG_DEPOSIT
)
{
return Result.WARNING_STATUS_MINOR_RISK;
}
else if(accumulatedDayDegrees <
THRESHOLD_TMDD_PUPAE +
THRESHOLD_TMDD_EGG_DEPOSIT +
THRESHOLD_TMDD_EGG_HATCH +
THRESHOLD_TMDD_LARVAE_1 +
THRESHOLD_TMDD_LARVAE_2 +
THRESHOLD_TMDD_LARVAE_3 +
THRESHOLD_TMDD_LARVAE_4 +
THRESHOLD_TMDD_LARVAE_5
)
{
return Result.WARNING_STATUS_HIGH_RISK;
}
else
{
return Result.WARNING_STATUS_NO_WARNING;
}
}
private void setAllThresholds(Result result) {
result.setValue(this.getModelId().toString(), "SWARMING_START", String.valueOf(THRESHOLD_TMDD_PUPAE));
result.setValue(this.getModelId().toString(), "EGG_HATCH_START", String.valueOf(THRESHOLD_TMDD_PUPAE + THRESHOLD_TMDD_EGG_DEPOSIT));
result.setValue(this.getModelId().toString(), "TREATMENT_OPTIMUM", String.valueOf(
THRESHOLD_TMDD_PUPAE
+ THRESHOLD_TMDD_EGG_DEPOSIT
+ THRESHOLD_TMDD_EGG_HATCH
+ THRESHOLD_TMDD_LARVAE_1
)
);
result.setValue(this.getModelId().toString(), "TREATMENT_LATE", String.valueOf(
THRESHOLD_TMDD_PUPAE
+ THRESHOLD_TMDD_EGG_DEPOSIT
+ THRESHOLD_TMDD_EGG_HATCH
+ THRESHOLD_TMDD_LARVAE_1
+ THRESHOLD_TMDD_LARVAE_2
+ THRESHOLD_TMDD_LARVAE_3
)
);
}
}
# Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
#
# This file is part of MamestraBrassicaeModel.
# MamestraBrassicaeModel is free software: you can redistribute it and/or modify
# it under the terms of the NIBIO Open Source License as published by
# NIBIO, either version 1 of the License, or (at your option) any
# later version.
#
# MamestraBrassicaeModel 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
# NIBIO Open Source License for more details.
#
# You should have received a copy of the NIBIO Open Source License
# along with MamestraBrassicaeModel. If not, see <http://www.nibio.no/licenses/>.
#
name=Mamestra brassicae model
description=TODO
statusInterpretation=TODO
usage=TODO
# Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
#
# This file is part of MamestraBrassicaeModel.
# MamestraBrassicaeModel is free software: you can redistribute it and/or modify
# it under the terms of the NIBIO Open Source License as published by
# NIBIO, either version 1 of the License, or (at your option) any
# later version.
#
# MamestraBrassicaeModel 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
# NIBIO Open Source License for more details.
#
# You should have received a copy of the NIBIO Open Source License
# along with MamestraBrassicaeModel. If not, see <http://www.nibio.no/licenses/>.
#
name=K\u00e5lflymodell
description=TODO
statusInterpretation=TODO
usage=TODO
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of MamestraBrassicaeModel.
* MamestraBrassicaeModel is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* MamestraBrassicaeModel 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
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with MamestraBrassicaeModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.mamestrabrassicaemodel;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MappingJsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static junit.framework.Assert.fail;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.Result;
import no.nibio.vips.entity.WeatherObservation;
import no.nibio.vips.model.ModelId;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author treinar
*/
public class MamestraBrassicaeModelTest {
public MamestraBrassicaeModelTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getResult method, of class MamestraBrassicaeModel.
*/
@Test
public void testGetResult() throws Exception {
System.out.println("getResult");
ModelConfiguration config = this.getConfiguration("/aas_2015.json");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
instance.setConfiguration(config);
List<Result> expResult = null;
List<Result> result = instance.getResult();
assertNotNull(result);
for(Result res:result)
{
System.out.println(res.toString());
}
}
/**
* Test of getModelId method, of class MamestraBrassicaeModel.
*/
@Test
public void testGetModelId() {
System.out.println("getModelId");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
ModelId expResult = new ModelId("MAMESTRABR");
ModelId result = instance.getModelId();
assertEquals(expResult.toString(), result.toString());
}
/**
* Test of getModelName method, of class MamestraBrassicaeModel.
*/
@Test
public void testGetModelName_0args() {
System.out.println("getModelName");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
String expResult = "";
String result = instance.getModelName();
assertNotNull(result);
}
/**
* Test of getLicense method, of class MamestraBrassicaeModel.
*/
@Test
public void testGetLicense() {
System.out.println("getLicense");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
String expResult = "";
String result = instance.getLicense();
assertNotNull(result);
}
/**
* Test of getCopyright method, of class MamestraBrassicaeModel.
*/
@Test
public void testGetCopyright() {
System.out.println("getCopyright");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
String expResult = "";
String result = instance.getCopyright();
assertNotNull(result);
}
/**
* Test of getModelDescription method, of class MamestraBrassicaeModel.
*/
@Test
public void testGetModelDescription_0args() {
System.out.println("getModelDescription");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
String expResult = "";
String result = instance.getModelDescription();
assertNotNull(result);
}
/**
* Test of getWarningStatusInterpretation method, of class MamestraBrassicaeModel.
*/
@Test
public void testGetWarningStatusInterpretation_0args() {
System.out.println("getWarningStatusInterpretation");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
String expResult = "";
String result = instance.getWarningStatusInterpretation();
assertNotNull(result);
}
/**
* Test of getModelUsage method, of class MamestraBrassicaeModel.
*/
@Test
public void testGetModelUsage_0args() {
System.out.println("getModelUsage");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
String expResult = "";
String result = instance.getModelUsage();
assertNotNull(result);
}
/**
* Test of getSampleConfig method, of class MamestraBrassicaeModel.
*/
@Test
public void testGetSampleConfig() {
System.out.println("getSampleConfig");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
String expResult = "";
String result = instance.getSampleConfig();
assertNotNull(result);
}
/**
* Test of setConfiguration method, of class MamestraBrassicaeModel.
*/
@Test
public void testSetConfiguration() throws Exception {
System.out.println("setConfiguration");
ModelConfiguration config = this.getConfiguration("/weatherdata_both.json");
MamestraBrassicaeModel instance = new MamestraBrassicaeModel();
instance.setConfiguration(config);
}
private ModelConfiguration getConfiguration(String fileName)
{
try {
ModelConfiguration config = new ModelConfiguration();
config.setModelId(MamestraBrassicaeModel.MODEL_ID.toString());
config.setConfigParameter("timeZone", "Europe/Oslo");
BufferedInputStream inputStream = new BufferedInputStream(this.getClass().getResourceAsStream(fileName));
JsonFactory f = new MappingJsonFactory();
JsonParser jp = f.createParser(inputStream);
JsonNode all = jp.readValueAsTree();
List<WeatherObservation> observations = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
Date firstDate = null;
Date lastDate = null;
if(all.isArray())
{
for(JsonNode node : all){
Date timeMeasured = (Date)mapper.convertValue(node.get("timeMeasured").asText(), new TypeReference<Date>(){});
if(firstDate == null || firstDate.compareTo(timeMeasured) > 0)
{
firstDate = timeMeasured;
}
if(lastDate == null || lastDate.compareTo(timeMeasured) < 0)
{
lastDate = timeMeasured;
}
//System.out.println(node.toString());
WeatherObservation observation = new WeatherObservation();
observation.setTimeMeasured(timeMeasured);
observation.setLogIntervalId(node.get("logIntervalId").asInt());
observation.setElementMeasurementTypeId(node.get("elementMeasurementTypeId").asText());
observation.setValue(node.get("value").asDouble());
observations.add(observation);
}
}
else
{
fail("Data input from file is not a JSON array");
}
config.setConfigParameter("observations", observations);
return config;
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment