[Racket] Ferti hydroponic nutrient solver, redux.
Add get-sorted-nutrient-values helper.
Changed files
models/nutrient-value.rkt
@@ -5,12 +5,15 @@
5
5
nutrient-value-hash/c
6
6
(contract-out [insert-nutrient-values
7
7
(-> connection? db-id? nutrient-value-hash/c (listof (cons/c symbol? any/c)))]
8
Added:
[get-sorted-nutrient-values
9
Added:
(-> nutrient-value-hash/c (listof (cons/c nutrient? nutrient-value?)))]
8
10
[update-nutrient-values! (-> connection? db-id? nutrient-value-hash/c void?)]
9
11
[residuals->nutrient-value-hash
10
12
(-> (listof residual-vector/c) nutrient-value-hash/c)]))
11
13
12
14
(require db
13
15
sql
16
Added:
racket/hash
14
17
"nutrient.rkt"
15
18
"utils.rkt")
16
19
@@ -33,6 +36,9 @@
33
36
value_ppm
34
37
#:from (TableExpr:AST ,(make-values*-table-expr-ast nv-rows)))))
35
38
(simple-result-info result))
39
Added:
40
Added:
(define (get-sorted-nutrient-values nv)
41
Added:
(sort (hash->list (hash-filter-values nv positive?)) > #:key cdr))
36
42
37
43
(define (update-nutrient-values! conn nvs-id nutrient-values)
38
44
(for ([(n v) (in-hash nutrient-values)])
views.rkt
@@ -17,10 +17,10 @@
17
17
18
18
(require gregor
19
19
web-server/formlets
20
Removed:
racket/hash
21
20
"formlets.rkt"
22
21
"models/user.rkt"
23
22
"models/nutrient.rkt"
23
Added:
"models/nutrient-value.rkt"
24
24
"models/nutrient-measurement.rkt"
25
25
"models/crop.rkt"
26
26
"models/crop-rotation.rkt"
@@ -257,8 +257,7 @@
257
257
(define (show-fertilizer-page fp)
258
258
(define product-name (fertilizer-product-name fp))
259
259
(define brand-name (fertilizer-brand-name fp))
260
Removed:
(define positive-nutrient-values (hash-filter-values (fertilizer-product-values fp) positive?))
261
Removed:
(define sorted-nutrient-values (sort (hash->list positive-nutrient-values) > #:key cdr))
260
Added:
(define sorted-nutrient-values (get-sorted-nutrient-values (fertilizer-product-values fp)))
262
261
(define table
263
262
`(table ((class "table"))
264
263
(thead (tr (th "Nutriment") (th ((class "text-end")) "Concentration (mg/L)")))