Skip to content
Snippets Groups Projects
Commit 8c995086 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
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.bioforsk.vips.model</groupId>
<artifactId>DOWNCASTModel</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
This diff is collapsed.
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of DOWNCASTModel.
* DOWNCASTModel 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.
*
* DOWNCASTModel 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 DOWNCASTModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.bioforsk.vips.model.downcastmodel;
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 SPORULATION_VALUE = "SPORULATION_VALUE";
public final static String INFECTION_DIRECTLY_AFTER_SPORULATION = "IDAS";
public final static String INFECTION_TIME_AFTER_SPORULATION = "ITAS";
}
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of DOWNCASTModel.
* DOWNCASTModel 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.
*
* DOWNCASTModel 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 DOWNCASTModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.bioforsk.vips.model.downcastmodel;
import java.util.HashMap;
import java.util.Map;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class SporulationTable {
private final Map<Integer,Integer[]> sporulationTable;
Integer[] a22 = {null,null,null,0,1,1,1,1,2,2,2,2,3,3,3,3,3,3,2,2,2,2,2,2,1,1,1,0};
Integer[] a23 = {null,null,null,0,0,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,0,0};
Integer[] a24 = {null,null,null,0,0,0,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,0,0,0};
Integer[] a01 = {null,null,null,0,0,0,0,0,0,1,1,1,2,2,2,2,2,2,2,2,1,1,1,0,0,0,0,0};
Integer[] a02 = {null,null,null,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0};
Integer[] a03 = {null,null,null,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0};
Integer[] a04 = {null,null,null,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
public SporulationTable()
{
sporulationTable = new HashMap();
sporulationTable.put(22,a22);
sporulationTable.put(23,a23);
sporulationTable.put(0,a24);
sporulationTable.put(1,a01);
sporulationTable.put(2,a02);
sporulationTable.put(3,a03);
sporulationTable.put(4,a04);
}
public Integer getSporulationValue(Integer hourOfDay, Double averageTemperature)
{
try
{
return this.sporulationTable.get(hourOfDay)[new Double(Math.floor(averageTemperature)).intValue()];
}
catch(NullPointerException ex)
{
return 0;
}
}
}
# 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=DOWNCAST model
description=TODO
statusInterpretation=TODO
usage=TODO
name=L\u00f8kbladskimmelmodell
description=TODO
statusInterpretation=TODO
usage=TODO
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of DOWNCASTModel.
* DOWNCASTModel 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.
*
* DOWNCASTModel 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 DOWNCASTModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.bioforsk.vips.model.downcastmodel;
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 DOWNCASTModelTest {
public DOWNCASTModelTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getResult method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testGetResult() throws Exception {
System.out.println("getResult");
DOWNCASTModel instance = new DOWNCASTModel();
ModelConfiguration config = getConfiguration("/lier_2015.json");
instance.setConfiguration(config);
List<Result> result = instance.getResult();
assertNotNull(result);
/*
for(Result r:result)
{
System.out.println(r.toString());
}*/
}
/**
* Test of getModelId method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testGetModelId() {
System.out.println("getModelId");
DOWNCASTModel instance = new DOWNCASTModel();
ModelId result = instance.getModelId();
assertNotNull(result);
}
/**
* Test of getModelName method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testGetModelName_0args() {
System.out.println("getModelName");
DOWNCASTModel instance = new DOWNCASTModel();
String result = instance.getModelName();
assertNotNull(result);
}
/**
* Test of getLicense method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testGetLicense() {
System.out.println("getLicense");
DOWNCASTModel instance = new DOWNCASTModel();
String result = instance.getLicense();
assertNotNull(result);
}
/**
* Test of getCopyright method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testGetCopyright() {
System.out.println("getCopyright");
DOWNCASTModel instance = new DOWNCASTModel();
String result = instance.getCopyright();
assertNotNull(result);
}
/**
* Test of getModelDescription method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testGetModelDescription_0args() {
System.out.println("getModelDescription");
DOWNCASTModel instance = new DOWNCASTModel();
String result = instance.getModelDescription();
assertNotNull(result);
}
/**
* Test of getWarningStatusInterpretation method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testGetWarningStatusInterpretation_0args() {
System.out.println("getWarningStatusInterpretation");
DOWNCASTModel instance = new DOWNCASTModel();
String result = instance.getWarningStatusInterpretation();
assertNotNull(result);
}
/**
* Test of getModelUsage method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testGetModelUsage_0args() {
System.out.println("getModelUsage");
DOWNCASTModel instance = new DOWNCASTModel();
String result = instance.getModelUsage();
assertNotNull(result);
}
/**
* Test of getSampleConfig method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testGetSampleConfig() {
System.out.println("getSampleConfig");
DOWNCASTModel instance = new DOWNCASTModel();
String result = instance.getSampleConfig();
assertNotNull(result);
}
/**
* Test of setConfiguration method, of class DOWNCASTModel.
*/
@org.junit.Test
public void testSetConfiguration() throws Exception {
System.out.println("setConfiguration");
ModelConfiguration config = getConfiguration("/lier_2015.json");
DOWNCASTModel instance = new DOWNCASTModel();
instance.setConfiguration(config);
}
private ModelConfiguration getConfiguration(String fileName)
{
try {
ModelConfiguration config = new ModelConfiguration();
config.setModelId("BREMIALACT");
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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment