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

A couple of bugfixes and updates

parent d19ab8c0
Branches
Tags
No related merge requests found
......@@ -20,6 +20,7 @@
package no.nibio.vips.model.deliaradicumfloralisobservationmodel;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayInputStream;
import java.io.IOException;
......@@ -45,6 +46,7 @@ import no.nibio.vips.model.ModelId;
import no.nibio.vips.observation.Observation;
import no.nibio.vips.observation.ObservationImpl;
import no.nibio.vips.util.ModelUtil;
import no.nibio.vips.util.WeatherUtil;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -57,6 +59,7 @@ public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Mo
protected final static Integer DAMAGE_THRESHOLD_OLD_CROP = 40;
protected final static Integer OLD_CROP_AGE_IN_DAYS = 28;
private final ModelUtil modelUtil;
private final WeatherUtil weatherUtil;
private ObjectMapper objectMapper;
......@@ -70,6 +73,7 @@ public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Mo
{
super("no.nibio.vips.model.deliaradicumfloralisobservationmodel.texts");
this.modelUtil = new ModelUtil();
this.weatherUtil = new WeatherUtil();
}
@Override
......@@ -248,7 +252,7 @@ public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Mo
@Override
public void setConfiguration(ModelConfiguration config) throws ConfigValidationException {
this.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.pestObservations = this.getObjectMapper().convertValue(config.getConfigParameter("pestObservations"), new TypeReference<List<ObservationImpl>>(){});
if(this.pestObservations == null || this.pestObservations.isEmpty())
{
......@@ -307,7 +311,7 @@ public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Mo
Observation currentObservation = null;
for(Observation obs:this.pestObservations)
{
Long obsTime = obs.getTimeOfObservation().getTime();
Long obsTime = this.weatherUtil.normalizeToExactDate(obs.getTimeOfObservation(), timeZone).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
......@@ -354,7 +358,7 @@ public class DeliaRadicumFloralisObservationModel extends I18nImpl implements Mo
public Observation getObservationAtDate(Date currentDate) {
for(Observation obs:this.pestObservations)
{
if(obs.getTimeOfObservation().compareTo(currentDate) == 0)
if(this.weatherUtil.normalizeToExactDate(obs.getTimeOfObservation(), timeZone).compareTo(currentDate) == 0)
{
return obs;
}
......
# 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
nameYoungCrop=Liten og stor k\u00e5lflue - observasjonsmodell i nyplantede felt
nameOldCrop=Liten og stor k\u00e5lflue - observasjonsmodell i felt eldre enn 4 uker
......@@ -96,10 +96,10 @@ public class DeliaRadicumFloralisObservationModelTest {
List<Result> expResult = null;
List<Result> result = instance.getResult();
System.out.println("Number of results returned: " + result.size());
for(Result res:result)
/*for(Result res:result)
{
System.out.println(res);
}
}*/
assertNotNull(result);
}
......@@ -238,8 +238,8 @@ public class DeliaRadicumFloralisObservationModelTest {
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));
/*ObjectMapper om = new ObjectMapper();
System.out.println(om.writeValueAsString(obs1));*/
ObservationImpl obs2 = new ObservationImpl();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment