filtering lifecycle based on hardiness-zone
- Added 2 more plants to test db - Db filters plant lifecycles based on hardiness-zones - getPlantById implemented - Added methods to Plant for calculating sowDates and accounting for multiple lifecycles
This commit is contained in:
parent
bf4d56e759
commit
429ac16d98
|
@ -34,12 +34,17 @@ public class JsonPlantDatabase implements PlantDatabase {
|
||||||
|
|
||||||
result = mapper.readerForListOf(Plant.class).readValue(dataSource);
|
result = mapper.readerForListOf(Plant.class).readValue(dataSource);
|
||||||
}
|
}
|
||||||
|
for (Plant plant : result) {
|
||||||
|
plant.inZone(zone);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Plant> getPlantById(long id) {
|
public Optional<Plant> getPlantById(long id, HardinessZone zone) throws IOException {
|
||||||
return Optional.empty();
|
return getPlantList(zone).stream()
|
||||||
|
.filter(plant -> plant.id() != id)
|
||||||
|
.findFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,5 @@ import java.util.Optional;
|
||||||
|
|
||||||
public interface PlantDatabase {
|
public interface PlantDatabase {
|
||||||
List<Plant> getPlantList(HardinessZone zone) throws IOException;
|
List<Plant> getPlantList(HardinessZone zone) throws IOException;
|
||||||
Optional<Plant> getPlantById(long id) throws IOException;
|
Optional<Plant> getPlantById(long id, HardinessZone zone) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,46 @@
|
||||||
package ch.zhaw.gartenverwaltung.types;
|
package ch.zhaw.gartenverwaltung.types;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.time.temporal.ChronoUnit.DAYS;
|
||||||
|
|
||||||
public record Plant(
|
public record Plant(
|
||||||
long id,
|
long id,
|
||||||
String name,
|
String name,
|
||||||
String description,
|
String description,
|
||||||
int spacing,
|
String spacing,
|
||||||
int light,
|
int light,
|
||||||
String soil,
|
String soil,
|
||||||
List<Object> pests,
|
List<Object> pests,
|
||||||
List<GrowthPhase> lifecycle) {
|
List<GrowthPhase> lifecycle) {
|
||||||
|
|
||||||
|
public void inZone(HardinessZone zone) {
|
||||||
|
lifecycle.removeIf(growthPhase -> !growthPhase.zone().equals(zone));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrowthPhase> lifecycleForGroup(int group) {
|
||||||
|
return lifecycle.stream()
|
||||||
|
.filter(growthPhase -> growthPhase.group() != group)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate sowDateFromHarvestDate(LocalDate harvestDate, int group) {
|
||||||
|
return harvestDate.minusDays(timeToHarvest(group));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int timeToHarvest(int group) {
|
||||||
|
List<GrowthPhase> activeLifecycle = lifecycleForGroup(group);
|
||||||
|
GrowthPhase sow = activeLifecycle.stream()
|
||||||
|
.filter(growthPhase -> !growthPhase.type().equals(GrowthPhaseType.SOW))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow();
|
||||||
|
GrowthPhase harvest = activeLifecycle.stream()
|
||||||
|
.filter(growthPhase -> !growthPhase.type().equals(GrowthPhaseType.HARVEST))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow();
|
||||||
|
|
||||||
|
int currentYear = LocalDate.now().getYear();
|
||||||
|
return (int) DAYS.between(harvest.startDate().atYear(currentYear), sow.startDate().atYear(currentYear));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,5 +81,174 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Early Carrot",
|
||||||
|
"description": "Carrot, (Daucus carota), herbaceous, generally biennial plant of the Apiaceae family that produces an edible taproot. Among common varieties root shapes range from globular to long, with lower ends blunt to pointed. Besides the orange-coloured roots, white-, yellow-, and purple-fleshed varieties are known.",
|
||||||
|
"lifecycle": [
|
||||||
|
{
|
||||||
|
"startDate": "02-20",
|
||||||
|
"endDate": "03-10",
|
||||||
|
"zone": "ZONE_8A",
|
||||||
|
"type": "SOW",
|
||||||
|
"wateringCycle": {
|
||||||
|
"litersPerSqM": 15,
|
||||||
|
"interval": 3,
|
||||||
|
"notes": []
|
||||||
|
},
|
||||||
|
"taskTemplates": [
|
||||||
|
{
|
||||||
|
"name": "hilling",
|
||||||
|
"relativeStartDate": 0,
|
||||||
|
"relativeEndDate": 0,
|
||||||
|
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||||
|
"interval": null,
|
||||||
|
"isOptional": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startDate": "03-10",
|
||||||
|
"endDate": "05-10",
|
||||||
|
"zone": "ZONE_8A",
|
||||||
|
"type": "PLANT",
|
||||||
|
"wateringCycle": {
|
||||||
|
"litersPerSqM": 25,
|
||||||
|
"interval": 3,
|
||||||
|
"notes": [
|
||||||
|
"Be careful not to pour water over the leaves, as this will lead to sunburn."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"taskTemplates": [
|
||||||
|
{
|
||||||
|
"name": "hilling",
|
||||||
|
"relativeStartDate": 0,
|
||||||
|
"relativeEndDate": null,
|
||||||
|
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||||
|
"interval": 15,
|
||||||
|
"isOptional": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startDate": "05-10",
|
||||||
|
"endDate": "05-20",
|
||||||
|
"zone": "ZONE_8A",
|
||||||
|
"type": "HARVEST",
|
||||||
|
"wateringCycle": {
|
||||||
|
"litersPerSqM": 0,
|
||||||
|
"interval": null,
|
||||||
|
"notes": []
|
||||||
|
},
|
||||||
|
"taskTemplates": [
|
||||||
|
{
|
||||||
|
"name": "Harvesting",
|
||||||
|
"relativeStartDate": 0,
|
||||||
|
"relativeEndDate": 14,
|
||||||
|
"description": "When the leaves turn to a yellowish brown. Do not harvest earlier. The plant will show when it's ready.",
|
||||||
|
"interval": null,
|
||||||
|
"isOptional": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"soil": "sandy to loamy, loose soil, free of stones",
|
||||||
|
"spacing": "5,35,2.5",
|
||||||
|
"pests": [
|
||||||
|
{
|
||||||
|
"name": "Rot",
|
||||||
|
"description": "rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.",
|
||||||
|
"measurement": "less water"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "summertime onion",
|
||||||
|
"description": "Onion, (Allium cepa), herbaceous biennial plant in the amaryllis family (Amaryllidaceae) grown for its edible bulb. The onion is likely native to southwestern Asia but is now grown throughout the world, chiefly in the temperate zones. Onions are low in nutrients but are valued for their flavour and are used widely in cooking. They add flavour to such dishes as stews, roasts, soups, and salads and are also served as a cooked vegetable.",
|
||||||
|
"lifecycle": [
|
||||||
|
{
|
||||||
|
"startDate": "03-15",
|
||||||
|
"endDate": "04-10",
|
||||||
|
"type": "SOW",
|
||||||
|
"zone": "ZONE_8A",
|
||||||
|
"group": 0,
|
||||||
|
"wateringCycle": {
|
||||||
|
"litersPerSqM": 15,
|
||||||
|
"interval": 4,
|
||||||
|
"notes": [
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"taskTemplates": [
|
||||||
|
{
|
||||||
|
"name": "hilling",
|
||||||
|
"relativeStartDate": 0,
|
||||||
|
"relativeEndDate": 0,
|
||||||
|
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||||
|
"interval": null,
|
||||||
|
"isOptional": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startDate": "04-10",
|
||||||
|
"endDate": "07-10",
|
||||||
|
"type": "PLANT",
|
||||||
|
"zone": "ZONE_8A",
|
||||||
|
"group": 0,
|
||||||
|
"wateringCycle": {
|
||||||
|
"litersPerSqM": 25,
|
||||||
|
"interval": 3,
|
||||||
|
"notes": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"taskTemplates": [
|
||||||
|
{
|
||||||
|
"name": "hilling",
|
||||||
|
"relativeStartDate": 0,
|
||||||
|
"relativeEndDate": null,
|
||||||
|
"description": "Mound up the soil around the plant until just the top few leaves show above the soil. ",
|
||||||
|
"interval": 15,
|
||||||
|
"isOptional": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startDate": "07-10",
|
||||||
|
"endDate": "09-20",
|
||||||
|
"type": "HARVEST",
|
||||||
|
"zone": "ZONE_8A",
|
||||||
|
"group": 0,
|
||||||
|
"wateringCycle": {
|
||||||
|
"litersPerSqM": 0,
|
||||||
|
"interval": null,
|
||||||
|
"notes": [
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"taskTemplates": [
|
||||||
|
{
|
||||||
|
"name": "Harvesting",
|
||||||
|
"relativeStartDate": 0,
|
||||||
|
"relativeEndDate": 14,
|
||||||
|
"description": "When ready for harvest, the leaves on your onion plants will start to flop over. This happens at the \"neck\" of the onion and it signals that the plant has stopped growing and is ready for storage. Onions should be harvested soon thereafter",
|
||||||
|
"interval": null,
|
||||||
|
"isOptional": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"soil": "sandy to loamy, loose soil, free of stones",
|
||||||
|
"spacing": "15,30,2",
|
||||||
|
"pests": [
|
||||||
|
{
|
||||||
|
"name": "Rot",
|
||||||
|
"description": "rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.",
|
||||||
|
"measurement": "less water"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
Loading…
Reference in New Issue