diff options
author | Joris | 2017-04-09 00:37:59 +0200 |
---|---|---|
committer | Joris | 2017-04-09 00:37:59 +0200 |
commit | 69be67a67503c0cb80153510083513f92de952bf (patch) | |
tree | 62de654cdcc1efeea25788f9e80d69b4f01a1fab | |
parent | ba548aafb4dcad5d7d69ef85b9b13e852facd31d (diff) |
Add food
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | src/Food.purs | 231 | ||||
-rw-r--r-- | src/Format.purs | 50 | ||||
-rw-r--r-- | src/Indicator.purs | 10 | ||||
-rw-r--r-- | src/Main.purs | 4 | ||||
-rw-r--r-- | src/Page.purs | 16 |
6 files changed, 296 insertions, 23 deletions
@@ -25,3 +25,11 @@ Later, stop the environment with: ```sh ./make stop ``` + +Sources +------- + +- http://www.aprifel.com/fiche-nutri-composant-glucides,6.html +- http://www.aly-abbara.com/livre_gyn_obs/termes/diabete/index_glycemique.html#glucides +- http://www.montignac.com/fr/rechercher-l-index-glycemique-d-un-aliment/ +- http://www.monmenu.fr/ diff --git a/src/Food.purs b/src/Food.purs index 50e1309..9253959 100644 --- a/src/Food.purs +++ b/src/Food.purs @@ -13,17 +13,232 @@ type Aliment = , carbohydrates :: Int -- for 100 grams } +-- let @a = 'I , { name: "A", glycemicIndex: TDTf Xdf i, carbohydrates: f XL }t^' + glycemicLoad :: Aliment -> Number glycemicLoad aliment = toNumber aliment.glycemicIndex * toNumber aliment.carbohydrates / 100.0 all :: Array Aliment all = - [ { 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 basmati", glycemicIndex: 58, carbohydrates: 25 } + [ { name: "Abricot", glycemicIndex: 30, carbohydrates: 10 } + , { name: "Abricot séché", glycemicIndex: 35, carbohydrates: 34 } + , { name: "Ail", glycemicIndex: 30, carbohydrates: 25 } + , { name: "Amande", glycemicIndex: 15, carbohydrates: 17 } + , { name: "Amande en poudre", glycemicIndex: 20, carbohydrates: 17 } + , { name: "Ananas", glycemicIndex: 45, carbohydrates: 12 } + , { name: "Artichaut", glycemicIndex: 15, carbohydrates: 1 } + , { name: "Asperge", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Aubergine", glycemicIndex: 20, carbohydrates: 3 } + , { name: "Avocat", glycemicIndex: 10, carbohydrates: 4 } + + , { name: "Bambou pousses", glycemicIndex: 20, carbohydrates: 6 } + , { name: "Banane", glycemicIndex: 60, carbohydrates: 22 } + , { name: "Betterave crue", glycemicIndex: 30, carbohydrates: 9 } + , { name: "Betterave cuite", glycemicIndex: 65, carbohydrates: 7 } + -- , { name: "Blé (farine blanche)", glycemicIndex: 77, carbohydrates: 76 } + -- , { name: "Blé (farine complète)", glycemicIndex: 40, carbohydrates: 73 } + , { name: "Boulghour", glycemicIndex: 55, carbohydrates: 20 } + , { name: "Brocoli", glycemicIndex: 15, carbohydrates: 5 } + , { name: "Brugnon", glycemicIndex: 35, carbohydrates: 14 } + + , { name: "Cacahuète", glycemicIndex: 15, carbohydrates: 11 } + , { name: "Cacao en poudre", glycemicIndex: 20, carbohydrates: 25 } + , { name: "Canneloni", glycemicIndex: 55, carbohydrates: 10 } + , { name: "Carotte crue", glycemicIndex: 20, carbohydrates: 5 } + , { name: "Carotte cuite", glycemicIndex: 35, carbohydrates: 5 } + , { name: "Céleri branche", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Céleri-rave", glycemicIndex: 35, carbohydrates: 3 } + , { name: "Céleri-rave rapé", glycemicIndex: 20, carbohydrates: 6 } + , { name: "Cêpes", glycemicIndex: 15, carbohydrates: 4 } + , { name: "Cerise", glycemicIndex: 25, carbohydrates: 16 } + , { name: "Cerneaux de noix", glycemicIndex: 15, carbohydrates: 11 } + , { name: "Champignon", glycemicIndex: 0, carbohydrates: 1 } + , { name: "Chataigne grillée", glycemicIndex: 60, carbohydrates: 42 } + + , { name: "Choux blanc", glycemicIndex: 15, carbohydrates: 4 } + , { name: "Choux chinois", glycemicIndex: 15, carbohydrates: 1 } + , { name: "Choux de bruxelles", glycemicIndex: 15, carbohydrates: 3 } + , { name: "Choux fleur", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Choux romanesco", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Choux rouge", glycemicIndex: 15, carbohydrates: 7 } + , { name: "Choux vert", glycemicIndex: 15, carbohydrates: 1 } + , { name: "citron", glycemicIndex: 20, carbohydrates: 3 } + , { name: "Citron vert", glycemicIndex: 20, carbohydrates: 7 } + , { name: "Citrouille", glycemicIndex: 80, carbohydrates: 6 } + , { name: "Clémentine", glycemicIndex: 30, carbohydrates: 9 } + , { name: "Coeur de palmier", glycemicIndex: 20, carbohydrates: 11 } + , { name: "Coing", glycemicIndex: 35, carbohydrates: 14 } + , { name: "Compote pomme", glycemicIndex: 35, carbohydrates: 18 } + , { name: "Concombre", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Confiture de fruit", glycemicIndex: 65, carbohydrates: 60 } + , { name: "Coquillettes", glycemicIndex: 55, carbohydrates: 13 } + , { name: "Cornichon", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Coulis de tomate", glycemicIndex: 30, carbohydrates: 5 } + , { name: "Courgette", glycemicIndex: 15, carbohydrates: 3 } + , { name: "Cresson", glycemicIndex: 15, carbohydrates: 2 } + + , { name: "Dattes", glycemicIndex: 70, carbohydrates: 73 } + + , { name: "Echalote", glycemicIndex: 15, carbohydrates: 7 } + , { name: "Endive", glycemicIndex: 15, carbohydrates: 4 } + , { name: "Épinard", glycemicIndex: 15, carbohydrates: 3 } + + + , { name: "Faisselle 0%", glycemicIndex: 30, carbohydrates: 4 } + , { name: "Faisselle 40%", glycemicIndex: 30, carbohydrates: 3 } + + , { name: "Farine de blé", glycemicIndex: 85, carbohydrates: 71 } + , { name: "Farine de blé à levure incorporée", glycemicIndex: 85, carbohydrates: 71 } + , { name: "Farine de blé complète T130", glycemicIndex: 45, carbohydrates: 64 } + , { name: "Farine de blé intégrale T150", glycemicIndex: 45, carbohydrates: 64 } + , { name: "Farine de maïs", glycemicIndex: 85, carbohydrates: 85 } + , { name: "Farine de quinoa", glycemicIndex: 40, carbohydrates: 64 } + , { name: "Farine de riz", glycemicIndex: 95, carbohydrates: 85 } + , { name: "Farine de seigle complète T130", glycemicIndex: 45, carbohydrates: 59 } + , { name: "Farine de seigle intégraile T150", glycemicIndex: 45, carbohydrates: 59 } + , { name: "Fécule de maïs", glycemicIndex: 85, carbohydrates: 88 } + , { name: "Fenouil", glycemicIndex: 15, carbohydrates: 5 } + , { name: "Fève", glycemicIndex: 15, carbohydrates: 14 } + , { name: "Figue Blanche", glycemicIndex: 20, carbohydrates: 19 } + , { name: "Figue noir", glycemicIndex: 35, carbohydrates: 13 } + , { name: "Flageolet", glycemicIndex: 25, carbohydrates: 12 } + , { name: "Flocons d'avoine", glycemicIndex: 40, carbohydrates: 62 } + , { name: "Fraise", glycemicIndex: 25, carbohydrates: 7 } + , { name: "Framboise", glycemicIndex: 25, carbohydrates: 8 } + , { name: "Frites maison", glycemicIndex: 95, carbohydrates: 52 } + , { name: "Fromage blanc", glycemicIndex: 30, carbohydrates: 4 } + , { name: "Fruits rouges", glycemicIndex: 15, carbohydrates: 6 } + + , { name: "Galette de blé noir", glycemicIndex: 40, carbohydrates: 31 } + , { name: "Gnocchi", glycemicIndex: 68, carbohydrates: 32 } + , { name: "Grenade", glycemicIndex: 35, carbohydrates: 13 } + , { name: "Groseilles", glycemicIndex: 25, carbohydrates: 10 } + , { name: "Groseilles à maquereau", glycemicIndex: 25, carbohydrates: 6 } + + , { name: "Haricot beurre", glycemicIndex: 15, carbohydrates: 3 } + , { name: "Haricot blanc", glycemicIndex: 35, carbohydrates: 17 } + , { name: "Haricot mange tout", glycemicIndex: 15, carbohydrates: 7 } + , { name: "Haricot noir", glycemicIndex: 35, carbohydrates: 24 } + , { name: "Haricot rouge", glycemicIndex: 35, carbohydrates: 15 } + , { name: "Haricot vert", glycemicIndex: 30, carbohydrates: 3 } + + , { name: "Jus d'abricot", glycemicIndex: 50, carbohydrates: 14 } + , { name: "Jus d'ananas", glycemicIndex: 50, carbohydrates: 12 } + , { name: "Jus d'orange", glycemicIndex: 45, carbohydrates: 11 } + , { name: "Jus de citron", glycemicIndex: 20, carbohydrates: 9 } + , { name: "Jus de framboise", glycemicIndex: 50, carbohydrates: 11 } + , { name: "Jus de pamplemousse rose", glycemicIndex: 45, carbohydrates: 9 } + , { name: "Jus de pomme", glycemicIndex: 50, carbohydrates: 11 } + , { name: "Jus de pruneaux", glycemicIndex: 55, carbohydrates: 19 } + , { name: "Jus de raisin", glycemicIndex: 55, carbohydrates: 15 } + , { name: "Jus de tomate", glycemicIndex: 35, carbohydrates: 4 } + , { name: "Jus multifruits", glycemicIndex: 50, carbohydrates: 12 } + , { name: "Jus peche", glycemicIndex: 50, carbohydrates: 13 } + + , { name: "Kiwi", glycemicIndex: 50, carbohydrates: 11 } + + , { name: "Lait de coco", glycemicIndex: 40, carbohydrates: 3 } + , { name: "lait demi écrémé", glycemicIndex: 30, carbohydrates: 5 } + , { name: "Lait écrémé", glycemicIndex: 30, carbohydrates: 5 } + , { name: "Lait en poudre", glycemicIndex: 30, carbohydrates: 38 } + , { name: "Lait entier", glycemicIndex: 30, carbohydrates: 5 } + , { name: "Lentilles cuites", glycemicIndex: 20, carbohydrates: 16 } + , { name: "Levure chimique sachet", glycemicIndex: 35, carbohydrates: 19 } + , { name: "Litchi", glycemicIndex: 50, carbohydrates: 17 } + + , { name: "Maïs", glycemicIndex: 70, carbohydrates: 19 } + , { name: "Maïzena", glycemicIndex: 70, carbohydrates: 70 } + , { name: "Mandarine", glycemicIndex: 30, carbohydrates: 9 } + , { name: "Mangue", glycemicIndex: 50, carbohydrates: 15 } + , { name: "Mélange noix", glycemicIndex: 15, carbohydrates: 24 } + , { name: "Melon", glycemicIndex: 60, carbohydrates: 8 } + , { name: "Miel", glycemicIndex: 90, carbohydrates: 86 } + , { name: "Muesli Bjorg", glycemicIndex: 20, carbohydrates: 61 } + , { name: "Mulet", glycemicIndex: 15, carbohydrates: 1 } + , { name: "Mûre", glycemicIndex: 25, carbohydrates: 12 } + , { name: "Myrtilles", glycemicIndex: 25, carbohydrates: 11 } + + , { name: "Navet", glycemicIndex: 70, carbohydrates: 7 } + , { name: "Nectar d'abricot", glycemicIndex: 50, carbohydrates: 13 } + , { name: "Nectar de banane", glycemicIndex: 50, carbohydrates: 10 } + , { name: "Nectar de goyave", glycemicIndex: 50, carbohydrates: 10 } + , { name: "Nectar de mangue", glycemicIndex: 50, carbohydrates: 12 } + , { name: "Nectarine", glycemicIndex: 35, carbohydrates: 13 } + + , { name: "Noix de cajou", glycemicIndex: 15, carbohydrates: 21 } + , { name: "Noix de coco", glycemicIndex: 35, carbohydrates: 10 } + , { name: "Noix de coco râpée", glycemicIndex: 35, carbohydrates: 12 } + , { name: "Noix de macadamia", glycemicIndex: 15, carbohydrates: 13 } + , { name: "Noix de pecan", glycemicIndex: 15, carbohydrates: 14 } + + , { name: "Olive verte", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Olives noires", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Orange", glycemicIndex: 30, carbohydrates: 9 } + + , { name: "Pain", glycemicIndex: 70, carbohydrates: 56 } + , { name: "Pain à Hamburger", glycemicIndex: 85, carbohydrates: 50 } + , { name: "Pain au seigle", glycemicIndex: 65, carbohydrates: 50 } + , { name: "pain aux céréales", glycemicIndex: 65, carbohydrates: 55 } + , { name: "Pain aux raisins", glycemicIndex: 70, carbohydrates: 46 } + , { name: "Pain chocolat", glycemicIndex: 65, carbohydrates: 33 } + , { name: "Pain complet", glycemicIndex: 65, carbohydrates: 44 } + , { name: "pain hamburger complet", glycemicIndex: 20, carbohydrates: 48 } + , { name: "Pastèque", glycemicIndex: 75, carbohydrates: 7 } + , { name: "Pâte", glycemicIndex: 70, carbohydrates: 20 } + , { name: "Pâte de fruit", glycemicIndex: 70, carbohydrates: 53 } + , { name: "Petit pois", glycemicIndex: 35, carbohydrates: 11 } + , { name: "Physalis", glycemicIndex: 25, carbohydrates: 6 } + , { name: "Pissenlit", glycemicIndex: 15, carbohydrates: 6 } + , { name: "Pistache", glycemicIndex: 15, carbohydrates: 15 } + , { name: "Poire", glycemicIndex: 30, carbohydrates: 14 } + , { name: "Poireau", glycemicIndex: 15, carbohydrates: 3 } + , { name: "Pois chiches bouillis", glycemicIndex: 30, carbohydrates: 28 } + , { name: "Pois chiches", glycemicIndex: 30, carbohydrates: 19 } + , { name: "Poivron", glycemicIndex: 15, carbohydrates: 4 } + , { name: "Pomme", glycemicIndex: 35, carbohydrates: 19 } + , { name: "Pomme de terre au four", glycemicIndex: 95, carbohydrates: 23 } + , { name: "Pommes de terre", glycemicIndex: 65, carbohydrates: 19 } + , { name: "Potimarron", glycemicIndex: 80, carbohydrates: 6 } + , { name: "Potiron", glycemicIndex: 80, carbohydrates: 5 } + , { name: "Pulpe Tomate", glycemicIndex: 30, carbohydrates: 4 } + + , { name: "Raisin", glycemicIndex: 40, carbohydrates: 16 } + , { name: "Raisin sec", glycemicIndex: 65, carbohydrates: 75 } + , { name: "Rhubarbe", glycemicIndex: 15, carbohydrates: 3 } + , { name: "Riz complet cuit à la vapeur", glycemicIndex: 50, carbohydrates: 24 } + , { name: "Riz complet cuit dans un excès d'eau pendant 25 minutes", glycemicIndex: 72, carbohydrates: 24 } + , { name: "Riz blanc", glycemicIndex: 83, carbohydrates: 29 } + , { name: "Riz basmati blanc", glycemicIndex: 58, carbohydrates: 26 } + , { name: "Riz basmati complet", glycemicIndex: 45, carbohydrates: 21 } + , { name: "Riz inca (Quinoa)", glycemicIndex: 53, carbohydrates: 21 } + , { name: "Riz sauvage", glycemicIndex: 57, carbohydrates: 29 } + + , { name: "Salade", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Salade feuille de chêne", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Salade frisée", glycemicIndex: 15, carbohydrates: 1 } + , { name: "Salade laitue", glycemicIndex: 15, carbohydrates: 2 } + , { name: "Salade mache", glycemicIndex: 15, carbohydrates: 1 } + , { name: "Salade mesclun", glycemicIndex: 15, carbohydrates: 2 } + , { name: "salade roquette", glycemicIndex: 15, carbohydrates: 4 } + , { name: "Salsifis", glycemicIndex: 30, carbohydrates: 14 } + , { name: "Sauge (feuille)", glycemicIndex: 40, carbohydrates: 60 } + , { name: "Semoule", glycemicIndex: 68, carbohydrates: 24 } + , { name: "Sirop d'érable", glycemicIndex: 65, carbohydrates: 65 } + , { name: "Son d'avoine", glycemicIndex: 15, carbohydrates: 51 } + + , { name: "Tomate", glycemicIndex: 30, carbohydrates: 4 } + , { name: "Tomate cerise", glycemicIndex: 30, carbohydrates: 4 } + , { name: "Tomate grappe", glycemicIndex: 30, carbohydrates: 3 } + , { name: "Tomate sechée", glycemicIndex: 35, carbohydrates: 8 } + , { name: "Tomme de chèvre", glycemicIndex: 10, carbohydrates: 3 } + , { name: "Topinambour", glycemicIndex: 15, carbohydrates: 14 } + , { name: "Tranche pain de mie", glycemicIndex: 85, carbohydrates: 46 } + + , { name: "Yaourt", glycemicIndex: 35, carbohydrates: 5 } + , { name: "Yaourt brassé nature", glycemicIndex: 35, carbohydrates: 6 } + , { name: "yaourt lait de brebis", glycemicIndex: 35, carbohydrates: 4 } + , { name: "Yaourt lait entier", glycemicIndex: 35, carbohydrates: 5 } + , { name: "Yaourt nature", glycemicIndex: 35, carbohydrates: 5 } + + , { name: "Zeste citron", glycemicIndex: 20, carbohydrates: 13 } ] diff --git a/src/Format.purs b/src/Format.purs index 22593e5..bed5927 100644 --- a/src/Format.purs +++ b/src/Format.purs @@ -1,12 +1,17 @@ -module Format where +module Format + ( number + , compare + , unaccent + ) where import Data.Int (toNumber, fromNumber) import Data.Array (replicate) import Data.Maybe (fromMaybe) -import Data.String (length, joinWith) +import Data.String (length, joinWith, fromCharArray, toCharArray, toLower) import Math (round, trunc, pow) -import Prelude +import Prelude hiding (compare) +import Prelude as Prelude number :: Int -> Number -> String number decimalLength num = formattedIntegerPart <> formattedDecimalPart @@ -27,3 +32,42 @@ number decimalLength num = formattedIntegerPart <> formattedDecimalPart # \str -> "," <> (joinWith "" $ replicate (decimalLength - length str) "0") <> str else "" + +compare :: String -> String -> Ordering +compare xs ys = Prelude.compare (formatString xs) (formatString ys) + where formatString = unaccent <<< toLower + +unaccent :: String -> String +unaccent = fromCharArray <<< map unaccentChar <<< toCharArray + where + unaccentChar :: Char -> Char + unaccentChar c = case c of + 'à' -> 'a' + 'á' -> 'a' + 'â' -> 'a' + 'ã' -> 'a' + 'ä' -> 'a' + 'ç' -> 'c' + 'è' -> 'e' + 'é' -> 'e' + 'ê' -> 'e' + 'ë' -> 'e' + 'ì' -> 'i' + 'í' -> 'i' + 'î' -> 'i' + 'ï' -> 'i' + 'ñ' -> 'n' + 'ò' -> 'o' + 'ó' -> 'o' + 'ô' -> 'o' + 'õ' -> 'o' + 'ö' -> 'o' + 'š' -> 's' + 'ù' -> 'u' + 'ú' -> 'u' + 'û' -> 'u' + 'ü' -> 'u' + 'ý' -> 'y' + 'ÿ' -> 'y' + 'ž' -> 'z' + _ -> c diff --git a/src/Indicator.purs b/src/Indicator.purs index 536133d..39a98ca 100644 --- a/src/Indicator.purs +++ b/src/Indicator.purs @@ -1,6 +1,6 @@ module Indicator ( Indicator(..) - , fromGlycemicIndex + , fromGlycemicLoad ) where import Prelude @@ -12,8 +12,8 @@ instance showIndicator :: Show Indicator where show Medium = "Medium" show Bad = "Bad" -fromGlycemicIndex :: Int -> Indicator -fromGlycemicIndex n - | n < 40 = Good - | n < 55 = Medium +fromGlycemicLoad :: Number -> Indicator +fromGlycemicLoad n + | n <= 10.0 = Good + | n < 20.0 = Medium | otherwise = Bad diff --git a/src/Main.purs b/src/Main.purs index 3121aa5..e00f4ce 100644 --- a/src/Main.purs +++ b/src/Main.purs @@ -1,4 +1,6 @@ -module Main where +module Main + ( main + ) where import Prelude import Control.Monad.Eff (Eff) diff --git a/src/Page.purs b/src/Page.purs index 07372d2..c0b641c 100644 --- a/src/Page.purs +++ b/src/Page.purs @@ -1,4 +1,7 @@ -module Page where +module Page + ( component + , Query + ) where import Data.Array ((:), sortBy) import Data.Maybe (Maybe(..)) @@ -32,7 +35,7 @@ component = [ HH.h1 [] [ HH.text "Glycémie" ] , HH.ul [ HP.class_ $ HH.ClassName "aliments" ] - (renderTitle : (map renderAliment <<< sortBy (\a b -> compare a.name b.name) $ Food.all)) + (renderTitle : (map renderAliment <<< sortBy (\a b -> Format.compare a.name b.name) $ Food.all)) ] eval :: Query ~> H.ComponentDSL State Query Message m @@ -65,12 +68,13 @@ renderAliment aliment = [] [ HH.text aliment.name ] , HH.div - [ HP.class_ $ HH.ClassName ("number " <> (show $ Indicator.fromGlycemicIndex aliment.glycemicIndex)) ] + [ HP.class_ $ HH.ClassName "number" ] [ HH.text (show aliment.glycemicIndex) ] , HH.div [ HP.class_ $ HH.ClassName "number" ] [ HH.text (show aliment.carbohydrates) ] - , HH.div - [ HP.class_ $ HH.ClassName "number" ] - [ HH.text (Format.number 2 <<< Food.glycemicLoad $ aliment) ] + , let glycemicLoad = Food.glycemicLoad aliment + in HH.div + [ HP.class_ $ HH.ClassName ("number " <> (show $ Indicator.fromGlycemicLoad glycemicLoad)) ] + [ HH.text (Format.number 2 glycemicLoad) ] ] |