aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoris2017-04-05 21:26:31 +0200
committerJoris2017-04-05 21:26:35 +0200
commit28d595fef6d96557c3d318bc63e716dcebba282d (patch)
tree6ece538d3c6094f72cc7f63f1cef3288adb5ad35 /src
parent82f5793b57e923be50e53b6845802fdd30ef947b (diff)
Add glycemic index indicator
Diffstat (limited to 'src')
-rw-r--r--src/Food.purs12
-rw-r--r--src/Indicator.purs19
-rw-r--r--src/Page.purs12
3 files changed, 33 insertions, 10 deletions
diff --git a/src/Food.purs b/src/Food.purs
index b1e3d29..19b667c 100644
--- a/src/Food.purs
+++ b/src/Food.purs
@@ -18,8 +18,12 @@ glycemicLoad aliment = toNumber aliment.glycemicIndex * toNumber aliment.carbohy
all :: Array Aliment
all =
- [ { name: "oignon", glycemicIndex: 15, carbohydrates: 9 }
- , { name: "olive", glycemicIndex: 15, carbohydrates: 6 }
- , { name: "haricot rouge", glycemicIndex: 35, carbohydrates: 24 }
- , { name: "haricot blanc", glycemicIndex: 35, carbohydrates: 13 }
+ [ { name: "oignons", glycemicIndex: 15, carbohydrates: 9 }
+ , { name: "olives", glycemicIndex: 15, carbohydrates: 6 }
+ , { name: "haricots rouges", glycemicIndex: 35, carbohydrates: 24 }
+ , { name: "haricots blancs", glycemicIndex: 35, carbohydrates: 13 }
+ , { name: "pommes de terres (cuites avec leur peau)", glycemicIndex: 70, carbohydrates: 37 }
+ , { name: "lentilles vertes", glycemicIndex: 30, carbohydrates: 30 }
+ , { name: "lentilles corail", glycemicIndex: 21, carbohydrates: 48 }
+ , { name: "riz basmatti", glycemicIndex: 58, carbohydrates: 25 }
]
diff --git a/src/Indicator.purs b/src/Indicator.purs
new file mode 100644
index 0000000..536133d
--- /dev/null
+++ b/src/Indicator.purs
@@ -0,0 +1,19 @@
+module Indicator
+ ( Indicator(..)
+ , fromGlycemicIndex
+ ) where
+
+import Prelude
+
+data Indicator = Good | Medium | Bad
+
+instance showIndicator :: Show Indicator where
+ show Good = "Good"
+ show Medium = "Medium"
+ show Bad = "Bad"
+
+fromGlycemicIndex :: Int -> Indicator
+fromGlycemicIndex n
+ | n < 40 = Good
+ | n < 55 = Medium
+ | otherwise = Bad
diff --git a/src/Page.purs b/src/Page.purs
index 76cdf8d..07372d2 100644
--- a/src/Page.purs
+++ b/src/Page.purs
@@ -1,5 +1,6 @@
module Page where
+import Data.Array ((:), sortBy)
import Data.Maybe (Maybe(..))
import Halogen as H
import Halogen.HTML as HH
@@ -9,12 +10,11 @@ import Prelude
import Food (Aliment)
import Food as Food
import Format as Format
-
-type State = Unit
+import Indicator as Indicator
data Query a = NoOp a
-
-data Message = Toggled Boolean
+type State = Unit
+type Message = Unit
component :: forall m . H.Component HH.HTML Query State Message m
component =
@@ -32,7 +32,7 @@ component =
[ HH.h1 [] [ HH.text "Glycémie" ]
, HH.ul
[ HP.class_ $ HH.ClassName "aliments" ]
- ([renderTitle] <> (map renderAliment Food.all))
+ (renderTitle : (map renderAliment <<< sortBy (\a b -> compare a.name b.name) $ Food.all))
]
eval :: Query ~> H.ComponentDSL State Query Message m
@@ -65,7 +65,7 @@ renderAliment aliment =
[]
[ HH.text aliment.name ]
, HH.div
- [ HP.class_ $ HH.ClassName "number" ]
+ [ HP.class_ $ HH.ClassName ("number " <> (show $ Indicator.fromGlycemicIndex aliment.glycemicIndex)) ]
[ HH.text (show aliment.glycemicIndex) ]
, HH.div
[ HP.class_ $ HH.ClassName "number" ]