From a3863b1c9c685ecaeb7a1d4fdfa443b9a119caed Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sat, 13 Dec 2025 22:32:11 +0100 Subject: Add get-sorted-nutrient-values helper. --- models/nutrient-value.rkt | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'models/nutrient-value.rkt') diff --git a/models/nutrient-value.rkt b/models/nutrient-value.rkt index 08bcfad..9653c7f 100644 --- a/models/nutrient-value.rkt +++ b/models/nutrient-value.rkt @@ -5,12 +5,15 @@ nutrient-value-hash/c (contract-out [insert-nutrient-values (-> connection? db-id? nutrient-value-hash/c (listof (cons/c symbol? any/c)))] + [get-sorted-nutrient-values + (-> nutrient-value-hash/c (listof (cons/c nutrient? nutrient-value?)))] [update-nutrient-values! (-> connection? db-id? nutrient-value-hash/c void?)] [residuals->nutrient-value-hash (-> (listof residual-vector/c) nutrient-value-hash/c)])) (require db sql + racket/hash "nutrient.rkt" "utils.rkt") @@ -34,6 +37,9 @@ #:from (TableExpr:AST ,(make-values*-table-expr-ast nv-rows))))) (simple-result-info result)) +(define (get-sorted-nutrient-values nv) + (sort (hash->list (hash-filter-values nv positive?)) > #:key cdr)) + (define (update-nutrient-values! conn nvs-id nutrient-values) (for ([(n v) (in-hash nutrient-values)]) (query-exec conn -- cgit v1.2.3