diff options
| author | Marius Peter <dev@marius-peter.com> | 2025-12-13 22:32:11 +0100 |
|---|---|---|
| committer | Marius Peter <dev@marius-peter.com> | 2025-12-13 22:32:11 +0100 |
| commit | a3863b1c9c685ecaeb7a1d4fdfa443b9a119caed (patch) | |
| tree | 685ce81195093af48bd0172b794a50e7e44822bd /models/nutrient-value.rkt | |
| parent | e4df053522e0f1ae0a8d3abd62dfe52d28e20d45 (diff) | |
Add get-sorted-nutrient-values helper.
Diffstat (limited to 'models/nutrient-value.rkt')
| -rw-r--r-- | models/nutrient-value.rkt | 6 |
1 files changed, 6 insertions, 0 deletions
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 |