summaryrefslogtreecommitdiff
path: root/models/nutrient-target.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'models/nutrient-target.rkt')
-rw-r--r--models/nutrient-target.rkt35
1 files changed, 21 insertions, 14 deletions
diff --git a/models/nutrient-target.rkt b/models/nutrient-target.rkt
index ce4d561..cffa657 100644
--- a/models/nutrient-target.rkt
+++ b/models/nutrient-target.rkt
@@ -32,7 +32,7 @@
(for ([(n v) (in-hash (nutrient-target-nutrient-values v))])
(fprintf out
"~a ~a\n"
- (~a (nutrient-name n) #:min-width 14)
+ (~a (nutrient-canonical-name n) #:min-width 14)
(~a v #:max-width 6 #:align 'right)))))
;; CREATE
@@ -78,6 +78,7 @@
nt.effective_on
n.id
n.canonical_name
+ n.french_name
n.formula
nv.value_ppm
#:from (TableExpr:AST ,joined)
@@ -100,6 +101,7 @@
nt.effective_on
n.id
n.canonical_name
+ n.french_name
n.formula
nv.value_ppm
#:from (TableExpr:AST ,joined)
@@ -113,15 +115,16 @@
[many (error 'get-nutrient-target "expected 1 nutrient target, got ~a" (length many))]))
(define (get-nutrient-target-values nutrient-target)
- (for/hash ([(nutrient-id name formula value_ppm)
+ (for/hash ([(nutrient-id canonical-name french-name formula value_ppm)
(in-query (current-conn)
(select n.id
n.canonical_name
+ n.french_name
n.formula
nv.value_ppm
#:from (TableExpr:AST ,joined)
#:where (= nt.id ,(nutrient-target-id nutrient-target))))])
- (values (nutrient nutrient-id name formula) value_ppm)))
+ (values (nutrient nutrient-id canonical-name french-name formula) value_ppm)))
(define (get-nutrient-target-value nutrient-target nutrient)
(query-maybe-value (current-conn)
@@ -140,19 +143,23 @@
#:limit 1)))
(define (get-latest-nutrient-target-hash)
- (for/hash ([(n-id n-name n-formula residual-rows) (in-query (current-conn)
- (select n.id
- n.canonical_name
- n.formula
- nt.effective_on
- nv.value_ppm
- #:from (TableExpr:AST ,joined)
- #:order-by nt.effective_on
- #:desc)
- #:group '(#(0 1 2)))])
+ (define grouped-rows
+ (query-rows (current-conn)
+ (select n.id
+ n.canonical_name
+ n.french_name
+ n.formula
+ nt.effective_on
+ nv.value_ppm
+ #:from (TableExpr:AST ,joined)
+ #:order-by nt.effective_on
+ #:desc)
+ #:group '(#(0 1 2 3))))
+ (for/hash ([row grouped-rows])
+ (match-define (vector n-id n-canonical-name n-french-name n-formula residual-rows) row)
;; residual-rows is a non-empty list of vectors: #(effective_on value_ppm)
(match-define (vector _effective-on value-ppm) (first residual-rows))
- (values (nutrient n-id n-name n-formula) value-ppm)))
+ (values (nutrient n-id n-canonical-name n-french-name n-formula) value-ppm)))
;; UPDATE
Copyright 2019--2026 Marius PETER