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

Refactoring to work with NetBeans/JUnit

Some final changes to make it work with VIPSCore
parent 49fe5de8
No related branches found
No related tags found
No related merge requests found
Showing
with 17 additions and 25 deletions
......@@ -4,14 +4,8 @@
<artifactId>FinnCerealModels</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>resources</directory>
<excludes>
......@@ -42,4 +36,4 @@
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
File moved
File moved
package fi.luke.vips.model.cerealmodels;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.stream.Collectors;
import fi.uef.envi.mtt.model.diseasepressure.DiseasePressureModel;
import no.nibio.vips.entity.ModelConfiguration;
......@@ -24,10 +21,8 @@ import no.nibio.vips.model.Model;
import no.nibio.vips.model.ModelExcecutionException;
import no.nibio.vips.model.ModelId;
import no.nibio.vips.util.InvalidAggregationTypeException;
import no.nibio.vips.util.WeatherElements;
import no.nibio.vips.util.WeatherObservationListException;
import no.nibio.vips.util.WeatherUtil;
import no.nibio.vips.util.test.WeatherDataFileReader;
public class FinnCerealModels implements Model {
private final static ModelId MODEL_ID = new ModelId("FINNCEREAL");
......@@ -132,6 +127,7 @@ public class FinnCerealModels implements Model {
if(wetLeaves == null) {
throw new ModelExcecutionException("Leaf wetness data not found!");
}
m.setLeafIsWet(wetLeaves);
List<Double> wind = windSpeed2.get(currentDate);
if(wind == null) {
......@@ -213,16 +209,16 @@ public class FinnCerealModels implements Model {
double measurement = wo.getValue();
// TODO This if-else -structure contains part of the model definition. Should this be changed?
if(measurement >= 87) {
wetList.add(true);
wetList.add(Boolean.TRUE);
prevWet = true;
} else if(measurement < 70) {
wetList.add(false);
wetList.add(Boolean.FALSE);
prevWet = false;
} else if(measurement - prevRh > 6) { // Rh is increasing
wetList.add(true);
wetList.add(Boolean.TRUE);
prevWet = true;
} else if(prevRh - measurement > 4) { // Rh is decreasing
wetList.add(false);
wetList.add(Boolean.FALSE);
prevWet = false;
} else {
wetList.add(prevWet);
......@@ -286,7 +282,7 @@ public class FinnCerealModels implements Model {
@Override
public void setConfiguration(ModelConfiguration arg0) throws ConfigValidationException {
m = new DiseasePressureModel(new BufferedInputStream(this.getClass().getResourceAsStream(
"model-constants.json")));
"/model-constants.json")));
try {
String zoneString = (String)arg0.getConfigParameter("timeZone");
if(zoneString == null) {
......@@ -321,11 +317,11 @@ public class FinnCerealModels implements Model {
}
// weather information
List<WeatherObservation> temperature = (List<WeatherObservation>)arg0.getConfigParameter("temperature");
List<WeatherObservation> rainfall = (List<WeatherObservation>)arg0.getConfigParameter("rainfall");
List<WeatherObservation> rh = (List<WeatherObservation>)arg0.getConfigParameter("rh");
List<WeatherObservation> windSpeedAll = (List<WeatherObservation>)arg0.getConfigParameter("windspeed");
ObjectMapper objectMapper = new ObjectMapper();
List<WeatherObservation> temperature = objectMapper.convertValue(arg0.getConfigParameter("temperature"), new TypeReference<List<WeatherObservation>>(){});
List<WeatherObservation> rainfall = objectMapper.convertValue(arg0.getConfigParameter("rainfall"), new TypeReference<List<WeatherObservation>>(){});
List<WeatherObservation> rh = objectMapper.convertValue(arg0.getConfigParameter("rh"), new TypeReference<List<WeatherObservation>>(){});
List<WeatherObservation> windSpeedAll = objectMapper.convertValue(arg0.getConfigParameter("windspeed"), new TypeReference<List<WeatherObservation>>(){});
WeatherUtil wu = new WeatherUtil();
// get average daily temperatures
try {
......
......@@ -137,5 +137,7 @@ public class DiseasePressureModel {
public double getAccumulatedRisk() {
return accumulatedRisk.compute();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment