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

First commit

parents
Branches
Tags
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>BremiaLactucaeModel</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 BremiaLactucaeModel.
* BremiaLactucaeModel 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.
*
* BremiaLactucaeModel 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 BremiaLactucaeModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.bremialactucaemodel;
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 Q0 = "Q0";
public final static String TXD = "TXD";
public final static String UM = "UM";
public final static String BTG = "BTg";
/**
* Enough relative humidity yesterday night? (Rule #1) 1 or 0
*/
public final static String ERHYN = "ERHYN";
/**
* Sporulation yesterday night? (Rule #2) 1 or 0
*/
public final static String SYN = "SYN";
/**
* Enough leaf wetness after sunrise yesterday and before sunrise today? (Rule #3) 1 or 0
*/
public final static String ELWASYBST = "ELWASYBST";
/**
* Max temp between sunrise yesterday and sunrise today (Rule #4)
*/
public final static String TXASYBST = "TXASYBST";
/**
* Max temp hourly
*/
public final static String TX = "TX";
/**
* Enough relative humidity last night? (Rule #5) 1 or 0
*/
public final static String ERHLN = "ERHLN";
/**
* Sporulation last night? (Rule #6) 1 or 0
*/
public final static String SLN = "SLN";
/**
* Enough leaf wetness after sunrise today (Rule #7)
*/
public final static String ELWAST = "ELWAST";
/**
* Max temp today (Rule #8)
*/
public final static String TXT = "TXT";
}
# 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=Bremia lactucae model
description=TODO
statusInterpretation=TODO
usage=TODO
name=Salatbladskimmelmodell
description=TODO
statusInterpretation=TODO
usage=TODO
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of BremiaLactucaeModel.
* BremiaLactucaeModel 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.
*
* BremiaLactucaeModel 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 BremiaLactucaeModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.bremialactucaemodel;
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 com.ibm.icu.util.Calendar;
import com.ibm.icu.util.TimeZone;
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 BremiaLactucaeModelTest {
public BremiaLactucaeModelTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getResult method, of class BremiaLactucaeModel.
*/
@Test
public void testGetResult() throws Exception {
System.out.println("getResult");
ModelConfiguration config = this.getConfiguration("/lier_2015.json");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
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 BremiaLactucaeModel.
*/
@Test
public void testGetModelId() {
System.out.println("getModelId");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
ModelId expResult = new ModelId("BREMIALACT");
ModelId result = instance.getModelId();
assertEquals(expResult.toString(), result.toString());
}
/**
* Test of getModelName method, of class BremiaLactucaeModel.
*/
@Test
public void testGetModelName_0args() {
System.out.println("getModelName");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
String result = instance.getModelName();
assertNotNull(result);
}
/**
* Test of getLicense method, of class BremiaLactucaeModel.
*/
@Test
public void testGetLicense() {
System.out.println("getLicense");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
String result = instance.getLicense();
assertNotNull(result);
}
/**
* Test of getCopyright method, of class BremiaLactucaeModel.
*/
@Test
public void testGetCopyright() {
System.out.println("getCopyright");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
String result = instance.getCopyright();
assertNotNull(result);
}
/**
* Test of getModelDescription method, of class BremiaLactucaeModel.
*/
@Test
public void testGetModelDescription_0args() {
System.out.println("getModelDescription");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
String result = instance.getModelDescription();
assertNotNull(result);
}
/**
* Test of getWarningStatusInterpretation method, of class BremiaLactucaeModel.
*/
@Test
public void testGetWarningStatusInterpretation_0args() {
System.out.println("getWarningStatusInterpretation");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
String result = instance.getWarningStatusInterpretation();
assertNotNull(result);
}
/**
* Test of getModelUsage method, of class BremiaLactucaeModel.
*/
@Test
public void testGetModelUsage_0args() {
System.out.println("getModelUsage");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
String result = instance.getModelUsage();
assertNotNull(result);
}
/**
* Test of getSampleConfig method, of class BremiaLactucaeModel.
*/
@Test
public void testGetSampleConfig() {
System.out.println("getSampleConfig");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
String result = instance.getSampleConfig();
assertNotNull(result);
}
/**
* Test of setConfiguration method, of class BremiaLactucaeModel.
*/
@Test
public void testSetConfiguration() throws Exception {
System.out.println("setConfiguration");
ModelConfiguration config = this.getConfiguration("/lier_2015.json");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
instance.setConfiguration(config);
}
@Test
public void testGetSunset() throws Exception {
System.out.println("getSunset");
ModelConfiguration config = this.getConfiguration("/lier_2015.json");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
instance.setConfiguration(config);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Oslo"));
cal.set(2015, Calendar.JUNE, 22, 0, 0, 0);
cal.set(Calendar.MILLISECOND,0);
Date testDate = cal.getTime();
cal.set(Calendar.HOUR_OF_DAY, 22);
Date expResult = cal.getTime();
Date result = instance.getSunset(testDate);
assertEquals(expResult, result);
}
@Test
public void testGetSunrise() throws Exception {
System.out.println("getSunset");
ModelConfiguration config = this.getConfiguration("/lier_2015.json");
BremiaLactucaeModel instance = new BremiaLactucaeModel();
instance.setConfiguration(config);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Oslo"));
cal.set(2015, Calendar.JUNE, 23, 0, 0, 0);
cal.set(Calendar.MILLISECOND,0);
Date testDate = cal.getTime();
cal.set(Calendar.HOUR_OF_DAY, 5);
Date expResult = cal.getTime();
Date result = instance.getSunrise(testDate);
assertEquals(expResult, result);
}
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