#23 watering task refactor
This commit is contained in:
@@ -32,7 +32,6 @@ public class AppLoader {
|
||||
private final TaskList taskList = new JsonTaskList();
|
||||
|
||||
private final GardenSchedule gardenSchedule = new GardenSchedule(taskList, plantList);
|
||||
private final WeatherGradenTaskPlanner weatherGradenTaskPlanner = new WeatherGradenTaskPlanner(taskList,plantList,cropList);
|
||||
private final Garden garden = new Garden(gardenSchedule, cropList);
|
||||
|
||||
|
||||
|
||||
@@ -74,11 +74,8 @@ public class WeatherGradenTaskPlanner {
|
||||
Plant plant = plantList.getPlantById(HardinessZone.ZONE_8A,crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
||||
|
||||
// nur für aktuelle growthphase
|
||||
for (GrowthPhase growthphase : plant.lifecycle()) {
|
||||
|
||||
if(growthphase.wateringCycle().litersPerSqM() < rainAmount){
|
||||
adjustNextExecutionOfWateringTask(taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(7)));
|
||||
}
|
||||
if(plant.wateringCycle().litersPerSqM() < rainAmount){
|
||||
adjustNextExecutionOfWateringTask(taskList.getTaskList(LocalDate.now(), LocalDate.now().plusDays(7)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,16 +49,13 @@ public class GardenSchedule {
|
||||
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
|
||||
Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
||||
int growPhaseGroup = plant.getGrowphaseGroupForDate(crop.getStartDate());
|
||||
addTask(new Task("watering Task", "pour water over the plant circa : "+ plant.wateringCycle().litersPerSqM() +" per square meter",
|
||||
crop.getStartDate(), crop.getStartDate().plusDays(plant.timeToHarvest(0)),
|
||||
plant.wateringCycle().interval(), crop.getCropId().orElse(0L)));
|
||||
|
||||
for (GrowthPhase growthPhase : plant.lifecycleForGroup(growPhaseGroup)) {
|
||||
for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) {
|
||||
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
|
||||
|
||||
}
|
||||
//TODO add wateringtask
|
||||
if(growthPhase.wateringCycle() != null){
|
||||
addTask(new Task("watering Task", "pour water over the plant circa : "+ growthPhase.wateringCycle().litersPerSqM() +" per square meter",
|
||||
growthPhase.startDate().atYear(LocalDate.now().getYear()), growthPhase.endDate().atYear(LocalDate.now().getYear()),
|
||||
growthPhase.wateringCycle().interval(), crop.getCropId().orElse(0L)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package ch.zhaw.gartenverwaltung.types;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -12,7 +12,6 @@ public record GrowthPhase(
|
||||
MonthDay startDate,
|
||||
MonthDay endDate,
|
||||
int group,
|
||||
WateringCycle wateringCycle,
|
||||
@JsonDeserialize(using = GrowthPhaseTypeDeserializer.class) GrowthPhaseType type,
|
||||
@JsonDeserialize(using = HardinessZoneDeserializer.class) HardinessZone zone,
|
||||
List<TaskTemplate> taskTemplates) {
|
||||
|
||||
@@ -18,6 +18,7 @@ public record Plant(
|
||||
int light,
|
||||
String soil,
|
||||
List<Pest> pests,
|
||||
WateringCycle wateringCycle,
|
||||
List<GrowthPhase> lifecycle) {
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user