summaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authorMarius Peter <dev@marius-peter.com>2025-11-30 11:11:09 +0100
committerMarius Peter <dev@marius-peter.com>2025-11-30 11:11:09 +0100
commit355bbfd898a8b61797b3a077f15c5f97ab7ebb04 (patch)
treef4d64c5db18d04dec249eb939ede834148a26acc /models
parentd70e4dc1318d461d4da9fec5b5c1aa73a299f23c (diff)
Add contracts related to nutrient-value.
Diffstat (limited to 'models')
-rw-r--r--models/crop-requirement.rkt25
-rw-r--r--models/fertilizer-product.rkt3
-rw-r--r--models/nutrient-measurement.rkt7
-rw-r--r--models/nutrient-target.rkt4
-rw-r--r--models/nutrient.rkt6
5 files changed, 24 insertions, 21 deletions
diff --git a/models/crop-requirement.rkt b/models/crop-requirement.rkt
index e26f1dc..4176ae4 100644
--- a/models/crop-requirement.rkt
+++ b/models/crop-requirement.rkt
@@ -6,20 +6,17 @@
crop-requirement-profile
crop-requirement-crop-id
(rename-out [crop-requirement-nutrient-values crop-requirement-values])
- (contract-out [create-crop-requirement!
- (->* (string? nutrient-value-hash/c) ((or/c #f crop?)) crop-requirement?)]
- [get-crop-requirements (-> (listof crop-requirement?))]
- [get-crop-requirement
- (->* ()
- (#:id (or/c #f exact-nonnegative-integer?) #:profile (or/c #f string?))
- (or/c crop-requirement? #f))]
- [get-crop-requirement-values
- (-> crop-requirement-or-id/c nutrient-value-hash/c)]
- [get-crop-requirement-value (-> crop-requirement-or-id/c nutrient? number?)]
- [delete-crop-requirement! (-> crop-requirement-or-id/c void?)]
- [average-crop-requirement-nutrient-values
- (-> (listof (cons/c crop-requirement? (and/c real? (>=/c 0) (<=/c 100))))
- nutrient-value-hash/c)]))
+ (contract-out
+ [create-crop-requirement! (->* (string? nutrient-value-hash/c) (crop?) crop-requirement?)]
+ [get-crop-requirements (-> (listof crop-requirement?))]
+ [get-crop-requirement
+ (->* () (#:id exact-nonnegative-integer? #:profile string?) (or/c crop-requirement? #f))]
+ [get-crop-requirement-values (-> crop-requirement-or-id/c nutrient-value-hash/c)]
+ [get-crop-requirement-value (-> crop-requirement-or-id/c nutrient? maybe-nutrient-value?)]
+ [delete-crop-requirement! (-> crop-requirement-or-id/c void?)]
+ [average-crop-requirement-nutrient-values
+ (-> (listof (cons/c crop-requirement? (and/c real? (>=/c 0) (<=/c 100))))
+ nutrient-value-hash/c)]))
(require racket/contract
db
diff --git a/models/fertilizer-product.rkt b/models/fertilizer-product.rkt
index 5c0de6c..cd86e2e 100644
--- a/models/fertilizer-product.rkt
+++ b/models/fertilizer-product.rkt
@@ -14,7 +14,8 @@
(#:id (or/c #f exact-nonnegative-integer?) #:canonical-name (or/c #f string?))
(or/c fertilizer-product? #f))]
[get-fertilizer-product-values (-> fertilizer-product-or-id/c nutrient-value-hash/c)]
- [get-fertilizer-product-value (-> fertilizer-product-or-id/c nutrient? (or/c #f number?))]
+ [get-fertilizer-product-value
+ (-> fertilizer-product-or-id/c nutrient? maybe-nutrient-value?)]
[delete-fertilizer-product! (-> fertilizer-product-or-id/c void?)]))
(require racket/contract
diff --git a/models/nutrient-measurement.rkt b/models/nutrient-measurement.rkt
index b4baba6..ae0e2ef 100644
--- a/models/nutrient-measurement.rkt
+++ b/models/nutrient-measurement.rkt
@@ -10,11 +10,12 @@
[get-nutrient-measurements (-> (listof nutrient-measurement?))]
[get-nutrient-measurement
(->* ()
- (#:id (or/c #f exact-nonnegative-integer?) #:measured-on (or/c #f string?))
+ (#:id exact-nonnegative-integer? #:measured-on string?)
(or/c nutrient-measurement? #f))]
[get-nutrient-measurement-values (-> nutrient-measurement-or-id/c nutrient-value-hash/c)]
- [get-nutrient-measurement-value (-> nutrient-measurement-or-id/c nutrient? (or/c real? #f))]
- [get-latest-nutrient-measurement-value (-> nutrient? (or/c real? #f))]
+ [get-nutrient-measurement-value
+ (-> nutrient-measurement-or-id/c nutrient? maybe-nutrient-value?)]
+ [get-latest-nutrient-measurement-value (-> nutrient? maybe-nutrient-value?)]
[get-latest-nutrient-measurement-hash (-> nutrient-value-hash/c)]
[delete-nutrient-measurement! (-> nutrient-measurement-or-id/c void?)]))
diff --git a/models/nutrient-target.rkt b/models/nutrient-target.rkt
index 0a117b5..4fd5a10 100644
--- a/models/nutrient-target.rkt
+++ b/models/nutrient-target.rkt
@@ -13,8 +13,8 @@
(#:id (or/c #f exact-nonnegative-integer?) #:effective-on (or/c #f string?))
(or/c nutrient-target? #f))]
[get-nutrient-target-values (-> nutrient-target-or-id/c nutrient-value-hash/c)]
- [get-nutrient-target-value (-> nutrient-target-or-id/c nutrient? (or/c number? #f))]
- [get-latest-nutrient-target-value (-> nutrient? (or/c number? #f))]
+ [get-nutrient-target-value (-> nutrient-target-or-id/c nutrient? maybe-nutrient-value?)]
+ [get-latest-nutrient-target-value (-> nutrient? maybe-nutrient-value?)]
[get-latest-nutrient-target-hash (-> nutrient-value-hash/c)]
[delete-nutrient-target! (-> nutrient-target-or-id/c void?)]))
diff --git a/models/nutrient.rkt b/models/nutrient.rkt
index dd8d677..1103aac 100644
--- a/models/nutrient.rkt
+++ b/models/nutrient.rkt
@@ -6,6 +6,8 @@
nutrient-canonical-name
nutrient-french-name
nutrient-formula
+ nutrient-value?
+ maybe-nutrient-value?
nutrient-value-hash/c
(contract-out [create-nutrient! (-> string? string? string? nutrient?)]
[get-nutrients (-> (listof nutrient?))]
@@ -33,7 +35,9 @@
#:property prop:custom-write
(λ (v out _) (fprintf out "#<~a ~a>" (nutrient-id v) (nutrient-canonical-name v))))
-(define nutrient-value-hash/c (hash/c nutrient? (and/c real? (>=/c 0)) #:immutable #t))
+(define nutrient-value? (and/c real? (>=/c 0)))
+(define maybe-nutrient-value? (or/c nutrient-value? #f))
+(define nutrient-value-hash/c (hash/c nutrient? nutrient-value? #:immutable #t))
;; vector/c id, canonical name, french name, nutrient formula, value (ppm)
(define residual-vector/c (vector/c exact-nonnegative-integer? string? string? string? real?))
Copyright 2019--2026 Marius PETER