Merge pull request #85 from schrom01/feature_weather
#23 bugfix testclass WeatherGradenTaskPlannerTest and bugfix Task and…
This commit is contained in:
@@ -25,11 +25,12 @@ public class BackgroundTasks extends TimerTask {
|
||||
|
||||
private void movePastTasks() throws IOException {
|
||||
List<Task> taskList = this.taskList.getTaskList(LocalDate.MIN, LocalDate.now().minusDays(1));
|
||||
taskList.forEach(task -> {
|
||||
for (Task task : taskList) {
|
||||
if (!task.isDone()) {
|
||||
task.setNextExecution(LocalDate.now());
|
||||
this.taskList.saveTask(task);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public BackgroundTasks(TaskList taskList, CropList cropList, PlantList plantList) {
|
||||
|
||||
+66
-14
@@ -9,8 +9,12 @@ import ch.zhaw.gartenverwaltung.types.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
/**
|
||||
* The WeatherGardenTaskPlanner creates Tasks based on weather events and the rain amount from the last days
|
||||
*
|
||||
@@ -43,8 +47,7 @@ public class WeatherGradenTaskPlanner {
|
||||
private void getSevereWeatherEvents() throws IOException {
|
||||
SevereWeather actualWeather = weatherService.causeSevereWeather(1);
|
||||
if (SevereWeather.HAIL.equals(actualWeather)) {
|
||||
//ToDo creates hail task all 3 seconds, pls fix
|
||||
//createPreHailTask();
|
||||
createPreHailTask();
|
||||
} else if (SevereWeather.FROST.equals(actualWeather)) {
|
||||
createPreFrostTask();
|
||||
} else if (SevereWeather.SNOW.equals(actualWeather)) {
|
||||
@@ -63,11 +66,27 @@ public class WeatherGradenTaskPlanner {
|
||||
*/
|
||||
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",
|
||||
dateSevereWeather.minusDays(1L),dateSevereWeather.plusDays(1L),1L);
|
||||
taskList.saveTask(preHailTask);
|
||||
List<Crop> actualCrops = cropList.getCrops();
|
||||
|
||||
for (Crop crop : actualCrops) {
|
||||
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",
|
||||
dateSevereWeather,dateSevereWeather.plusDays(1L),crop.getCropId().orElse(-1L));
|
||||
|
||||
List<Task> actualCropTaskList = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||
List<Task> hailTasklist = actualCropTaskList.stream().filter(task -> task.getName().equals("Hail")).toList();
|
||||
|
||||
List<Task> hailTaskListAtDate = new ArrayList<>();
|
||||
for (Task task : hailTasklist) {
|
||||
if (task.getStartDate() == (preHailTask.getStartDate())) {
|
||||
hailTaskListAtDate.add(task);
|
||||
}
|
||||
}
|
||||
|
||||
if(hailTaskListAtDate.isEmpty() && hailTasklist.isEmpty()){
|
||||
taskList.saveTask(preHailTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,10 +94,26 @@ public class WeatherGradenTaskPlanner {
|
||||
* @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),1L);
|
||||
taskList.saveTask(preFrostTask);
|
||||
List<Crop> actualCrops = cropList.getCrops();
|
||||
for (Crop crop : actualCrops) {
|
||||
|
||||
Task preFrostTask = new Task("Frost",
|
||||
"The temperatur falls below zero degrees, cover especially the root with wool",
|
||||
dateSevereWeather,dateSevereWeather.plusDays(1L),crop.getCropId().orElse(-1L));
|
||||
|
||||
List<Task> actualCropTaskList = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||
List<Task> frostTasklist = actualCropTaskList.stream().filter(task -> task.getName().equals("Frost")).toList();
|
||||
|
||||
List<Task> frostTaskListAtDate = new ArrayList<>();
|
||||
for (Task task : frostTasklist) {
|
||||
if (task.getStartDate() == preFrostTask.getStartDate()) {
|
||||
frostTaskListAtDate.add(task);
|
||||
}
|
||||
}
|
||||
if(frostTaskListAtDate.isEmpty() && frostTasklist.isEmpty()){
|
||||
taskList.saveTask(preFrostTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,10 +121,27 @@ public class WeatherGradenTaskPlanner {
|
||||
* @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),1L);
|
||||
taskList.saveTask(preSnowTask);
|
||||
List<Crop> actualCrops = cropList.getCrops();
|
||||
for (Crop crop : actualCrops) {
|
||||
|
||||
Task preSnowTask = new Task("Snow",
|
||||
"The weather brings little snowfall. Cover your crops",
|
||||
dateSevereWeather, dateSevereWeather.plusDays(1L), crop.getCropId().orElse(-1L));
|
||||
|
||||
List<Task> actualCropTaskList = taskList.getTaskForCrop(crop.getCropId().orElse(-1L));
|
||||
List<Task> snowTasklist = actualCropTaskList.stream().filter(task -> task.getName().equals("Snow")).toList();
|
||||
|
||||
List<Task> snowTaskListAtDate = new ArrayList<>();
|
||||
for (Task task : snowTasklist) {
|
||||
if (task.getStartDate() == preSnowTask.getStartDate()) {
|
||||
snowTaskListAtDate.add(task);
|
||||
}
|
||||
}
|
||||
if(snowTaskListAtDate .isEmpty() && snowTasklist.isEmpty()){
|
||||
taskList.saveTask(preSnowTask);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,6 +63,7 @@ public class Task {
|
||||
this.startDate = startDate;
|
||||
nextExecution = startDate;
|
||||
this.endDate = endDate;
|
||||
this.cropId = cropId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user