summaryrefslogtreecommitdiff
path: root/models/nutrient.rkt
diff options
context:
space:
mode:
authorMarius Peter <dev@marius-peter.com>2025-11-20 14:08:21 +0100
committerMarius Peter <dev@marius-peter.com>2025-11-20 14:08:21 +0100
commitd2b7a6a7e2739869f8b718c80cad7c9515f10070 (patch)
treed3e8ac04dc4d1178fe24bc0511ada49caadf25db /models/nutrient.rkt
parent434b521ddb70287b55d1dc8f5e24f18aeaa01fdc (diff)
Replace nutrient-value alists with hashes everywhere.
Diffstat (limited to 'models/nutrient.rkt')
-rw-r--r--models/nutrient.rkt16
1 files changed, 13 insertions, 3 deletions
diff --git a/models/nutrient.rkt b/models/nutrient.rkt
index 91be68f..d79801f 100644
--- a/models/nutrient.rkt
+++ b/models/nutrient.rkt
@@ -5,7 +5,7 @@
nutrient-id
nutrient-name
nutrient-formula
- nutrient-value-pair/c
+ nutrient-value-hash/c
(contract-out [create-nutrient! (-> string? string? nutrient?)]
[get-nutrients (-> (listof nutrient?))]
[get-nutrient
@@ -18,7 +18,9 @@
(->* (nutrient?)
(#:name (or/c #f string?) #:formula (or/c #f string?))
(or/c nutrient? #f))]
- [delete-nutrient! (-> nutrient? void?)]))
+ [delete-nutrient! (-> nutrient? void?)]
+ [residuals->nutrient-value-hash
+ (-> (listof residual-vector/c) nutrient-value-hash/c)]))
(require racket/contract
db
@@ -30,7 +32,15 @@
#:property prop:custom-write
(λ (v out _) (fprintf out "#<~a ~a>" (nutrient-id v) (nutrient-name v))))
-(define nutrient-value-pair/c (cons/c nutrient? (and/c real? (>=/c 0))))
+(define nutrient-value-hash/c (hash/c nutrient? (and/c real? (>=/c 0)) #:immutable #t))
+
+;; vector/c id, nutrient name, nutrient formula, value (ppm)
+(define residual-vector/c (vector/c exact-nonnegative-integer? string? string? real?))
+
+(define (residuals->nutrient-value-hash residuals)
+ (for/hash ([r (in-list residuals)])
+ (match-define (vector n-id n-name n-formula value-ppm) r)
+ (values (nutrient n-id n-name n-formula) value-ppm)))
;; CREATE
Copyright 2019--2026 Marius PETER