diff --git a/pom.xml b/pom.xml index 82b6234a15791b77be846e046bcbe10cd5eba0a6..7ae48d2d63e9768a2eac9fd640b56d22a08d3251 100755 --- a/pom.xml +++ b/pom.xml @@ -112,7 +112,7 @@ <dependency> <groupId>no.nibio.vips.common</groupId> <artifactId>VIPSCommon</artifactId> - <version>2022.1</version> + <version>1.0-SNAPSHOT</version> <type>jar</type> <exclusions> <exclusion> diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/LeafBlotchModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/LeafBlotchModelPreprocessor.java new file mode 100644 index 0000000000000000000000000000000000000000..c4f7822c593823fab14481a1a5300af675ca879b --- /dev/null +++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/LeafBlotchModelPreprocessor.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2022 NIBIO <http://www.nibio.no/>. + * + * This file is part of VIPSLogic. + * VIPSLogic 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. + * + * VIPSLogic 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 VIPSLogic. If not, see <http://www.nibio.no/licenses/>. + * + */ +package no.nibio.vips.logic.scheduling.model.preprocessor; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import java.util.logging.Logger; + +import no.nibio.vips.entity.ModelConfiguration; +import no.nibio.vips.entity.WeatherObservation; +import no.nibio.vips.logic.entity.ForecastConfiguration; +import no.nibio.vips.logic.entity.PointOfInterestWeatherStation; +import no.nibio.vips.logic.scheduling.model.ModelRunPreprocessor; +import no.nibio.vips.logic.scheduling.model.PreprocessorException; +import no.nibio.vips.logic.util.SystemTime; +import no.nibio.vips.util.WeatherElements; +import no.nibio.vips.util.WeatherUtil; +import no.nibio.vips.util.weather.WeatherDataSourceException; +import no.nibio.vips.util.weather.WeatherDataSourceUtil; + +/** + * + * @author mila + */ +public class LeafBlotchModelPreprocessor extends ModelRunPreprocessor{ + public final static String LEAFBLOTCH_sowingDate = "LEAFBLOTCH_SOWING_DATE"; + @Override + public ModelConfiguration getModelConfiguration(ForecastConfiguration configuration) throws PreprocessorException { + PointOfInterestWeatherStation weatherStation = (PointOfInterestWeatherStation) configuration.getWeatherStationPointOfInterestId(); + + //Latitude for the calculation + Double latitude = weatherStation.getLatitude(); + + // What timezone is the calculation for + TimeZone timeZone = TimeZone.getTimeZone(weatherStation.getTimeZone()); + Calendar cal = Calendar.getInstance(timeZone); + cal.setTime(SystemTime.getSystemTime()); + cal.add(Calendar.DATE, 3); + + WeatherUtil wUtil = new WeatherUtil(); + Date endDate = wUtil.normalizeToExactDate(cal.getTime(), timeZone); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + format.setTimeZone(timeZone); + Date startDate = null; + try { + startDate = format.parse(configuration.getForecastModelConfigurationValue(LEAFBLOTCH_sowingDate)); + } catch (ParseException ex) { + //Logger.getLogger(LeafBlotchModelPreprocess.class.getName()).log(Level.SEVERE, null, ex); + } + + ModelConfiguration retVal = new ModelConfiguration(); + WeatherDataSourceUtil wdsUtil = new WeatherDataSourceUtil(); + + //Hourly weather observations: + List<WeatherObservation> observations; + try { + observations = wdsUtil.getWeatherObservations( + weatherStation, + WeatherObservation.LOG_INTERVAL_ID_1H, + new String[]{ + WeatherElements.TEMPERATURE_MEAN, + WeatherElements.PRECIPITATION, + WeatherElements.RELATIVE_HUMIDITY_MEAN + }, + startDate, + endDate); + } catch (WeatherDataSourceException ex) { + throw new PreprocessorException(ex.getMessage()); + } + + //Daily weather observations: + List<WeatherObservation> dailyObs; + try { + dailyObs = wdsUtil.getWeatherObservations( + weatherStation, + WeatherObservation.LOG_INTERVAL_ID_1D, + new String[]{ + WeatherElements.TEMPERATURE_MEAN + }, + startDate, + endDate); + } catch (WeatherDataSourceException ex) { + throw new PreprocessorException(ex.getMessage()); + } + //Combining hourly and daily data + observations.addAll(dailyObs); + + retVal.setModelId(this.getModelId()); + retVal.setConfigParameter("timeZone", timeZone.getID()); + retVal.setConfigParameter("observations", observations); + retVal.setConfigParameter("latitude", latitude); + retVal.setConfigParameter("sowingDate", format.format(startDate)); + + return retVal; + } + + @Override + public String getModelId() { + return "LEAFBLOTCH"; + } + +} diff --git a/src/main/webapp/formdefinitions/models/LEAFBLOTCH.json b/src/main/webapp/formdefinitions/models/LEAFBLOTCH.json new file mode 100644 index 0000000000000000000000000000000000000000..2fc42b68dc692767bb85de9973ff752460cb3daf --- /dev/null +++ b/src/main/webapp/formdefinitions/models/LEAFBLOTCH.json @@ -0,0 +1,28 @@ +{ + "_licenseNote": [ + "Copyright (c) 2016 NIBIO <http://www.nibio.no/>. ", + "", + "This file is part of VIPSLogic. ", + "VIPSLogic 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. ", + "", + "VIPSLogic 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 VIPSLogic. If not, see <http://www.nibio.no/licenses/>. " + ], + "_comment" : "Structure of the specific fields for LEAFBLOTCH", + "fields": [ + { + "name" : "sowingDate", + "dataType" : "DATE", + "dateFormat" : "yyyy-MM-dd", + "required" : true + } + ] +}