packages feed

Nutri (empty) → 0.1

raw patch · 10 files changed

+571/−0 lines, 10 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,121 @@+Creative Commons Legal Code++CC0 1.0 Universal++    CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE+    LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN+    ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS+    INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES+    REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS+    PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM+    THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED+    HEREUNDER.++Statement of Purpose++The laws of most jurisdictions throughout the world automatically confer+exclusive Copyright and Related Rights (defined below) upon the creator+and subsequent owner(s) (each and all, an "owner") of an original work of+authorship and/or a database (each, a "Work").++Certain owners wish to permanently relinquish those rights to a Work for+the purpose of contributing to a commons of creative, cultural and+scientific works ("Commons") that the public can reliably and without fear+of later claims of infringement build upon, modify, incorporate in other+works, reuse and redistribute as freely as possible in any form whatsoever+and for any purposes, including without limitation commercial purposes.+These owners may contribute to the Commons to promote the ideal of a free+culture and the further production of creative, cultural and scientific+works, or to gain reputation or greater distribution for their Work in+part through the use and efforts of others.++For these and/or other purposes and motivations, and without any+expectation of additional consideration or compensation, the person+associating CC0 with a Work (the "Affirmer"), to the extent that he or she+is an owner of Copyright and Related Rights in the Work, voluntarily+elects to apply CC0 to the Work and publicly distribute the Work under its+terms, with knowledge of his or her Copyright and Related Rights in the+Work and the meaning and intended legal effect of CC0 on those rights.++1. Copyright and Related Rights. A Work made available under CC0 may be+protected by copyright and related or neighboring rights ("Copyright and+Related Rights"). Copyright and Related Rights include, but are not+limited to, the following:++  i. the right to reproduce, adapt, distribute, perform, display,+     communicate, and translate a Work;+ ii. moral rights retained by the original author(s) and/or performer(s);+iii. publicity and privacy rights pertaining to a person's image or+     likeness depicted in a Work;+ iv. rights protecting against unfair competition in regards to a Work,+     subject to the limitations in paragraph 4(a), below;+  v. rights protecting the extraction, dissemination, use and reuse of data+     in a Work;+ vi. database rights (such as those arising under Directive 96/9/EC of the+     European Parliament and of the Council of 11 March 1996 on the legal+     protection of databases, and under any national implementation+     thereof, including any amended or successor version of such+     directive); and+vii. other similar, equivalent or corresponding rights throughout the+     world based on applicable law or treaty, and any national+     implementations thereof.++2. Waiver. To the greatest extent permitted by, but not in contravention+of, applicable law, Affirmer hereby overtly, fully, permanently,+irrevocably and unconditionally waives, abandons, and surrenders all of+Affirmer's Copyright and Related Rights and associated claims and causes+of action, whether now known or unknown (including existing as well as+future claims and causes of action), in the Work (i) in all territories+worldwide, (ii) for the maximum duration provided by applicable law or+treaty (including future time extensions), (iii) in any current or future+medium and for any number of copies, and (iv) for any purpose whatsoever,+including without limitation commercial, advertising or promotional+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each+member of the public at large and to the detriment of Affirmer's heirs and+successors, fully intending that such Waiver shall not be subject to+revocation, rescission, cancellation, termination, or any other legal or+equitable action to disrupt the quiet enjoyment of the Work by the public+as contemplated by Affirmer's express Statement of Purpose.++3. Public License Fallback. Should any part of the Waiver for any reason+be judged legally invalid or ineffective under applicable law, then the+Waiver shall be preserved to the maximum extent permitted taking into+account Affirmer's express Statement of Purpose. In addition, to the+extent the Waiver is so judged Affirmer hereby grants to each affected+person a royalty-free, non transferable, non sublicensable, non exclusive,+irrevocable and unconditional license to exercise Affirmer's Copyright and+Related Rights in the Work (i) in all territories worldwide, (ii) for the+maximum duration provided by applicable law or treaty (including future+time extensions), (iii) in any current or future medium and for any number+of copies, and (iv) for any purpose whatsoever, including without+limitation commercial, advertising or promotional purposes (the+"License"). The License shall be deemed effective as of the date CC0 was+applied by Affirmer to the Work. Should any part of the License for any+reason be judged legally invalid or ineffective under applicable law, such+partial invalidity or ineffectiveness shall not invalidate the remainder+of the License, and in such case Affirmer hereby affirms that he or she+will not (i) exercise any of his or her remaining Copyright and Related+Rights in the Work or (ii) assert any associated claims and causes of+action with respect to the Work, in either case contrary to Affirmer's+express Statement of Purpose.++4. Limitations and Disclaimers.++ a. No trademark or patent rights held by Affirmer are waived, abandoned,+    surrendered, licensed or otherwise affected by this document.+ b. Affirmer offers the Work as-is and makes no representations or+    warranties of any kind concerning the Work, express, implied,+    statutory or otherwise, including without limitation warranties of+    title, merchantability, fitness for a particular purpose, non+    infringement, or the absence of latent or other defects, accuracy, or+    the present or absence of errors, whether or not discoverable, all to+    the greatest extent permissible under applicable law.+ c. Affirmer disclaims responsibility for clearing rights of other persons+    that may apply to the Work or any use thereof, including without+    limitation any person's Copyright and Related Rights in the Work.+    Further, Affirmer disclaims responsibility for obtaining any necessary+    consents, permissions or other rights required for any use of the+    Work.+ d. Affirmer understands and acknowledges that Creative Commons is not a+    party to this document and has no duty or obligation with respect to+    this CC0 or use of the Work.
+ Nutri.cabal view
@@ -0,0 +1,34 @@+name:                Nutri+version:             0.1+synopsis:            A little library to calculate nutrition values of food items.+description:         This is the start of a library that helps to calculate with +                     nutrition values of food items. There is a basic datatype for +                     weight information and one for the nutrient information of food. +                     One can combine variouse foods together and let the library +                     calculate the overall protein, carbohydrate and fat percentages +                     as well as the caloric value. +homepage:            https://github.com/frosch03/Nutri+license:             PublicDomain+license-file:        LICENSE+author:              Matthias Brettschneider+maintainer:          frosch03@frosch03.de+category:            Utils+build-type:          Simple+extra-source-files:  Readme.md+cabal-version:       >=1.10++library+  exposed-modules:     Data.Nutri, +                       Data.Nutrition.Food, +                       Data.Nutrition.VariousFoods, +                       Data.Nutrition.Defaults, +                       Data.Nutrition.Macros, +                       Data.Nutrition.Weight++  build-depends:       base >=4.6 && <4.7+  default-language:    Haskell2010+  hs-source-dirs:      src++source-repository head+  type:     git+  location: https://github.com/frosch03/Nutri.git
+ Readme.md view
@@ -0,0 +1,29 @@+Nutri+==========++Nutri is a very basic library to calculate a little with macro+nutrient's. +++Foods+----------++There are some food's included in `VariousFoods.hs` and more can be+defined there. A Food is basically a function that takes an amount+value and calculates from that the caloric value.+++Weight+----------++The amount of food is given by the Weight type. Until now, there are+only `Gramm` values, but more can be added to that type.+++Macros+----------++The `Macros` type is a triple type, that contains the macro+nutrients. Those are *Protein*, *Carbohydrate*s and *Fat*s. ++
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Data/Nutri.hs view
@@ -0,0 +1,31 @@+{-# OPTIONS_HADDOCK prune, ignore-exports #-}++-- | Nutri is actual something like the Main module. It shows a simple+-- usage of the Nutri-library++module Data.Nutri+where++import Data.Monoid++import Data.Nutrition.Food   +import Data.Nutrition.Defaults+import Data.Nutrition.Weight+import Data.Nutrition.VariousFoods++tag1 :: Food+tag1 =    (Gramm 250) .@ schnitzelLutz +       <> (Gramm 500) .@ quark+       <> (Gramm 200) .@ frischkaese +       <> (Gramm 150) .@ haenchenstreifen ++tag2 :: Food+tag2 =    (Gramm 500) .@ quark+       <> (Gramm 150) .@ haenchenstreifen+       <> (Gramm 380) .@ putenbrust+       <> (Gramm 100) .@ reis++tag3 :: Food+tag3 =    (Gramm 500) .@ quark+       <> (Gramm 100) .@ wheyProtein+       <> (Gramm 440) .@ subwayTurkyHam
+ src/Data/Nutrition/Defaults.hs view
@@ -0,0 +1,20 @@+{-# OPTIONS_HADDOCK prune, ignore-exports #-}+++module Data.Nutrition.Defaults+where++type Percent = Float++type Protein = Percent +type Carb    = Percent +type Fat     = Percent  ++type Name    = String++-- | Default caloric values for proteins, carbohydrates and fats+kcalOfProt, kcalOfCarb, kcalOfFat  :: Float+kcalOfProt = 4.1+kcalOfCarb = 4.1+kcalOfFat  = 9.3+
+ src/Data/Nutrition/Food.hs view
@@ -0,0 +1,119 @@+{-# OPTIONS_HADDOCK prune, ignore-exports #-}++module Data.Nutrition.Food+    ( Food ()+    , Data.Nutrition.Food.prot+    , Data.Nutrition.Food.carb+    , Data.Nutrition.Food.fat++    , (.@)++    , foodGenerator+    )+where++import Data.Monoid+import Data.Nutrition.Weight+import Data.Nutrition.Macros hiding (prot, carb, fat)+import Data.Nutrition.Macros as M+import Data.Nutrition.Defaults++-- | The Food data type consists of four things: +-- +-- * @foodname@ A name of the food. +-- +-- * @macros@   The macro nutrients of that specific food-item.+-- +-- * @calories@ A calculated caloric value saved in kilo calories. +-- +-- * @amount@   The amount of the actual food. +data Food +    = Food +      { foodname :: Name +      , macros :: Macros +      , calories :: Int  +      , amount :: Weight +      } ++-- | A simple operator so one can write the 'Weight' value prefix to+-- the food.+(.@) :: Weight -> (Weight -> Food) -> Food+(.@) w f = f w ++-- | kcal takes a food item and gives back the kilo-caloric+-- value. This value is calculated from the macro-nutrition values.+kcal :: Food -> Int+kcal f +    = round $ protkcal + carbkcal + fatkcal+    where +      protkcal = kcalOfProt * (Data.Nutrition.Food.prot f)+      carbkcal = kcalOfCarb * (Data.Nutrition.Food.carb f)+      fatkcal  = kcalOfFat  * (Data.Nutrition.Food.fat f)++++-- | This function is a "smart constructor" to construct a food+-- item. If no 'Weight' is supplied, a food generating function for a+-- specific food item is returned. +foodGenerator :: String -> (Protein, Carb, Fat) -> (Weight -> Food)+foodGenerator s (p, c, f) w+    = Food+        s+        (newMacros (p, c, f))+        (round $ kcalOfProt * p / 100.0 * inGramm w+               + kcalOfCarb * c / 100.0 * inGramm w+               + kcalOfFat  * f / 100.0 * inGramm w)+        w++-- | The 'prot', 'carb' and 'fat' functions return the value of the+-- macro-nutrients in gram's. +prot, carb, fat :: Food -> Float+prot f = (inGramm.amount $ f) * (M.prot . macros $ f) / 100.0+carb f = (inGramm.amount $ f) * (M.carb . macros $ f) / 100.0+fat  f = (inGramm.amount $ f) * (M.fat  . macros $ f) / 100.0+++-- | 'Food' is an instance of the Show class, so it can be printed+-- onto the screen.+instance Show Food where+    show (Food n ms cals (Gramm a))+         = show (round a) ++ "g (" ++ show cals ++ " kcal) " ++ n ++ " (Prot: " ++ show (round $ M.prot ms) ++ "%, Carb: " +                                             ++ show (round $ M.carb ms) ++ "%, Fat: " +                                             ++ show (round $ M.fat ms)  ++ "%)\n"+           where prot_g = a * (M.prot ms) / 100.0+                 carb_g = a * (M.carb ms) / 100.0+                 fat_g  = a * (M.fat  ms) / 100.0+++                  +-- | 'Food' is an instance of the Monoid class. That leads to the+-- possibility of combining foods to meals together.+instance Monoid Food where+    mempty +        = Food "" (newMacros (0, 0, 0)) 0 (Gramm 0)++    f1 `mappend` f2+        = addFood f1 f2 +++-- | The 'addFood' function does the combination of two foods into+-- another one.+addFood :: Food -> Food -> Food+addFood f1 f2+    = Food { foodname = foodname f1 ++ " and " ++ foodname f2 +           , macros = newMacros ( ((Data.Nutrition.Food.prot f1) + (Data.Nutrition.Food.prot f2)) / fact'+                                , ((Data.Nutrition.Food.carb f1) + (Data.Nutrition.Food.carb f2)) / fact'+                                , ((Data.Nutrition.Food.fat  f1) + (Data.Nutrition.Food.fat  f2)) / fact'+                                )+           , calories = calories f1 + calories f2+           , amount = amount f1 + amount f2+           }+    where +      fact1 = (fG $ amount f1) / 100.0+      fact2 = (fG $ amount f2) / 100.0+      fact' = (fact1 + fact2)+      mf1 = macros f1+      mf2 = macros f2+      fG (Gramm x) = x++
+ src/Data/Nutrition/Macros.hs view
@@ -0,0 +1,59 @@+{-# OPTIONS_HADDOCK prune, ignore-exports #-}++module Data.Nutrition.Macros+    ( +      Macros ()+    , newMacros ++    , prot+    , carb+    , fat++    )+where+++import Control.Category++type Percent = Float++type Protein = Percent  +type Carb    = Percent +type Fat     = Percent ++-- | The macro nutrients are @Protein@, @Carbohydrate@ and @Fat@. They+-- are stored within a triple that is called 'Macros'.+data Macros = Macros (Protein, Carb, Fat)+++-- | 'prot', 'carb' and 'fat' are functions that return the percent of+-- that macro nutrient. They are basically getters of the 'Macros'+-- data.+prot, fat, carb :: Macros -> Percent+prot (Macros (p, _, _)) = p+carb (Macros (_, c, _)) = c+fat  (Macros (_, _, f)) = f++-- | 'newMacros' is a smart constructor to 'Macros'. It checks,+-- whether the sum of the percentages is equal or below+-- 100%. Otherwise it does not construct a 'Macros' value.+newMacros :: (Protein, Carb, Fat) -> Macros+newMacros (p, c, f) +         | (p + c + f) <= 100 = Macros (p, c, f)+         | otherwise         = error $ "macro definition exeeds 100%"+++-- instance Num Macros where+--     m1 + m2 = newMacros $ percentualDo (+) (prot m1, carb m1, fat m1) (prot m2, carb m2, fat m2)+--     m1 - m2 = newMacros $ percentualDo (-) (prot m1, carb m1, fat m1) (prot m2, carb m2, fat m2)+--     (*) = error "this operation isn't defined on macros"++-- percentualDo op (p1, c1, f1) (p2, c2, f2) +--     = (p, c, f)+--     where sum1 = p1 + c1 + f1+--           sum2 = p2 + c2 + f2+--           percentCalc op sum1 sum2 v1 v2 +--               = (v1 * 100.0 / sum1) `op` (v2 * 100.0 / sum2) / 2+--           p = percentCalc op sum1 sum2 p1 p2+--           c = percentCalc op sum1 sum2 c1 c2+--           f = percentCalc op sum1 sum2 f1 f2
+ src/Data/Nutrition/VariousFoods.hs view
@@ -0,0 +1,130 @@+{-# OPTIONS_HADDOCK prune, ignore-exports #-}++-- | Within this module, various food items are defined. They are+-- defined without any weight information. Within the 'Nutri'-module,+-- the amount of a specific food can be generated via: @(Gramm 150)+-- .@ quark@.++module Data.Nutrition.VariousFoods++where++import Data.Nutrition.Food   +import Data.Nutrition.Defaults+import Data.Nutrition.Weight++-- | turkey-breast+putenbrust :: Weight -> Food+putenbrust+    = foodGenerator+      "Putenbrust"+      (21, 1, 1)++-- | Rice+reis :: Weight -> Food+reis +    = foodGenerator+      "Reis"+      (7, 77, 1)++-- | Curd+quark :: Weight -> Food+quark +    = foodGenerator+      "Speisequark"+      (12, 4, 1)++-- | Cream-Cheese+frischkaese :: Weight -> Food+frischkaese +    = foodGenerator +      "körniger Frischkäse"+      (12, 4, 0)++-- | Chicken strips+haenchenstreifen :: Weight -> Food+haenchenstreifen +    = foodGenerator+      "Hähnchen-Filetstreifen"+      (25, 2, 5)++-- | Schnitzel (you know what i mean ;-) +schnitzelLutz :: Weight -> Food+schnitzelLutz+    = foodGenerator+      "Schnitzel"+      (16, 17, 8)++-- | Caesar-Salad +caesarSalat :: Weight -> Food+caesarSalat+    = foodGenerator+      "Caesar Salat"+      (4, 6, 9)++wheyProtein :: Weight -> Food+wheyProtein+    = foodGenerator+      "Eiweisdrink"+      (80, 8, 4) -- TODO: correct? ++risoniNudelsalat :: Weight -> Food+risoniNudelsalat+    = foodGenerator+      "Risoni-Nudelsalat"+      (8, 10, 7)++mUndmMini :: Weight -> Food+mUndmMini+    = foodGenerator+      "M&M Mini"+      (9, 60, 25)+      +subwayTurkyHam :: Weight -> Food+subwayTurkyHam+    = foodGenerator+      "Sub-Turky&Ham"+      (10, 18, 3)++subwayFajita :: Weight -> Food+subwayFajita+    = foodGenerator+      "Sub-ChickenFajita"+      (10, 19, 3)++subwayChickenBreast :: Weight -> Food+subwayChickenBreast+    = foodGenerator+      "Sub-ChickenBreast"+      (10, 19, 5)++subwayTeriyaki :: Weight -> Food+subwayTeriyaki+    = foodGenerator+      "Sub-Teriyaki"+      (9, 19, 3)++subwayHam :: Weight -> Food+subwayHam+    = foodGenerator+      "Sub-Ham"+      (9, 20, 3)++subwayTurky :: Weight -> Food+subwayTurky+    = foodGenerator+      "Sub-Turky"+      (10, 19, 3)++subwayVeggi :: Weight -> Food+subwayVeggi+    = foodGenerator+      "Sub-Veggi"+      (6, 26, 4)++subwayTurkyHamBacon :: Weight -> Food+subwayTurkyHamBacon+    = foodGenerator+      "Sub-Turky&Ham&Bacon"+      (12, 17, 3)+
+ src/Data/Nutrition/Weight.hs view
@@ -0,0 +1,26 @@+{-# OPTIONS_HADDOCK prune, ignore-exports #-}++module Data.Nutrition.Weight +where++data Weight +    = Gramm Float+    deriving (Eq)+++-- | This Function return the weight as a floating point number and+-- calculates that as a gramm value. (ATM there is only a Gramm-Weight+-- Constructor)+inGramm :: Weight -> Float+inGramm (Gramm g) = g+++-- | A Weight is a member of the Typeclass 'Num'+instance Num Weight where+    (Gramm w1) + (Gramm w2) = Gramm (w1 + w2)+    (Gramm w1) * (Gramm w2) = Gramm (w1 * w2)+    abs (Gramm w)           = Gramm (abs w)+    signum (Gramm w)        = Gramm (signum w)+    fromInteger x           = Gramm (fromInteger x)++