implemented Method getGrowphaseGroupForDate

This commit is contained in:
schrom01 2022-11-18 12:21:21 +01:00
parent 384dc2d853
commit 165dc6d901
2 changed files with 13 additions and 1 deletions

View File

@ -46,7 +46,8 @@ public class GardenSchedule {
*/ */
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException { public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new); Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
for (GrowthPhase growthPhase : plant.lifecycle()) { int growPhaseGroup = plant.getGrowphaseGroupForDate(crop.getStartDate());
for (GrowthPhase growthPhase : plant.lifecycleForGroup(growPhaseGroup)) {
for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) { for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) {
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L))); addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
} }

View File

@ -3,6 +3,7 @@ package ch.zhaw.gartenverwaltung.types;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.MonthDay;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -39,6 +40,16 @@ public record Plant(
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public int getGrowphaseGroupForDate(LocalDate date) {
for(GrowthPhase growthPhase : lifecycle){
MonthDay plantingDate = MonthDay.of(date.getMonth().getValue(), date.getDayOfMonth());
if(plantingDate.isAfter(growthPhase.startDate()) && plantingDate.isBefore(growthPhase.endDate())){
return growthPhase.group();
}
}
return 0; // TODO implement
}
/** /**
* get sow date from given harvest day from lifecycle group * get sow date from given harvest day from lifecycle group
* @param harvestDate date of the harvest * @param harvestDate date of the harvest