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

Initial commit

parents
Branches
Tags
No related merge requests found
Pipeline #158 failed
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>SeptoriaReferenceHumidityModel</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>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
/*
* Copyright (c) 2019 NIBIO <http://www.nibio.no/>.
*
* This file is part of SeptoriaReferenceHumidityModel.
* SeptoriaReferenceHumidityModel 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.
*
* SeptoriaReferenceHumidityModel 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 SeptoriaReferenceHumidityModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.septoriareferencehumiditymodel;
import no.nibio.vips.util.DateMap;
/**
* @copyright 2018 <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 UM = "UM"; // Relative humidity (%)
public final static String BT = "BT"; // Leaf wetness (minutes/hour)
public final static String RR = "RR"; // Rainfall (mm)
public final static String TM = "TM"; // Mean temperature
public final static String WET_HOUR_SUM = "WHS"; // Wet hour sum
}
/*
* Copyright (c) 2019 NIBIO <http://www.nibio.no/>.
*
* This file is part of SeptoriaReferenceHumidityModel.
* SeptoriaReferenceHumidityModel 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.
*
* SeptoriaReferenceHumidityModel 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 SeptoriaReferenceHumidityModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.septoriareferencehumiditymodel;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
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.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.WeatherElements;
import no.nibio.vips.util.WeatherUtil;
import no.nibio.vips.util.XDate;
/**
* @copyright 2019 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class SeptoriaReferenceHumidityModel implements Model {
public final static ModelId MODEL_ID = new ModelId("SEPTREFHUM");
private final Integer MINIMUM_HOURLY_VALUES = 23;
private final Double TEMPERATURE_THRESHOLD = 8.0;
private List<WeatherObservation> observations;
private TimeZone timeZone;
@Override
public List<Result> getResult() throws ModelExcecutionException {
if(this.observations == null)
{
throw new ModelExcecutionException("No weather data. Aborting.");
}
List<Result> retVal = new ArrayList<>();
DataMatrix dMatrix = new DataMatrix();
this.observations.forEach(obs -> {
dMatrix.setParamDoubleValueForDate(obs.getTimeMeasured(), obs.getElementMeasurementTypeId(), obs.getValue());
});
List<Date> sortedMidnightTimestamps = dMatrix.getSortedDateAtMidnightKeys(this.timeZone);
sortedMidnightTimestamps.forEach((Date midnightTimestamp) -> {
Integer numberOfHoursWithDataForDay = 0;
Integer wetHoursForDay = 0;
XDate currentHour = new XDate(midnightTimestamp);
Date tomorrow = currentHour.getTomorrow();
while(currentHour.before(tomorrow))
{
Double TM = dMatrix.getParamDoubleValueForDate(currentHour, WeatherElements.TEMPERATURE_MEAN);
Double UM = dMatrix.getParamDoubleValueForDate(currentHour, WeatherElements.RELATIVE_HUMIDITY_MEAN);
Double BT = dMatrix.getParamDoubleValueForDate(currentHour, WeatherElements.LEAF_WETNESS_DURATION);
Double RR = dMatrix.getParamDoubleValueForDate(currentHour, WeatherElements.PRECIPITATION);
if(TM != null && (UM != null || BT != null || RR != null))
{
numberOfHoursWithDataForDay++; // We add up the number of hours we actually have weather data for
}
if(TM != null && TM >= this.TEMPERATURE_THRESHOLD)
{
wetHoursForDay += ((BT != null && BT > 30.0) || (RR != null && RR > 0.2) || (UM != null && UM > 88.0)) ? 1 : 0;
}
currentHour.add1Hour();
}
Result r = new ResultImpl();
r.setValidTimeStart(midnightTimestamp);
r.setValidTimeEnd(currentHour.get1HourBefore());
if(numberOfHoursWithDataForDay < this.MINIMUM_HOURLY_VALUES)
{
r.setWarningStatus(Result.WARNING_STATUS_NO_WARNING_MISSING_DATA);
}
else
{
r.setValue(SeptoriaReferenceHumidityModel.MODEL_ID.toString(), DataMatrix.WET_HOUR_SUM, wetHoursForDay.toString());
r.setWarningStatus(Result.WARNING_STATUS_NO_WARNING);
}
retVal.add(r);
});
return retVal;
}
@Override
public ModelId getModelId() {
return SeptoriaReferenceHumidityModel.MODEL_ID;
}
@Override
public String getModelName() {
return this.getModelName(DEFAULT_LANGUAGE);
}
@Override
public String getModelName(String language) {
return "Septoria Reference Humidity Model";
}
@Override
public String getLicense() {
return "Copyright (c) 2019 NIBIO <http://www.nibio.no/>. \n" +
"\n" +
"This file is part of SeptoriaReferenceHumidityModel. \n" +
"SeptoriaReferenceHumidityModel 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" +
"SeptoriaReferenceHumidityModel 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 SeptoriaReferenceHumidityModel. If not, see <http://www.nibio.no/licenses/>. \n";
}
@Override
public String getCopyright() {
return "(C) 2019 NIBIO";
}
@Override
public String getModelDescription() {
return this.getModelDescription(DEFAULT_LANGUAGE);
}
@Override
public String getModelDescription(String language) {
return "TODO";
}
@Override
public String getWarningStatusInterpretation() {
return this.getWarningStatusInterpretation(DEFAULT_LANGUAGE);
}
@Override
public String getWarningStatusInterpretation(String language) {
return "TODO";
}
@Override
public String getModelUsage() {
return this.getModelUsage(DEFAULT_LANGUAGE);
}
@Override
public String getModelUsage(String language) {
return "TODO";
}
@Override
public String getSampleConfig() {
return "TODO";
}
@Override
public void setConfiguration(ModelConfiguration config) throws ConfigValidationException {
ObjectMapper mapper = new ObjectMapper();
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
this.observations = mapper.convertValue(config.getConfigParameter("observations"), new TypeReference<List<WeatherObservation>>(){});
}
}
/*
* Copyright (c) 2019 NIBIO <http://www.nibio.no/>.
*
* This file is part of SeptoriaReferenceHumidityModel.
* SeptoriaReferenceHumidityModel 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.
*
* SeptoriaReferenceHumidityModel 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 SeptoriaReferenceHumidityModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.septoriareferencehumiditymodel;
import java.util.List;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.Result;
import no.nibio.vips.model.ModelId;
import no.nibio.vips.util.test.WeatherDataFileReader;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
*
* @author treinar
*/
public class SeptoriaReferenceHumidityModelTest {
public SeptoriaReferenceHumidityModelTest() {
}
@BeforeAll
public static void setUpClass() {
}
@AfterAll
public static void tearDownClass() {
}
@BeforeEach
public void setUp() {
}
@AfterEach
public void tearDown() {
}
/**
* Test of getResult method, of class SeptoriaReferenceHumidityModel.
*/
@org.junit.jupiter.api.Test
public void testGetResult() throws Exception {
System.out.println("getResult");
ModelConfiguration config = new WeatherDataFileReader().getModelConfigurationWithWeatherData("/ullensvang.json", SeptoriaReferenceHumidityModel.MODEL_ID.toString());
config.setConfigParameter("timeZone", "Europe/Oslo");
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
instance.setConfiguration(config);
List<Result> result = instance.getResult();
//result.forEach(r->System.out.println(r.toString()));
assertNotNull(result);
}
/**
* Test of getModelId method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetModelId() {
System.out.println("getModelId");
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
ModelId result = instance.getModelId();
assertEquals(result, SeptoriaReferenceHumidityModel.MODEL_ID);
}
/**
* Test of getModelName method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetModelName_0args() {
System.out.println("getModelName");
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getModelName();
assertNotNull(result);
}
/**
* Test of getModelName method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetModelName_String() {
System.out.println("getModelName");
String language = "";
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getModelName(language);
assertNotNull(result);
}
/**
* Test of getLicense method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetLicense() {
System.out.println("getLicense");
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getLicense();
assertNotNull(result);
}
/**
* Test of getCopyright method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetCopyright() {
System.out.println("getCopyright");
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getCopyright();
assertNotNull(result);
}
/**
* Test of getModelDescription method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetModelDescription_0args() {
System.out.println("getModelDescription");
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getModelDescription();
assertNotNull(result);
}
/**
* Test of getModelDescription method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetModelDescription_String() {
System.out.println("getModelDescription");
String language = "";
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getModelDescription(language);
assertNotNull(result);
}
/**
* Test of getWarningStatusInterpretation method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetWarningStatusInterpretation_0args() {
System.out.println("getWarningStatusInterpretation");
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getWarningStatusInterpretation();
assertNotNull(result);
}
/**
* Test of getWarningStatusInterpretation method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetWarningStatusInterpretation_String() {
System.out.println("getWarningStatusInterpretation");
String language = "";
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getWarningStatusInterpretation(language);
assertNotNull(result);
}
/**
* Test of getModelUsage method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetModelUsage_0args() {
System.out.println("getModelUsage");
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getModelUsage();
assertNotNull(result);
}
/**
* Test of getModelUsage method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetModelUsage_String() {
System.out.println("getModelUsage");
String language = "";
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getModelUsage(language);
assertNotNull(result);
}
/**
* Test of getSampleConfig method, of class SeptoriaReferenceHumidityModel.
*/
//@org.junit.jupiter.api.Test
public void testGetSampleConfig() {
System.out.println("getSampleConfig");
SeptoriaReferenceHumidityModel instance = new SeptoriaReferenceHumidityModel();
String result = instance.getSampleConfig();
assertNotNull(result);
}
}
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