Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateWateringStatus ¶
func CalculateWateringStatus(plantingYear int32, watermarks []entities.Watermark) entities.WateringStatus
CalculateWateringStatus determines the watering status of a plant based on its planting year and sensor watermarks.
Parameters:
- plantingYear: The year the plant was planted.
- watermarks: A slice of entities.Watermark containing sensor readings at different depths.
Returns:
- entities.WateringStatus: The calculated watering status based on the plant's lifetime and sensor watermarks.
Behavior:
- Calculates the plant's lifetime in years based on the current year.
- Validates the watermarks to ensure exactly three readings exist at depths of 30cm, 60cm, and 90cm. If validation fails, logs an error and returns `WateringStatusUnknown`.
- Based on the tree's lifetime, applies specific centibar ranges to the watermarks at different depths: - Year 1: Centibar ranges for 30cm, 60cm, and 90cm are 25–33. - Year 2: Centibar ranges for 30cm are 62–81, while 60cm and 90cm remain 25–33. - Year 3: Centibar ranges for 30cm are 1585–infinity, while 60cm and 90cm are 80–infinity.
- Maps the centibar values to a status (green, yellow, or red) and determines the final watering status based on the most severe status.
Errors:
- If the watermarks are malformed or do not contain exactly three readings at the required depths, logs an error with details and returns `WateringStatusUnknown`.
Example:
plantingYear := 2020 watermarks := []entities.Watermark{ {Depth: 30, Centibar: 28}, {Depth: 60, Centibar: 30}, {Depth: 90, Centibar: 35}, } status := CalculateWateringStatus(plantingYear, watermarks) fmt.Printf("Watering Status: %v\n", status)
Notes:
- The function assumes that watermarks are provided as a slice, where each entry represents a sensor reading at a specific depth.
- Any changes to the mapping of centibar ranges or tree lifetime logic should be reflected here.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.