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

Remove old non-functional grid model task

parent abe64fbe
Branches
No related tags found
No related merge requests found
...@@ -217,9 +217,6 @@ public class SchedulingBean { ...@@ -217,9 +217,6 @@ public class SchedulingBean {
sendForecastNotificationsCollector.getTasks().add(morningAndAfternoonPattern, VipsLogicTaskFactory.createVipsLogicTask(VipsLogicTaskFactory.SEND_FORECAST_EVENT_NOTIFICATIONS_TASK)); 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<>(); List<TaskCollector> definedTasks = new ArrayList<>();
definedTasks.add(modelRunCollector); definedTasks.add(modelRunCollector);
...@@ -227,7 +224,6 @@ public class SchedulingBean { ...@@ -227,7 +224,6 @@ public class SchedulingBean {
definedTasks.add(summariesCollector); definedTasks.add(summariesCollector);
definedTasks.add(deleteAllExpiredUserUuidsCollector); definedTasks.add(deleteAllExpiredUserUuidsCollector);
definedTasks.add(sendForecastNotificationsCollector); definedTasks.add(sendForecastNotificationsCollector);
definedTasks.add(runGridModelsCollector);
return definedTasks; return definedTasks;
} }
......
...@@ -26,7 +26,6 @@ import no.nibio.vips.logic.scheduling.tasks.DeleteAllExpiredUserUuidsTask; ...@@ -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.RunAllForecastConfigurationsForOrganizationTask;
import no.nibio.vips.logic.scheduling.tasks.RunAllForecastConfigurationsTask; import no.nibio.vips.logic.scheduling.tasks.RunAllForecastConfigurationsTask;
import no.nibio.vips.logic.scheduling.tasks.RunForecastConfigurationsByIdTask; 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.SendForecastEventNotificationsTask;
import no.nibio.vips.logic.scheduling.tasks.UpdateForecastResultCacheTableTask; import no.nibio.vips.logic.scheduling.tasks.UpdateForecastResultCacheTableTask;
import no.nibio.vips.logic.scheduling.tasks.UpdateForecastSummaryTableTask; import no.nibio.vips.logic.scheduling.tasks.UpdateForecastSummaryTableTask;
...@@ -46,7 +45,7 @@ public class VipsLogicTaskFactory { ...@@ -46,7 +45,7 @@ public class VipsLogicTaskFactory {
public static final int DELETE_ALL_EXPIRED_UUIDS_TASK = 5; public static final int DELETE_ALL_EXPIRED_UUIDS_TASK = 5;
public static final int SEND_FORECAST_EVENT_NOTIFICATIONS_TASK = 6; 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_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; public static final int RUN_FORECAST_CONFIGURATIONS_BY_ID_TASK = 9;
...@@ -89,9 +88,6 @@ public class VipsLogicTaskFactory { ...@@ -89,9 +88,6 @@ public class VipsLogicTaskFactory {
case RUN_ALL_FORECAST_CONFIGURATIONS_FOR_ORGANIZATION_TASK: case RUN_ALL_FORECAST_CONFIGURATIONS_FOR_ORGANIZATION_TASK:
retVal = new RunAllForecastConfigurationsForOrganizationTask(); retVal = new RunAllForecastConfigurationsForOrganizationTask();
break; break;
case RUN_GRID_MODELS_TASK:
retVal = new RunGridModelsTask();
break;
case RUN_FORECAST_CONFIGURATIONS_BY_ID_TASK: case RUN_FORECAST_CONFIGURATIONS_BY_ID_TASK:
retVal = new RunForecastConfigurationsByIdTask(); retVal = new RunForecastConfigurationsByIdTask();
break; break;
......
/*
* 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());
}
}
}
/*
* 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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment