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 | |
| parent | e4df053522e0f1ae0a8d3abd62dfe52d28e20d45 (diff) | |
Add get-sorted-nutrient-values helper.
| -rw-r--r-- | models/nutrient-value.rkt | 6 | ||||
| -rw-r--r-- | views.rkt | 5 |
2 files changed, 8 insertions, 3 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 @@ -17,10 +17,10 @@ (require gregor web-server/formlets - racket/hash "formlets.rkt" "models/user.rkt" "models/nutrient.rkt" + "models/nutrient-value.rkt" "models/nutrient-measurement.rkt" "models/crop.rkt" "models/crop-rotation.rkt" @@ -257,8 +257,7 @@ (define (show-fertilizer-page fp) (define product-name (fertilizer-product-name fp)) (define brand-name (fertilizer-brand-name fp)) - (define positive-nutrient-values (hash-filter-values (fertilizer-product-values fp) positive?)) - (define sorted-nutrient-values (sort (hash->list positive-nutrient-values) > #:key cdr)) + (define sorted-nutrient-values (get-sorted-nutrient-values (fertilizer-product-values fp))) (define table `(table ((class "table")) (thead (tr (th "Nutriment") (th ((class "text-end")) "Concentration (mg/L)"))) |