#23 documentation

This commit is contained in:
Gian-Andrea Hutter 2022-12-05 11:40:09 +01:00
parent 0fa2b81427
commit 28f76e7a04
2 changed files with 45 additions and 6 deletions

View File

@ -11,6 +11,10 @@ import java.io.IOException;
import java.time.LocalDate;
import java.util.List;
/**
* The WeatherGardenTaskPlanner creates Tasks based on weather events and the rain amount from the last days
*
*/
public class WeatherGradenTaskPlanner {
private final TaskList taskList;
private final PlantList plantList;
@ -25,6 +29,12 @@ public class WeatherGradenTaskPlanner {
weatherService = new WeatherService();
}
/**
* Method to refresh watering tasks and severe weather tasks
* @throws IOException If the database cannot be accessed
* @throws HardinessZoneNotSetException If the hardiness zone is not available
* @throws PlantNotFoundException if the plant is not available for the watering task
*/
public void refreshTasks() throws IOException, HardinessZoneNotSetException, PlantNotFoundException {
getSevereWeatherEvents();
getRainAmount();
@ -46,7 +56,11 @@ public class WeatherGradenTaskPlanner {
adjustWateringTask(rainAmount);
}
public void createPreHailTask() throws IOException {
/**
* Method to create a PreHailTask
* @throws IOException If the database cannot be accessed
*/
private void createPreHailTask() throws IOException {
Task preHailTask = new Task("Hail",
"During a summer Thunderstorm it could hail heavily. THe Hail could damage the crops. To prevent damage cover the plants with a strong tarpaulin",
@ -55,21 +69,36 @@ public class WeatherGradenTaskPlanner {
}
public void createPreFrostTask() throws IOException {
/**
* Method to create a PreFrosttask
* @throws IOException If the database cannot be accessed
*/
private void createPreFrostTask() throws IOException {
Task preFrostTask = new Task("Frost",
"The temperatur falls below zero degrees, cover especially the root with wool",
dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L));
taskList.saveTask(preFrostTask);
}
public void createPreSnowTask() throws IOException {
/**
* Method to create a PreSnowTask
* @throws IOException If the database cannot be accessed
*/
private void createPreSnowTask() throws IOException {
Task preSnowTask = new Task("Snow",
"The weather brings little snowfall. Cover your crops",
dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L));
taskList.saveTask(preSnowTask);
}
public void adjustWateringTask(int rainAmount) throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
/**
* Method to adjust the water plant tasks
* @param rainAmount Amount of rain from the last 7 days
* @throws IOException If the database cannot be accessed
* @throws HardinessZoneNotSetException If the hardiness zone is not available
* @throws PlantNotFoundException if the plant is not available for the watering task
*/
private void adjustWateringTask(int rainAmount) throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
for (Crop crop : cropList.getCrops()) {
Plant plant = plantList.getPlantById(HardinessZone.ZONE_8A,crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
@ -80,7 +109,14 @@ public class WeatherGradenTaskPlanner {
}
}
// vom startdatum abhängig,
/**
* Method to set next execution date of the water plant tasks
* @param cropTaskList List with tasks from crops
* @throws IOException If the database cannot be accessed
* @throws HardinessZoneNotSetException If the hardiness zone is not available
* @throws PlantNotFoundException if the plant is not available for the watering task
*/
private void adjustNextExecutionOfWateringTasks(List<Task> cropTaskList){
for(Task task : cropTaskList){
if(task.getName().equals("water plant")){

View File

@ -1,5 +1,8 @@
package ch.zhaw.gartenverwaltung.backgroundtasks.weather;
/**
* The WeatherService is a class to cause weather events for the WeatherGardenTaskPlanner
*
*/
public class WeatherService {
private static final int NO_RAIN = 0;
private static final int LITTLE_RAIN = 15;