diff --git a/src/main/java/no/nibio/vips/logic/controller/session/SchedulingBean.java b/src/main/java/no/nibio/vips/logic/controller/session/SchedulingBean.java index 5778f6c8ddb90ffeda30c8bfa10ac8563bb7e939..4ba5b84b7c265f39f60a687fd2de288a1d16e096 100755 --- a/src/main/java/no/nibio/vips/logic/controller/session/SchedulingBean.java +++ b/src/main/java/no/nibio/vips/logic/controller/session/SchedulingBean.java @@ -217,9 +217,6 @@ public class SchedulingBean { sendForecastNotificationsCollector.getTasks().add(morningAndAfternoonPattern, VipsLogicTaskFactory.createVipsLogicTask(VipsLogicTaskFactory.SEND_FORECAST_EVENT_NOTIFICATIONS_TASK)); - // Run grid models - VIPSLogicTaskCollector runGridModelsCollector = new VIPSLogicTaskCollector(-1); - runGridModelsCollector.getTasks().add(morningAndAfternoonPattern, VipsLogicTaskFactory.createVipsLogicTask(VipsLogicTaskFactory.RUN_GRID_MODELS_TASK)); List<TaskCollector> definedTasks = new ArrayList<>(); definedTasks.add(modelRunCollector); @@ -227,7 +224,6 @@ public class SchedulingBean { definedTasks.add(summariesCollector); definedTasks.add(deleteAllExpiredUserUuidsCollector); definedTasks.add(sendForecastNotificationsCollector); - definedTasks.add(runGridModelsCollector); return definedTasks; } diff --git a/src/main/java/no/nibio/vips/logic/scheduling/VipsLogicTaskFactory.java b/src/main/java/no/nibio/vips/logic/scheduling/VipsLogicTaskFactory.java index 38151970bf13e2851461ebf1d1ba560f112c51a1..66ae454af9550f24ce0552d5de6bb17d9cd2e87f 100755 --- a/src/main/java/no/nibio/vips/logic/scheduling/VipsLogicTaskFactory.java +++ b/src/main/java/no/nibio/vips/logic/scheduling/VipsLogicTaskFactory.java @@ -26,7 +26,6 @@ import no.nibio.vips.logic.scheduling.tasks.DeleteAllExpiredUserUuidsTask; import no.nibio.vips.logic.scheduling.tasks.RunAllForecastConfigurationsForOrganizationTask; import no.nibio.vips.logic.scheduling.tasks.RunAllForecastConfigurationsTask; import no.nibio.vips.logic.scheduling.tasks.RunForecastConfigurationsByIdTask; -import no.nibio.vips.logic.scheduling.tasks.RunGridModelsTask; import no.nibio.vips.logic.scheduling.tasks.SendForecastEventNotificationsTask; import no.nibio.vips.logic.scheduling.tasks.UpdateForecastResultCacheTableTask; import no.nibio.vips.logic.scheduling.tasks.UpdateForecastSummaryTableTask; @@ -46,7 +45,7 @@ public class VipsLogicTaskFactory { public static final int DELETE_ALL_EXPIRED_UUIDS_TASK = 5; public static final int SEND_FORECAST_EVENT_NOTIFICATIONS_TASK = 6; public static final int RUN_ALL_FORECAST_CONFIGURATIONS_FOR_ORGANIZATION_TASK = 7; - public static final int RUN_GRID_MODELS_TASK = 8; + //public static final int RUN_GRID_MODELS_TASK = 8; public static final int RUN_FORECAST_CONFIGURATIONS_BY_ID_TASK = 9; @@ -89,9 +88,6 @@ public class VipsLogicTaskFactory { case RUN_ALL_FORECAST_CONFIGURATIONS_FOR_ORGANIZATION_TASK: retVal = new RunAllForecastConfigurationsForOrganizationTask(); break; - case RUN_GRID_MODELS_TASK: - retVal = new RunGridModelsTask(); - break; case RUN_FORECAST_CONFIGURATIONS_BY_ID_TASK: retVal = new RunForecastConfigurationsByIdTask(); break; diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/grid/preprocessor/ZymoseptoriaSimpleRiskGridModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/grid/preprocessor/ZymoseptoriaSimpleRiskGridModelPreprocessor.java deleted file mode 100644 index 9161fc5d77bd11c0006f9e277c6298373a70622e..0000000000000000000000000000000000000000 --- a/src/main/java/no/nibio/vips/logic/scheduling/model/grid/preprocessor/ZymoseptoriaSimpleRiskGridModelPreprocessor.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2018 NIBIO <http://www.nibio.no/>. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ - -package no.nibio.vips.logic.scheduling.model.grid.preprocessor; - -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import javax.ejb.EJB; -import no.nibio.vips.entity.ModelConfiguration; -import no.nibio.vips.entity.PointWeatherObservationList; -import no.nibio.vips.entity.WeatherObservation; -import no.nibio.vips.gis.CoordinateProxy; -import no.nibio.vips.logic.controller.session.PointOfInterestBean; -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.WeatherObservationListException; -import no.nibio.vips.util.WeatherUtil; -import no.nibio.vips.util.weather.WeatherDataSourceException; -import no.nibio.vips.util.weather.WeatherDataSourceUtil; - -/** - * @copyright 2018-2022 <a href="http://www.nibio.no/">NIBIO</a> - * @author Tor-Einar Skog <tor-einar.skog@nibio.no> - */ -public class ZymoseptoriaSimpleRiskGridModelPreprocessor extends ModelRunPreprocessor{ - - @EJB - PointOfInterestBean pointOfInterestBean; - - @Override - public ModelConfiguration getModelConfiguration(ForecastConfiguration configuration) throws PreprocessorException { - - ModelConfiguration modelConfig = new ModelConfiguration(); - // Which weather stations?? - // Ilseng and Apelsvoll to start with ;-) - List<PointOfInterestWeatherStation> stations = Stream.of(configuration.getGridWeatherStationPointOfInterestIds()).map( - stationId -> (PointOfInterestWeatherStation) pointOfInterestBean.getPointOfInterest(stationId) - ).collect(Collectors.toList()); - - List<PointWeatherObservationList> allObs = new ArrayList<>(); - WeatherUtil wUtil = new WeatherUtil(); - for(PointOfInterestWeatherStation station:stations) - { - CoordinateProxy coordinate = new CoordinateProxy(station.getPointOfInterest().getLongitude(), station.getPointOfInterest().getLatitude()); - List<WeatherObservation> stationObs = getStationObs(station, configuration); - - try - { - // We need TM, UM and RR. BT is optional - List<WeatherObservation> mandatory = wUtil.filterWeatherObservationsByParameter(stationObs, new HashSet<>(Arrays.asList("TM","UM","RR"))); - stationObs = wUtil.checkForAndFixHourlyTimeSeriesHolesMultiParameter(mandatory, 6); - } - catch(WeatherObservationListException ex) - { - //throw new PreprocessorException(); - System.out.println("Problem with station " + station.getPointOfInterest().getName() + " (#" + station.getPointOfInterestId() + "): " + ex.getMessage()); - continue; - } - // Checking for BT - try - { - List<WeatherObservation> BT = wUtil.filterWeatherObservationsByParameter(stationObs, new HashSet<>(Arrays.asList("BT"))); - stationObs.addAll(wUtil.checkForAndFixHourlyTimeSeriesHoles(BT, 6)); - } - catch(WeatherObservationListException ex) - { - System.out.println("Problem with station " + station.getPointOfInterest().getName() + " (#" + station.getPointOfInterestId() + "): " + ex.getMessage()); - } - - - // TODO: Remove this debug - /* - if(station.getPointOfInterestId().equals(345)) - { - Collections.sort(stationObs); - stationObs.forEach(obs->System.out.println(obs)); - }*/ - - - PointWeatherObservationList pointObs = new PointWeatherObservationList(coordinate, stationObs, station.getTimeZone()); - allObs.add(pointObs); - } - - modelConfig.setConfigParameter("multiPointWeatherObservations", allObs); - modelConfig.setModelId(this.getModelId()); - modelConfig.setConfigParameter("timeZone", configuration.getTimeZone()); - return modelConfig; - } - - @Override - public String getModelId() { - return "GRIDZYMOSE"; - } - - private List<WeatherObservation> getStationObs(PointOfInterestWeatherStation station, ForecastConfiguration configuration) throws PreprocessorException - { - List<WeatherObservation> stationObs;// = new ArrayList<>(); - WeatherDataSourceUtil wdsUtil = new WeatherDataSourceUtil(); - - // We run this for max 1 week back in time to make sure it doesn't crash - ZonedDateTime aWeekAgo = ZonedDateTime.ofInstant(SystemTime.getSystemTime().toInstant(), ZoneId.of("Europe/Oslo")).minus(1, ChronoUnit.WEEKS); - ZonedDateTime aWeekAhead = ZonedDateTime.ofInstant(SystemTime.getSystemTime().toInstant(), ZoneId.of("Europe/Oslo")).plus(1, ChronoUnit.WEEKS); - try { - - stationObs = wdsUtil.getWeatherObservations( - station, - WeatherObservation.LOG_INTERVAL_ID_1H, - new String[]{ - WeatherElements.LEAF_WETNESS_DURATION, - WeatherElements.RELATIVE_HUMIDITY_MEAN, - WeatherElements.PRECIPITATION, - WeatherElements.TEMPERATURE_MEAN - }, - Date.from(aWeekAgo.toInstant()), - Date.from(aWeekAhead.toInstant()), - true, - new HashSet<>(Arrays.asList(WeatherObservation.LOG_INTERVAL_ID_1H,WeatherObservation.LOG_INTERVAL_ID_3H, WeatherObservation.LOG_INTERVAL_ID_6H)) - ); - return stationObs; - } catch (WeatherDataSourceException ex ) { - throw new PreprocessorException(ex.getMessage()); - } - } -} diff --git a/src/main/java/no/nibio/vips/logic/scheduling/tasks/RunGridModelsTask.java b/src/main/java/no/nibio/vips/logic/scheduling/tasks/RunGridModelsTask.java deleted file mode 100644 index 072565dfb10c5a919ccda14937fd3c5bcd6453eb..0000000000000000000000000000000000000000 --- a/src/main/java/no/nibio/vips/logic/scheduling/tasks/RunGridModelsTask.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2018 NIBIO <http://www.nibio.no/>. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ - -package no.nibio.vips.logic.scheduling.tasks; - -import it.sauronsoftware.cron4j.TaskExecutionContext; -import javax.ejb.EJB; -import no.nibio.vips.logic.controller.session.ForecastBean; -import no.nibio.vips.logic.controller.session.SessionControllerGetter; -import no.nibio.vips.logic.entity.ForecastConfiguration; -import no.nibio.vips.logic.scheduling.SchedulingUtil; -import no.nibio.vips.logic.scheduling.VipsLogicTask; -import no.nibio.vips.logic.scheduling.model.PreprocessorException; -import no.nibio.vips.logic.util.RunModelException; - -/** - * @copyright 2018-2022 <a href="http://www.nibio.no/">NIBIO</a> - * @author Tor-Einar Skog <tor-einar.skog@nibio.no> - */ -public class RunGridModelsTask extends VipsLogicTask{ - - @Override - public String getConfigFormDefinition(String language) { - return "{\"fields\":[]}"; - } - - @Override - public void execute(TaskExecutionContext tec) throws RuntimeException { - tec.setCompleteness(0.0); - //ZymoseptoriaSimpleRiskGridModelPreprocessor pp = new ZymoseptoriaSimpleRiskGridModelPreprocessor(); - // TODO: Must find a forecast configuration id! -1000 ! - - ForecastConfiguration fConfig = SessionControllerGetter.getForecastBean().getForecastConfiguration(-1000l); - - try - { - SessionControllerGetter.getForecastBean().runForecast(fConfig); - tec.setCompleteness(1.0); - } - catch(PreprocessorException | RunModelException ex) - { - tec.setCompleteness(0.0); - tec.setStatusMessage(SchedulingUtil.createSchedulingMessageHTML( - "Error with forecast #" + fConfig.getForecastConfigurationId(), - ex.getMessage(), - SchedulingUtil.MESSAGE_STATUS_DANGER - ) - ); - - ex.printStackTrace(); - throw new RuntimeException(); - } - } - - @Override - public boolean supportsStatusTracking() - { - return true; - } - - @Override - public boolean supportsCompletenessTracking() - { - return true; - } -}