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

First commit

parents
Branches
Tags
No related merge requests found
Showing
with 966 additions and 0 deletions
<?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>bioforsk_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.bioforsk.vips</groupId>
<artifactId>DeliaRadicumModel</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>no.bioforsk.vips.common</groupId>
<artifactId>VIPSCommon</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</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) 2015 NIBIO <http://www.nibio.no/>.
*
* This file is part of DeliaRadicumModel.
* DeliaRadicumModel 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.
*
* DeliaRadicumModel 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 DeliaRadicumModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.deliaradicummodel;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
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.bioforsk.vips.entity.ModelConfiguration;
import no.bioforsk.vips.entity.Result;
import no.bioforsk.vips.entity.ResultImpl;
import no.bioforsk.vips.entity.WeatherObservation;
import no.bioforsk.vips.i18n.I18nImpl;
import no.bioforsk.vips.model.ConfigValidationException;
import no.bioforsk.vips.model.Model;
import no.bioforsk.vips.model.ModelExcecutionException;
import no.bioforsk.vips.model.ModelId;
import no.bioforsk.vips.util.CommonNamespaces;
import no.bioforsk.vips.util.InvalidAggregationTypeException;
import no.bioforsk.vips.util.WeatherElements;
import no.bioforsk.vips.util.WeatherObservationListException;
import no.bioforsk.vips.util.WeatherUtil;
/**
* Model controller for aggregated temperature model for invasion of
* Delia radicum (NO: Liten kålflue) in fields
*
* <pre>
* Input parameters:
* Daily temperature mean
* Daily mean soil temperature, preferably at 10cm depth
* </pre>
*
* &copy; 2008-2015 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>: Programming
* @author Tor J. Johansen <tor.johansen@nibio.no>: Model research
*/
public class DeliaRadicumModel extends I18nImpl implements Model{
public final static ModelId MODEL_ID = new ModelId("DELIARADIC");
private final Integer soilTempSumLowerThreshold = 140;
private final Integer soilTempSumUpperThreshold = 160;
private final Integer airTempSumLowerThreshold = 185;
private final Integer airTempSumUpperThreshold = 210;
private final Double dayDegreeBaseTemp = 4.0; // Same for air and soil temp
private TimeZone timeZone;
private List<WeatherObservation> TM; // Air temperature
private List<WeatherObservation> TJM10; // Soil temperature at 10cm
private DeliaRadicumModelDataMatrix dataMatrix;
public DeliaRadicumModel()
{
// Setting the file name of the resource bundle
super("no.nibio.vips.model.deliaradicummodel.texts");
}
@Override
public List<Result> getResult() throws ModelExcecutionException {
this.calculateTemperatureSum(DeliaRadicumModelDataMatrix.TMD, DeliaRadicumModelDataMatrix.TMDD);
if(this.dataMatrix.getFirstDateWithParameterValue(DeliaRadicumModelDataMatrix.TJM10D) != null)
{
this.calculateTemperatureSum(DeliaRadicumModelDataMatrix.TJM10D, DeliaRadicumModelDataMatrix.TJM10DD);
}
List<Result> results = new ArrayList<>();
Date currentDate = this.dataMatrix.getFirstDateWithValues();
Date lastDate = this.dataMatrix.getLastDateWithValues();
Calendar cal = Calendar.getInstance(this.timeZone);
DecimalFormat dFormat = new DecimalFormat("###.##");
while(currentDate.compareTo(lastDate) < 0)
{
Result result = new ResultImpl();
result.setResultValidTime(currentDate);
Double airTempSum = this.dataMatrix.getParamDoubleValueForDate(currentDate, DeliaRadicumModelDataMatrix.TMDD);
result.setValue(
this.getModelId().toString(),
DeliaRadicumModelDataMatrix.TMDD,
dFormat.format(airTempSum)
);
Double soilTempSum = null;
if(this.dataMatrix.getFirstDateWithParameterValue(DeliaRadicumModelDataMatrix.TJM10D) != null)
{
soilTempSum = this.dataMatrix.getParamDoubleValueForDate(currentDate, DeliaRadicumModelDataMatrix.TJM10DD);
result.setValue(
this.getModelId().toString(),
DeliaRadicumModelDataMatrix.TJM10DD,
dFormat.format(soilTempSum)
);
}
// Registering weather data
result.setValue(
CommonNamespaces.NS_WEATHER,
"TMD",
dFormat.format(((WeatherObservation)this.dataMatrix.getParamValueForDate(currentDate, DeliaRadicumModelDataMatrix.TMD)).getValue())
);
WeatherObservation TJM10Obs = (WeatherObservation)this.dataMatrix.getParamValueForDate(currentDate, DeliaRadicumModelDataMatrix.TJM10D);
result.setValue(
CommonNamespaces.NS_WEATHER,
"TJM10D",
TJM10Obs != null ? dFormat.format(TJM10Obs.getValue()) : null
);
// Determining warning status
Integer warningStatus = Result.WARNING_STATUS_NO_RISK;
if( ( soilTempSum != null && soilTempSum >= this.soilTempSumLowerThreshold)
|| airTempSum >= this.airTempSumLowerThreshold
)
{
warningStatus = Result.WARNING_STATUS_MINOR_RISK;
}
if( ( soilTempSum != null && soilTempSum >= this.soilTempSumUpperThreshold)
|| airTempSum >= this.airTempSumUpperThreshold
)
{
warningStatus = Result.WARNING_STATUS_HIGH_RISK;
}
result.setWarningStatus(warningStatus);
results.add(result);
// Moving one day forward
cal.setTime(currentDate);
cal.add(Calendar.DATE, 1);
currentDate = cal.getTime();
}
return results;
}
@Override
public ModelId getModelId() {
return DeliaRadicumModel.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) 2015 NIBIO <http://www.nibio.no/>. \n" +
"\n" +
"This file is part of DeliaRadicumModel. \n" +
"DeliaRadicumModel 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" +
"DeliaRadicumModel 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 DeliaRadicumModel. If not, see <http://www.nibio.no/licenses/>. \n";
}
@Override
public String getCopyright() {
return "(c) 2015 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) {
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";
}
/**
*
* @param config
* @throws ConfigValidationException
*/
@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 DeliaRadicumModelDataMatrix();
ObjectMapper mapper = new ObjectMapper();
// Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("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(), DeliaRadicumModelDataMatrix.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(), DeliaRadicumModelDataMatrix.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(DeliaRadicumModelDataMatrix.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(), DeliaRadicumModelDataMatrix.TMD, obs);
}
} catch (WeatherObservationListException | InvalidAggregationTypeException ex) {
throw new ConfigValidationException(ex.getMessage());
}
}
// Soil temperature
if(dataMatrix.getFirstDateWithParameterValue(DeliaRadicumModelDataMatrix.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(), DeliaRadicumModelDataMatrix.TJM10D, obs);
}
}
} catch (WeatherObservationListException | InvalidAggregationTypeException ex) {
throw new ConfigValidationException(ex.getMessage());
}
}
//System.out.println("DataMatrix");
//System.out.println(this.dataMatrix.toString());
}
/**
* Operates on the datamatrix
* @param inputParameterName the parameter to sum
* @param outputParameterName the result
*/
private void calculateTemperatureSum(String inputParameterName, String outputParameterName) {
Date today = this.dataMatrix.getFirstDateWithParameterValue(inputParameterName);
Date lastDate = this.dataMatrix.getLastDateWithValues();
Calendar cal = Calendar.getInstance(this.timeZone);
Double sum = 0.0;
while(today.compareTo(lastDate) < 0)
{
WeatherObservation todayTemp = (WeatherObservation)this.dataMatrix.getParamValueForDate(today, inputParameterName);
sum += Math.max(0.0, todayTemp.getValue() - this.dayDegreeBaseTemp);
this.dataMatrix.setParamDoubleValueForDate(today, outputParameterName, sum);
cal.setTime(today);
cal.add(Calendar.DATE, 1);
today = cal.getTime();
}
}
}
/*
* Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
*
* This file is part of DeliaRadicumModel.
* DeliaRadicumModel 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.
*
* DeliaRadicumModel 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 DeliaRadicumModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.deliaradicummodel;
import no.bioforsk.vips.util.DateMap;
/**
* @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class DeliaRadicumModelDataMatrix extends DateMap{
// Aggregated values
public final static String TMDD = "TMDD";
public final static String TJM10DD = "TJM10DD";
// Weather data stored for convenience (putting into result object)
public final static String TMD = "TMD";
public final static String TJM10D = "TJM10D";
public DeliaRadicumModelDataMatrix()
{
super();
}
}
# Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
#
# This file is part of DeliaRadicumModel.
# DeliaRadicumModel 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.
#
# DeliaRadicumModel 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 DeliaRadicumModel. If not, see <http://www.nibio.no/licenses/>.
#
name=Delia radicum model
description=TODO: Add description
statusInterpretation=TODO: Add warning status interpretation
usage=TODO: Add usage
# Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
#
# This file is part of DeliaRadicumModel.
# DeliaRadicumModel 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.
#
# DeliaRadicumModel 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 DeliaRadicumModel. If not, see <http://www.nibio.no/licenses/>.
#
name=Delia radicum-modell
description=TODO: Add description
statusInterpretation=TODO: Add warning status interpretation
usage=TODO: Add usage
/*
* Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
*
* This file is part of DeliaRadicumModel.
* DeliaRadicumModel 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.
*
* DeliaRadicumModel 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 DeliaRadicumModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.deliaradicummodel;
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.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import static junit.framework.Assert.fail;
import no.bioforsk.vips.entity.ModelConfiguration;
import no.bioforsk.vips.entity.Result;
import no.bioforsk.vips.entity.WeatherObservation;
import no.bioforsk.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 DeliaRadicumModelTest {
public DeliaRadicumModelTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getResult method, of class DeliaRadicumModel.
*/
@Test
public void testAcceptance() throws Exception {
System.out.println("testAcceptance");
DeliaRadicumModel instance = new DeliaRadicumModel();
ModelConfiguration config = this.getConfiguration("/weatherdata_both.json");
instance.setConfiguration(config);
List<Result> results = instance.getResult();
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Oslo"));
cal.set(2014, Calendar.MAY, 15, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
Date lastGreen = cal.getTime();
cal.set(2014, Calendar.MAY,18,0,0,0);
Date lastYellow = cal.getTime();
for(Result result:results)
{
//System.out.println(result.getResultValidTime() + ": " + result.getWarningStatus());
if(result.getResultValidTime().compareTo(lastGreen) <= 0)
{
assertEquals(Result.WARNING_STATUS_NO_RISK, result.getWarningStatus());
}
else if(result.getResultValidTime().compareTo(lastYellow) <= 0)
{
assertEquals(Result.WARNING_STATUS_MINOR_RISK, result.getWarningStatus());
}
else
{
assertEquals(Result.WARNING_STATUS_HIGH_RISK, result.getWarningStatus());
}
}
// Testing withour TJM10
config = this.getConfiguration("/weatherdata_air.json");
instance.setConfiguration(config);
results = instance.getResult();
cal.set(2014, Calendar.MAY, 18, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
lastGreen = cal.getTime();
cal.set(2014, Calendar.MAY,20,0,0,0);
lastYellow = cal.getTime();
for(Result result:results)
{
//System.out.println(result.getResultValidTime() + ": " + result.getWarningStatus());
if(result.getResultValidTime().compareTo(lastGreen) <= 0)
{
assertEquals(Result.WARNING_STATUS_NO_RISK, result.getWarningStatus());
}
else if(result.getResultValidTime().compareTo(lastYellow) <= 0)
{
assertEquals(Result.WARNING_STATUS_MINOR_RISK, result.getWarningStatus());
}
else
{
assertEquals(Result.WARNING_STATUS_HIGH_RISK, result.getWarningStatus());
}
}
}
/**
* Test of getModelId method, of class DeliaRadicumModel.
*/
@Test
public void testGetModelId() {
System.out.println("getModelId");
DeliaRadicumModel instance = new DeliaRadicumModel();
ModelId expResult = new ModelId("DELIARADIC");
ModelId result = instance.getModelId();
assertEquals(expResult.toString(), result.toString());
}
/**
* Test of getModelName method, of class DeliaRadicumModel.
*/
@Test
public void testGetModelName_0args() {
System.out.println("getModelName");
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getModelName();
}
/**
* Test of getModelName method, of class DeliaRadicumModel.
*/
@Test
public void testGetModelName_String() {
System.out.println("getModelName");
String language = "";
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getModelName(language);
}
/**
* Test of getLicense method, of class DeliaRadicumModel.
*/
@Test
public void testGetLicense() {
System.out.println("getLicense");
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getLicense();
}
/**
* Test of getCopyright method, of class DeliaRadicumModel.
*/
@Test
public void testGetCopyright() {
System.out.println("getCopyright");
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getCopyright();
}
/**
* Test of getModelDescription method, of class DeliaRadicumModel.
*/
@Test
public void testGetModelDescription_0args() {
System.out.println("getModelDescription");
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getModelDescription();
}
/**
* Test of getModelDescription method, of class DeliaRadicumModel.
*/
@Test
public void testGetModelDescription_String() {
System.out.println("getModelDescription");
String language = "";
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getModelDescription(language);
}
/**
* Test of getWarningStatusInterpretation method, of class DeliaRadicumModel.
*/
@Test
public void testGetWarningStatusInterpretation_0args() {
System.out.println("getWarningStatusInterpretation");
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getWarningStatusInterpretation();
}
/**
* Test of getWarningStatusInterpretation method, of class DeliaRadicumModel.
*/
@Test
public void testGetWarningStatusInterpretation_String() {
System.out.println("getWarningStatusInterpretation");
String language = "";
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getWarningStatusInterpretation(language);
}
/**
* Test of getModelUsage method, of class DeliaRadicumModel.
*/
@Test
public void testGetModelUsage_0args() {
System.out.println("getModelUsage");
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getModelUsage();
}
/**
* Test of getModelUsage method, of class DeliaRadicumModel.
*/
@Test
public void testGetModelUsage_String() {
System.out.println("getModelUsage");
String language = "";
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getModelUsage(language);
}
/**
* Test of getSampleConfig method, of class DeliaRadicumModel.
*/
@Test
public void testGetSampleConfig() {
System.out.println("getSampleConfig");
DeliaRadicumModel instance = new DeliaRadicumModel();
String expResult = "";
String result = instance.getSampleConfig();
}
/**
* Test of setConfiguration method, of class DeliaRadicumModel.
*/
@Test
public void testSetConfiguration() throws Exception {
System.out.println("setConfiguration");
ModelConfiguration config = this.getConfiguration("/weatherdata_both.json");
DeliaRadicumModel instance = new DeliaRadicumModel();
instance.setConfiguration(config);
}
private ModelConfiguration getConfiguration(String fileName)
{
try {
ModelConfiguration config = new ModelConfiguration();
config.setModelId(DeliaRadicumModel.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) {
return null;
}
}
}
This diff is collapsed.
This diff is collapsed.
File added
File added
File added
# Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
#
# This file is part of DeliaRadicumModel.
# DeliaRadicumModel 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.
#
# DeliaRadicumModel 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 DeliaRadicumModel. If not, see <http://www.nibio.no/licenses/>.
#
name=Delia radicum model
description=TODO: Add description
statusInterpretation=TODO: Add warning status interpretation
usage=TODO: Add usage
# Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
#
# This file is part of DeliaRadicumModel.
# DeliaRadicumModel 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.
#
# DeliaRadicumModel 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 DeliaRadicumModel. If not, see <http://www.nibio.no/licenses/>.
#
name=Delia radicum-modell
description=TODO: Add description
statusInterpretation=TODO: Add warning status interpretation
usage=TODO: Add usage
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite failures="0" time="0.752" errors="0" skipped="0" tests="14" name="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="sun.boot.library.path" value="/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64"/>
<property name="java.vm.version" value="24.75-b04"/>
<property name="java.vm.vendor" value="Oracle Corporation"/>
<property name="java.vendor.url" value="http://java.oracle.com/"/>
<property name="path.separator" value=":"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="file.encoding.pkg" value="sun.io"/>
<property name="user.country" value="US"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="sun.os.patch.level" value="unknown"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="/home/treinar/prosjekter/vips/Sourcecode/DeliaRadicumModel"/>
<property name="java.runtime.version" value="1.7.0_75-b13"/>
<property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/>
<property name="java.endorsed.dirs" value="/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/endorsed"/>
<property name="os.arch" value="amd64"/>
<property name="java.io.tmpdir" value="/tmp"/>
<property name="line.separator" value="
"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="os.name" value="Linux"/>
<property name="maven.ext.class.path" value="/home/treinar/bin/netbeans-8.0/java/maven-nblib/netbeans-eventspy.jar"/>
<property name="classworlds.conf" value="/home/treinar/bin/netbeans-8.0/java/maven/bin/m2.conf"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.library.path" value="/usr/lib/jvm/default-java/jre/lib/amd64:/usr/lib/jvm/default-java/jre/lib/i386::/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.class.version" value="51.0"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="os.version" value="3.13.0-46-generic"/>
<property name="user.home" value="/home/treinar"/>
<property name="user.timezone" value="Europe/Oslo"/>
<property name="java.awt.printerjob" value="sun.print.PSPrinterJob"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.specification.version" value="1.7"/>
<property name="user.name" value="treinar"/>
<property name="java.class.path" value="/home/treinar/bin/netbeans-8.0/java/maven/boot/plexus-classworlds-2.4.jar"/>
<property name="java.vm.specification.version" value="1.7"/>
<property name="sun.arch.data.model" value="64"/>
<property name="java.home" value="/usr/lib/jvm/java-7-openjdk-amd64/jre"/>
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher -Dmaven.ext.class.path=/home/treinar/bin/netbeans-8.0/java/maven-nblib/netbeans-eventspy.jar test"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="user.language" value="en"/>
<property name="awt.toolkit" value="sun.awt.X11.XToolkit"/>
<property name="java.vm.info" value="mixed mode"/>
<property name="java.version" value="1.7.0_75"/>
<property name="java.ext.dirs" value="/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext:/usr/java/packages/lib/ext"/>
<property name="securerandom.source" value="file:/dev/./urandom"/>
<property name="sun.boot.class.path" value="/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jfr.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/classes"/>
<property name="java.vendor" value="Oracle Corporation"/>
<property name="maven.home" value="/home/treinar/bin/netbeans-8.0/java/maven"/>
<property name="file.separator" value="/"/>
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
<property name="sun.cpu.endian" value="little"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="sun.desktop" value="gnome"/>
<property name="sun.cpu.isalist" value=""/>
</properties>
<testcase time="0.006" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetModelId"/>
<testcase time="0.004" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetModelName_0args"/>
<testcase time="0" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetModelName_String"/>
<testcase time="0" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetLicense"/>
<testcase time="0" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetCopyright"/>
<testcase time="0" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetModelDescription_0args"/>
<testcase time="0" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetModelDescription_String"/>
<testcase time="0.001" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetWarningStatusInterpretation_0args"/>
<testcase time="0" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetWarningStatusInterpretation_String"/>
<testcase time="0.001" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetModelUsage_0args"/>
<testcase time="0" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetModelUsage_String"/>
<testcase time="0" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testGetSampleConfig"/>
<testcase time="0.408" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testSetConfiguration"/>
<testcase time="0.287" classname="no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest" name="testAcceptance"/>
</testsuite>
\ No newline at end of file
-------------------------------------------------------------------------------
Test set: no.nibio.vips.model.deliaradicummodel.DeliaRadicumModelTest
-------------------------------------------------------------------------------
Tests run: 14, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.752 sec
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment