From ad27abde5a5a45f4d1fb9290c8baf71cef7b516f Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sat, 13 Dec 2025 17:01:24 +0100 Subject: Sort fertilizer product values by nutrient quantity. --- views.rkt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'views.rkt') diff --git a/views.rkt b/views.rkt index d89f31d..75018a4 100644 --- a/views.rkt +++ b/views.rkt @@ -242,15 +242,15 @@ (define (show-fertilizer-page fp) (define product-name (fertilizer-product-name fp)) (define brand-name (fertilizer-brand-name fp)) - (define nutrient-values (fertilizer-product-values 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 table `(table ((class "table")) (thead (tr (th "Nutriment") (th ((class "text-end")) "Apport (mg/L)"))) - (tbody ,@(for/list ([(nutrient quantity) (in-hash nutrient-values)] - #:when (not (zero? quantity))) - `(tr (td ,(nutrient-french-name nutrient)) - (td ((class "text-end font-monospace")) ,(round 2 quantity))))))) - + (tbody ,@(for/list ([nv-pair sorted-nutrient-values]) + (match-define (cons n v) nv-pair) + `(tr (td ,(nutrient-french-name n)) + (td ((class "text-end font-monospace")) ,(round 2 v))))))) (page-template product-name `((h1 ((class "display-1 mb-3")) ,(or brand-name "Intrant générique")) (h5 ((class "display-5 mb-3")) ,product-name) -- cgit v1.2.3