Abstract
Everyone needs to take care of their health and the most important thing is to be careful what you eat.You can find many interesting recipes and cook anything you want, but for health it is important to know what kind of influence it can have on you. In other words you need some nutrition information about meals.The goal of this project is to create a program which will give users such kind of information.You can import ingredients of meals and the program will give you some information such as total calories content, total sugar content etc ...
The code of my project is
CloudDeploy[FormFunction[
{"items", None} -> RepeatingElement[
CompoundElement[<|
"food" -> <|"Label" -> "Foods", "Interpreter" -> "Food"|>,
"quantity" -> <|"Label" -> "Quantity",
"Interpreter" -> "Quantity"|>
|>]
],
With[{vals =
Values@EntityGroup[
EntityInstance @@@ #items][{"AbsoluteTotalCaloriesContent",
"AbsoluteTotalCarbohydratesContent",
"AbsoluteTotalSugarContent", "AbsoluteTotalFatContent",
"AbsoluteCholesterolContent", "AbsoluteTotalProteinContent"},
"PropertyAssociation"]},
If[FreeQ[vals, _Missing],
Grid[
Prepend[Transpose[{{"Calories", "Carbs", "Sugar", "Fat",
"Cholesterol", "Protein"}, vals}], {"Name", "Content"}],
Background -> {None, {Lighter[Yellow, .9], {White,
Lighter[Blend[{Red, Red}], .6]}}},
Dividers -> {{Darker[Gray, .6], {Lighter[Gray, .5]},
Darker[Gray, .6]}, {Darker[Gray, .6],
Darker[Gray, .6], {False}, Darker[Gray, .6]}},
ItemSize -> {{20, 20}}, Frame -> Darker[Gray, .6],
ItemStyle -> 15, Spacings -> {Automatic, .8}],
"Sorry, Missing data"]] &, "PNG"
], Permissions -> "Public"]
Steps of work
- Get data from Wolfram
- Set relations between items and their quantities
- Count the total quantity of contents
- Set condition for those items whose data are missing
- Design page
- Put it on web
In Wolfram Alpha there are a lot of information about foods, including nutrition information.So I've used those ones to make my project. As the output of the program depends on items and their quantities, I've used EntityInstance
function to set relations between items and their quantities
Then to combine all entities I've used EntityGroup
function.
To count total quantity of contents I've used properties such as "AbsoluteTotalCaloriesContent", "AbsoluteTotalCarbohydratesContent", "AbsoluteTotalSugarContent", "AbsoluteTotalFatContent", "AbsoluteCholesterolContent", "AbsoluteTotalProteinContent"
Property "PropertyAssociation"
helped me to create association between properties and appropriate quantities.
There are some foods about which there are no information in wolfram data, so for correct working of program I've used functions With
and If
. So as a result, if you input item about which there is no information the program will give this
For designing outputs I've used Grid
function
Grid[Prepend[
Transpose[{{"Calories", "Carbs", "Sugar", "Fat", "Cholesterol",
"Protein"}, vals}], {"Name", "Content"}],
Background -> {None, {Lighter[Yellow, .9], {White,
Lighter[Blend[{Red, Red}], .6]}}},
Dividers -> {{Darker[Gray, .6], {Lighter[Gray, .5]},
Darker[Gray, .6]}, {Darker[Gray, .6], Darker[Gray, .6], {False},
Darker[Gray, .6]}}, ItemSize -> {{20, 20}},
Frame -> Darker[Gray, .6], ItemStyle -> 15,
Spacings -> {Automatic, .8}]
Then for creating web page I've used CloudDeploy
In Quantity field you should import not only quantity but also a unit, otherwise it will show
You can try to use this program here
Attachments: