[Racket] Ferti hydroponic nutrient solver, redux.
Sort fertilizer product values by nutrient quantity.
views.rkt
@@ -242,15 +242,15 @@
242
242
(define (show-fertilizer-page fp)
243
243
(define product-name (fertilizer-product-name fp))
244
244
(define brand-name (fertilizer-brand-name fp))
245
Removed:
(define nutrient-values (fertilizer-product-values fp))
245
Added:
(define positive-nutrient-values (hash-filter-values (fertilizer-product-values fp) positive?))
246
Added:
(define sorted-nutrient-values (sort (hash->list positive-nutrient-values) > #:key cdr))
246
247
(define table
247
248
`(table ((class "table"))
248
249
(thead (tr (th "Nutriment") (th ((class "text-end")) "Apport (mg/L)")))
249
Removed:
(tbody ,@(for/list ([(nutrient quantity) (in-hash nutrient-values)]
250
Removed:
#:when (not (zero? quantity)))
251
Removed:
`(tr (td ,(nutrient-french-name nutrient))
252
Removed:
(td ((class "text-end font-monospace")) ,(round 2 quantity)))))))
253
Removed:
250
Added:
(tbody ,@(for/list ([nv-pair sorted-nutrient-values])
251
Added:
(match-define (cons n v) nv-pair)
252
Added:
`(tr (td ,(nutrient-french-name n))
253
Added:
(td ((class "text-end font-monospace")) ,(round 2 v)))))))
254
254
(page-template product-name
255
255
`((h1 ((class "display-1 mb-3")) ,(or brand-name "Intrant générique"))
256
256
(h5 ((class "display-5 mb-3")) ,product-name)