implemented Method getGrowphaseGroupForDate
This commit is contained in:
parent
384dc2d853
commit
165dc6d901
|
@ -46,7 +46,8 @@ public class GardenSchedule {
|
|||
*/
|
||||
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
|
||||
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()) {
|
||||
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package ch.zhaw.gartenverwaltung.types;
|
|||
import javafx.scene.image.Image;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.MonthDay;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -39,6 +40,16 @@ public record Plant(
|
|||
.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
|
||||
* @param harvestDate date of the harvest
|
||||
|
|
Loading…
Reference in New Issue