utils

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2025 License: AGPL-3.0 Imports: 5 Imported by: 0

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:

  1. Calculates the plant's lifetime in years based on the current year.
  2. 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`.
  3. 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.
  4. 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.

func CheckAndSortWatermarks

func CheckAndSortWatermarks(w []entities.Watermark) (w30, w60, w90 entities.Watermark, err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL