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

First commit

parents
Branches
Tags
No related merge requests found
Showing
with 1113 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>DeliaRadicumFloralisObservationModel</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 DeliaRadicumFloralisObservationModel.
* DeliaRadicumFloralisObservationModel 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.
*
* DeliaRadicumFloralisObservationModel 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 DeliaRadicumFloralisObservationModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.deliaradicumfloralisobservationmodel;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class DeliaRadicumFloralisObservation {
private Integer
counting01,
counting02,
counting03,
counting04,
counting05,
counting06,
counting07,
counting08,
counting09,
counting10;
public DeliaRadicumFloralisObservation(
Integer counting01,
Integer counting02,
Integer counting03,
Integer counting04,
Integer counting05,
Integer counting06,
Integer counting07,
Integer counting08,
Integer counting09,
Integer counting10
)
{
this.counting01 = counting01;
this.counting02 = counting02;
this.counting03 = counting03;
this.counting04 = counting04;
this.counting05 = counting05;
this.counting06 = counting06;
this.counting07 = counting07;
this.counting08 = counting08;
this.counting09 = counting09;
this.counting10 = counting10;
}
public Double getAverage()
{
return
(this.counting01
+ this.counting02
+ this.counting03
+ this.counting04
+ this.counting05
+ this.counting06
+ this.counting07
+ this.counting08
+ this.counting09
+ this.counting10)
/10.0;
}
/**
* @return the counting01
*/
public Integer getCounting01() {
return counting01;
}
/**
* @param counting01 the counting01 to set
*/
public void setCounting01(Integer counting01) {
this.counting01 = counting01;
}
/**
* @return the counting02
*/
public Integer getCounting02() {
return counting02;
}
/**
* @param counting02 the counting02 to set
*/
public void setCounting02(Integer counting02) {
this.counting02 = counting02;
}
/**
* @return the counting03
*/
public Integer getCounting03() {
return counting03;
}
/**
* @param counting03 the counting03 to set
*/
public void setCounting03(Integer counting03) {
this.counting03 = counting03;
}
/**
* @return the counting04
*/
public Integer getCounting04() {
return counting04;
}
/**
* @param counting04 the counting04 to set
*/
public void setCounting04(Integer counting04) {
this.counting04 = counting04;
}
/**
* @return the counting05
*/
public Integer getCounting05() {
return counting05;
}
/**
* @param counting05 the counting05 to set
*/
public void setCounting05(Integer counting05) {
this.counting05 = counting05;
}
/**
* @return the counting06
*/
public Integer getCounting06() {
return counting06;
}
/**
* @param counting06 the counting06 to set
*/
public void setCounting06(Integer counting06) {
this.counting06 = counting06;
}
/**
* @return the counting07
*/
public Integer getCounting07() {
return counting07;
}
/**
* @param counting07 the counting07 to set
*/
public void setCounting07(Integer counting07) {
this.counting07 = counting07;
}
/**
* @return the counting08
*/
public Integer getCounting08() {
return counting08;
}
/**
* @param counting08 the counting08 to set
*/
public void setCounting08(Integer counting08) {
this.counting08 = counting08;
}
/**
* @return the counting09
*/
public Integer getCounting09() {
return counting09;
}
/**
* @param counting09 the counting09 to set
*/
public void setCounting09(Integer counting09) {
this.counting09 = counting09;
}
/**
* @return the counting10
*/
public Integer getCounting10() {
return counting10;
}
/**
* @param counting10 the counting10 to set
*/
public void setCounting10(Integer counting10) {
this.counting10 = counting10;
}
}
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of DeliaRadicumFloralisObservationModel.
* DeliaRadicumFloralisObservationModel 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.
*
* DeliaRadicumFloralisObservationModel 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 DeliaRadicumFloralisObservationModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.deliaradicumfloralisobservationmodel;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.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.observation.Observation;
import no.nibio.vips.observation.ObservationImpl;
import no.nibio.vips.util.ModelUtil;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Model{
public final static ModelId MODEL_ID = new ModelId("DELIARFOBS");
protected final static Integer DAMAGE_THRESHOLD_YOUNG_CROP = 14;
protected final static Integer DAMAGE_THRESHOLD_OLD_CROP = 40;
protected final static Integer OLD_CROP_AGE_IN_DAYS = 28;
private final ModelUtil modelUtil;
private ObjectMapper objectMapper;
private List<Observation> pestObservations;
private TimeZone timeZone;
private Date startDateGrowth;
private Date endDateCalculation;
private final Integer observationMaximumValidDays = 9;
public DeliaRadicumFloralisObservationModel()
{
super("no.nibio.vips.model.deliaradicumfloralisobservationmodel.texts");
this.modelUtil = new ModelUtil();
}
@Override
public List<Result> getResult() throws ModelExcecutionException {
List<Result> retVal = new ArrayList<>();
Calendar cal = Calendar.getInstance(timeZone);
DecimalFormat dFormat = new DecimalFormat("###.##");
Date currentDate = startDateGrowth;
while(currentDate.compareTo(endDateCalculation) <= 0)
{
Result result = new ResultImpl();
result.setResultValidTime(currentDate);
Observation latestObs = getObservationValidForDate(currentDate);
if(latestObs == null)
{
result.setWarningStatus(Result.WARNING_STATUS_NO_WARNING_MISSING_DATA);
}
else if(this.getPestObservationValue(latestObs.getObservationData()) >= this.getEconomicThreshold(currentDate))
{
result.setWarningStatus(Result.WARNING_STATUS_HIGH_RISK);
}
else
{
result.setWarningStatus(Result.WARNING_STATUS_NO_RISK);
}
Observation obsToday = getObservationAtDate(currentDate);
if(obsToday != null)
{
result.setValue(DeliaRadicumFloralisObservationModel.MODEL_ID.toString(), "OBS_AVG", dFormat.format(this.getPestObservationValue(obsToday.getObservationData())));
}
// Outsourcing this to enable override for the subclasses
this.setThresholdsInResult(result);
retVal.add(result);
// Move forward in time
cal.setTime(currentDate);
cal.add(Calendar.DATE, 1);
currentDate = cal.getTime();
}
return retVal;
}
public void setThresholdsInResult(Result result)
{
result.setValue(DeliaRadicumFloralisObservationModel.MODEL_ID.toString(), "THRESHOLD_YOUNG", String.valueOf(DeliaRadicumFloralisObservationModel.DAMAGE_THRESHOLD_YOUNG_CROP));
result.setValue(DeliaRadicumFloralisObservationModel.MODEL_ID.toString(), "THRESHOLD_OLD", String.valueOf(DeliaRadicumFloralisObservationModel.DAMAGE_THRESHOLD_OLD_CROP));
}
@Override
public ModelId getModelId() {
return DeliaRadicumFloralisObservationModel.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 DeliaRadicumFloralisObservationModel. \n" +
"DeliaRadicumFloralisObservationModel 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" +
"DeliaRadicumFloralisObservationModel 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 DeliaRadicumFloralisObservationModel. 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\"timeZone\":\"Europe/Oslo\",\n" +
"\t\t\"startDateGrowth\":\"2012-03-25\",\n" +
"\t\t\"endDateCalculation\":\"2012-03-25\",\n" +
"\t\t\"pestObservations\":[\n" +
"\t\t\t{" +
"\t\t\t\t\"timeOfObservation\":\"2016-04-20T00:00:00+02:00\"," +
"\t\t\t\t\"observationData\":{" +
"\t\t\t\t\t\"counting01\":3," +
"\t\t\t\t\t\"counting02\":2," +
"\t\t\t\t\t\"counting03\":3," +
"\t\t\t\t\t\"counting04\":4," +
"\t\t\t\t\t\"counting05\":0," +
"\t\t\t\t\t\"counting06\":0," +
"\t\t\t\t\t\"counting07\":0," +
"\t\t\t\t\t\"counting08\":0," +
"\t\t\t\t\t\"counting09\":0," +
"\t\t\t\t\t\"counting10\":0" +
"\t\t\t\t}" +
"\t\t\t\"}," +
"\t\t\t{" +
"\t\t\t\t\"timeOfObservation\":\"2016-04-25T00:00:00+02:00\"," +
"\t\t\t\t\"observationData\":{" +
"\t\t\t\t\t\"counting01\":30," +
"\t\t\t\t\t\"counting02\":18," +
"\t\t\t\t\t\"counting03\":13," +
"\t\t\t\t\t\"counting04\":14," +
"\t\t\t\t\t\"counting05\":25," +
"\t\t\t\t\t\"counting06\":20," +
"\t\t\t\t\t\"counting07\":9," +
"\t\t\t\t\t\"counting08\":15," +
"\t\t\t\t\t\"counting09\":21," +
"\t\t\t\t\t\"counting10\":21" +
"\t\t\t\t}" +
"\t\t\t\"}" +
"\t\t]\n" +
"\t}\n" +
"}\n";
}
@Override
public void setConfiguration(ModelConfiguration config) throws ConfigValidationException {
this.pestObservations = this.getObjectMapper().convertValue(config.getConfigParameter("pestObservations"), new TypeReference<List<ObservationImpl>>(){});
if(this.pestObservations == null || this.pestObservations.isEmpty())
{
throw new ConfigValidationException("ERROR: No observations");
}
Collections.sort(this.pestObservations);
// Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
//this.startDateAscosporeMaturity = mapper.convertValue(config.getConfigParameter("startDateAscosporeMaturity"), new TypeReference<java.util.Date>(){});
String[] dateparts;
try
{
dateparts = config.getConfigParameter("startDateGrowth").toString().split("-");
}
catch (NullPointerException ex){
throw new ConfigValidationException("startDateGrowth not set");
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(timeZone);
try
{
this.startDateGrowth = format.parse(config.getConfigParameter("startDateGrowth").toString());
this.endDateCalculation = format.parse(config.getConfigParameter("endDateCalculation").toString());
}
catch(ParseException | NullPointerException ex)
{
throw new ConfigValidationException("Illegal date format for startDateGrowth: " + config.getConfigParameter("startDateGrowth"));
}
}
/**
* Depends on age of crop
* @param currentDate
* @return
*/
protected Integer getEconomicThreshold(Date currentDate)
{
Calendar cal = Calendar.getInstance(this.timeZone);
cal.setTime(currentDate);
cal.add(Calendar.DATE, - DeliaRadicumFloralisObservationModel.OLD_CROP_AGE_IN_DAYS);
if(this.startDateGrowth.before(cal.getTime()))
{
return DeliaRadicumFloralisObservationModel.DAMAGE_THRESHOLD_OLD_CROP;
}
else
{
return DeliaRadicumFloralisObservationModel.DAMAGE_THRESHOLD_YOUNG_CROP;
}
}
public Observation getObservationValidForDate(Date currentDate) {
Long currentTime = currentDate.getTime();
Observation currentObservation = null;
for(Observation obs:this.pestObservations)
{
Long obsTime = obs.getTimeOfObservation().getTime();
if( currentTime - obsTime >= 0 // Must be before the current date
&& currentTime - obsTime < this.observationMaximumValidDays * (24 * 3600 * 1000) // Must be maximum [9] days before current date
&& (currentObservation == null || currentTime - obsTime < currentTime - currentObservation.getTimeOfObservation().getTime()) // Must be closer to current date than any other observations
)
{
currentObservation = obs;
}
}
return currentObservation;
}
/**
* Parses the JSON and returns the average number
* @param observationData
* @return
*/
public Double getPestObservationValue(String observationData)
{
try
{
Map<String, Double> data = this.getObjectMapper().readValue(new ByteArrayInputStream(observationData.getBytes("UTF-8")), new TypeReference<HashMap<String,Double>>() {});
Double sum = 0.0;
for(String key:data.keySet())
{
sum += data.get(key);
}
return sum/data.size();
}
catch(IOException ex)
{
return 0.0;
}
}
private ObjectMapper getObjectMapper()
{
if(this.objectMapper == null)
{
this.objectMapper = new ObjectMapper();
}
return this.objectMapper;
}
public Observation getObservationAtDate(Date currentDate) {
for(Observation obs:this.pestObservations)
{
if(obs.getTimeOfObservation().compareTo(currentDate) == 0)
{
return obs;
}
}
return null;
}
}
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of DeliaRadicumFloralisObservationModel.
* DeliaRadicumFloralisObservationModel 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.
*
* DeliaRadicumFloralisObservationModel 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 DeliaRadicumFloralisObservationModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.deliaradicumfloralisobservationmodel;
import java.util.Date;
import no.nibio.vips.entity.Result;
import no.nibio.vips.model.ModelId;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class DeliaRadicumFloralisObservationModelOldCrop extends DeliaRadicumFloralisObservationModel{
@Override
public ModelId getModelId()
{
return new ModelId("DELIARFOBO");
}
@Override
public String getModelName(String language)
{
return this.getText("nameOldCrop", language);
}
@Override
protected Integer getEconomicThreshold(Date currentDate)
{
return 40;
}
@Override
public void setThresholdsInResult(Result result)
{
result.setValue(DeliaRadicumFloralisObservationModel.MODEL_ID.toString(), "THRESHOLD_OLD", String.valueOf(DeliaRadicumFloralisObservationModel.DAMAGE_THRESHOLD_OLD_CROP));
}
}
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of DeliaRadicumFloralisObservationModel.
* DeliaRadicumFloralisObservationModel 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.
*
* DeliaRadicumFloralisObservationModel 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 DeliaRadicumFloralisObservationModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.deliaradicumfloralisobservationmodel;
import java.util.Date;
import no.nibio.vips.entity.Result;
import no.nibio.vips.model.ModelId;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class DeliaRadicumFloralisObservationModelYoungCrop extends DeliaRadicumFloralisObservationModel{
@Override
public ModelId getModelId()
{
return new ModelId("DELIARFOBY");
}
@Override
public String getModelName(String language)
{
return this.getText("nameYoungCrop", language);
}
@Override
protected Integer getEconomicThreshold(Date currentDate)
{
return 14;
}
@Override
public void setThresholdsInResult(Result result)
{
result.setValue(DeliaRadicumFloralisObservationModel.MODEL_ID.toString(), "THRESHOLD_YOUNG", String.valueOf(DeliaRadicumFloralisObservationModel.DAMAGE_THRESHOLD_YOUNG_CROP));
}
}
# 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=Delia radicum/floralis observation model
description=TODO
statusInterpretation=TODO
usage=TODO
nameYoungCrop=Delia radicum/floralis observation model for young crops
nameOldCrop=Delia radicum/floralis observation model for old crops
# 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=Liten og stor k\u00e5lflue - observasjonsmodell
description=TODO
statusInterpretation=TODO
usage=TODO
nameYoungCrop=Liten og stor k\u00e5lflue - observasjonsmodell i nyplantede felt\n
nameOldCrop=Liten og stor k\u00e5lflue - observasjonsmodell i felt eldre enn 4 uker
/*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of DeliaRadicumFloralisObservationModel.
* DeliaRadicumFloralisObservationModel 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.
*
* DeliaRadicumFloralisObservationModel 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 DeliaRadicumFloralisObservationModel. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.model.deliaradicumfloralisobservationmodel;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.text.SimpleDateFormat;
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.model.ModelId;
import no.nibio.vips.observation.Observation;
import no.nibio.vips.observation.ObservationImpl;
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 DeliaRadicumFloralisObservationModelTest {
public DeliaRadicumFloralisObservationModelTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getResult method, of class DeliaRadicumFloralisObservationModel.
*/
@Test
public void testGetResult() throws Exception {
System.out.println("getResult");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
ModelConfiguration config = new ModelConfiguration();
String tzID="Europe/Oslo";
TimeZone timeZone = TimeZone.getTimeZone(tzID);
config.setConfigParameter("timeZone", tzID);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(timeZone);
config.setConfigParameter("startDateGrowth", "2016-04-01");
config.setConfigParameter("endDateCalculation", "2016-06-01");
List<Observation> pestObservations = new ArrayList<>();
ObservationImpl obs1 = new ObservationImpl();
obs1.setTimeOfObservation(format.parse("2016-04-20"));
obs1.setObservationData("{\"counting01\":3,\"counting02\":2,\"counting03\":3,\"counting04\":4,\"counting05\":0,\"counting06\":0,\"counting07\":0,\"counting08\":0,\"counting09\":0,\"counting10\":0}");
pestObservations.add(obs1);
ObservationImpl obs2 = new ObservationImpl();
obs2.setTimeOfObservation(format.parse("2016-04-24"));
obs2.setObservationData("{\"counting01\":3,\"counting02\":12,\"counting03\":13,\"counting04\":14,\"counting05\":20,\"counting06\":18,\"counting07\":15,\"counting08\":13,\"counting09\":18,\"counting10\":22}");
pestObservations.add(obs2);
config.setConfigParameter("pestObservations", pestObservations);
instance.setConfiguration(config);
List<Result> expResult = null;
List<Result> result = instance.getResult();
System.out.println("Number of results returned: " + result.size());
for(Result res:result)
{
System.out.println(res);
}
assertNotNull(result);
}
/**
* Test of getModelId method, of class DeliaRadicumFloralisObservationModel.
*/
@Test
public void testGetModelId() {
System.out.println("getModelId");
DeliaRadicumFloralisObservationModel instance1 = new DeliaRadicumFloralisObservationModel();
DeliaRadicumFloralisObservationModel instance2 = new DeliaRadicumFloralisObservationModelYoungCrop();
DeliaRadicumFloralisObservationModel instance3 = new DeliaRadicumFloralisObservationModelOldCrop();
ModelId result = instance1.getModelId();
assertEquals("DELIARFOBS", result.toString());
result = instance2.getModelId();
assertEquals("DELIARFOBY", result.toString());
result = instance3.getModelId();
assertEquals("DELIARFOBO", result.toString());
}
/**
* Test of getModelName method, of class DeliaRadicumFloralisObservationModel.
*/
@Test
public void testGetModelName_0args() {
System.out.println("getModelName");
DeliaRadicumFloralisObservationModel instance1 = new DeliaRadicumFloralisObservationModel();
DeliaRadicumFloralisObservationModel instance2 = new DeliaRadicumFloralisObservationModelYoungCrop();
DeliaRadicumFloralisObservationModel instance3 = new DeliaRadicumFloralisObservationModelOldCrop();
assertNotNull(instance1.getModelName());
assertNotNull(instance2.getModelName());
assertNotNull(instance3.getModelName());
assertNotEquals(instance1.getModelName(), instance2.getModelName());
assertNotEquals(instance2.getModelName(), instance3.getModelName());
}
/**
* Test of getLicense method, of class DeliaRadicumFloralisObservationModel.
*/
@Test
public void testGetLicense() {
System.out.println("getLicense");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
assertNotNull(instance.getLicense());
}
/**
* Test of getCopyright method, of class DeliaRadicumFloralisObservationModel.
*/
@Test
public void testGetCopyright() {
System.out.println("getCopyright");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
assertNotNull(instance.getCopyright());
}
/**
* Test of getModelDescription method, of class DeliaRadicumFloralisObservationModel.
*/
@Test
public void testGetModelDescription_0args() {
System.out.println("getModelDescription");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
assertNotNull(instance.getModelDescription());
}
/**
* Test of getWarningStatusInterpretation method, of class DeliaRadicumFloralisObservationModel.
*/
@Test
public void testGetWarningStatusInterpretation_0args() {
System.out.println("getWarningStatusInterpretation");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
assertNotNull(instance.getWarningStatusInterpretation());
}
/**
* Test of getModelUsage method, of class DeliaRadicumFloralisObservationModel.
*/
@Test
public void testGetModelUsage_0args() {
System.out.println("getModelUsage");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
assertNotNull(instance.getModelUsage());
}
/**
* Test of getSampleConfig method, of class DeliaRadicumFloralisObservationModel.
*/
@Test
public void testGetSampleConfig() {
System.out.println("getSampleConfig");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
String result = instance.getSampleConfig();
assertNotNull(result);
}
@Test
public void testGetPestObservationValue() throws Exception {
System.out.println("testGetPestObservationValue");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
String observationData="{\"counting01\":3,\"counting02\":2,\"counting03\":3,\"counting04\":4,\"counting05\":0,\"counting06\":0,\"counting07\":0,\"counting08\":0,\"counting09\":0,\"counting10\":0}";
Double expectedResult = 1.2;
assertEquals(expectedResult, instance.getPestObservationValue(observationData));
}
@Test
public void testGetObservationAtDate() throws Exception
{
System.out.println("getObservationAtDate");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
ModelConfiguration config = new ModelConfiguration();
String tzID="Europe/Oslo";
TimeZone timeZone = TimeZone.getTimeZone(tzID);
config.setConfigParameter("timeZone", tzID);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(timeZone);
config.setConfigParameter("startDateGrowth", "2016-04-01");
config.setConfigParameter("endDateCalculation", "2016-06-01");
List<Observation> pestObservations = new ArrayList<>();
ObservationImpl obs1 = new ObservationImpl();
obs1.setTimeOfObservation(format.parse("2016-04-20"));
obs1.setObservationData("{\"counting01\":3,\"counting02\":2,\"counting03\":3,\"counting04\":4,\"counting05\":0,\"counting06\":0,\"counting07\":0,\"counting08\":0,\"counting09\":0,\"counting10\":0}");
pestObservations.add(obs1);
ObjectMapper om = new ObjectMapper();
System.out.println(om.writeValueAsString(obs1));
ObservationImpl obs2 = new ObservationImpl();
obs2.setTimeOfObservation(format.parse("2016-04-24"));
obs2.setObservationData("{\"counting01\":3,\"counting02\":12,\"counting03\":13,\"counting04\":14,\"counting05\":20,\"counting06\":18,\"counting07\":15,\"counting08\":13,\"counting09\":18,\"counting10\":22}");
pestObservations.add(obs2);
config.setConfigParameter("pestObservations", pestObservations);
instance.setConfiguration(config);
Date testDate = format.parse("2016-04-21");
Observation obs = instance.getObservationAtDate(testDate);
assertNull(obs);
testDate = format.parse("2016-04-25");
obs = instance.getObservationAtDate(testDate);
assertNull(obs);
testDate = format.parse("2016-04-19");
obs = instance.getObservationAtDate(testDate);
assertNull(obs);
testDate = format.parse("2016-04-20");
obs = instance.getObservationAtDate(testDate);
assertEquals(testDate,obs.getTimeOfObservation());
}
@Test
public void testGetObservationValidForDate() throws Exception
{
System.out.println("getObservationValidForDate");
DeliaRadicumFloralisObservationModel instance = new DeliaRadicumFloralisObservationModel();
ModelConfiguration config = new ModelConfiguration();
String tzID="Europe/Oslo";
TimeZone timeZone = TimeZone.getTimeZone(tzID);
config.setConfigParameter("timeZone", tzID);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(timeZone);
config.setConfigParameter("startDateGrowth", "2016-04-01");
config.setConfigParameter("endDateCalculation", "2016-06-01");
List<Observation> pestObservations = new ArrayList<>();
ObservationImpl obs1 = new ObservationImpl();
obs1.setTimeOfObservation(format.parse("2016-04-20"));
obs1.setObservationData("{\"counting01\":3,\"counting02\":2,\"counting03\":3,\"counting04\":4,\"counting05\":0,\"counting06\":0,\"counting07\":0,\"counting08\":0,\"counting09\":0,\"counting10\":0}");
pestObservations.add(obs1);
ObservationImpl obs2 = new ObservationImpl();
obs2.setTimeOfObservation(format.parse("2016-04-24"));
obs2.setObservationData("{\"counting01\":3,\"counting02\":12,\"counting03\":13,\"counting04\":14,\"counting05\":20,\"counting06\":18,\"counting07\":15,\"counting08\":13,\"counting09\":18,\"counting10\":22}");
pestObservations.add(obs2);
config.setConfigParameter("pestObservations", pestObservations);
instance.setConfiguration(config);
Date testDate = format.parse("2016-04-21");
Observation obs = instance.getObservationValidForDate(testDate);
assertEquals(format.parse("2016-04-20"), obs.getTimeOfObservation());
testDate = format.parse("2016-04-25");
obs = instance.getObservationValidForDate(testDate);
assertEquals(format.parse("2016-04-24"), obs.getTimeOfObservation());
testDate = format.parse("2016-04-19");
obs = instance.getObservationValidForDate(testDate);
assertNull(obs);
}
}
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