diff options
| author | Marius Peter <dev@marius-peter.com> | 2025-12-06 17:44:46 +0100 |
|---|---|---|
| committer | Marius Peter <dev@marius-peter.com> | 2025-12-06 17:50:39 +0100 |
| commit | c7ec194f4a6c3dc879c24d8075bfe05a7687f976 (patch) | |
| tree | ba2ed86e217d32cdb5f561c1a89610be1eaef139 /models/nutrient.rkt | |
| parent | 92dbc8cba30b5e0f300fb4f98d465b3a0eec16db (diff) | |
Introduce nutrient-value module.
Diffstat (limited to 'models/nutrient.rkt')
| -rw-r--r-- | models/nutrient.rkt | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/models/nutrient.rkt b/models/nutrient.rkt index 4748083..cbf6bb1 100644 --- a/models/nutrient.rkt +++ b/models/nutrient.rkt @@ -6,9 +6,6 @@ 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?))] [get-nutrient @@ -21,32 +18,19 @@ (->* (nutrient?) (#:name (or/c #f string?) #:formula (or/c #f string?)) (or/c nutrient? #f))] - [delete-nutrient! (-> nutrient? void?)] - [residuals->nutrient-value-hash - (-> (listof residual-vector/c) nutrient-value-hash/c)])) + [delete-nutrient! (-> nutrient? void?)])) (require racket/contract db sql - "../db/conn.rkt") + "../db/conn.rkt" + "utils.rkt") (struct nutrient (id canonical-name french-name formula) #:transparent #:property prop:custom-write (λ (v out _) (fprintf out "#<~a ~a>" (nutrient-id v) (nutrient-canonical-name v)))) -(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?)) - -(define (residuals->nutrient-value-hash residuals) - (for/hash ([r (in-list residuals)]) - (match-define (vector n-id n-canonical-name n-french-name n-formula value-ppm) r) - (values (nutrient n-id n-canonical-name n-french-name n-formula) value-ppm))) - ;; CREATE (define (create-nutrient! canonical-name french-name formula) |