I can just about manage one more Wimpy Tour post before I set off on the 1st July. It’s just under a week now before I start my tour of all the UK’s Wimpy restaurants and there are a final few pieces of code I need to write before I head off. I need to make a data visualisation and a couple of web applications, the first of which gives the nutritional information of my meal.

Making a nutritional data application

To get the nutritional information of my meals I need some data. Wimpy’s nutrition guide contains all the information and I can import this directly from the web as a plain text file.
In[]:=
$PDFLocation="https://wimpy-uk.s3-eu-west-2.amazonaws.com/static/Nutrition%20Guide.pdf";​​unprocessedImport=Import[$PDFLocation,"Plaintext"];
When looking at the imported data, I found that the information I was interested in was in the form of a name followed by 9 numbers, which correspond to nutritional values. I can split the imported file by newlines and look specifically for lines which match this pattern.
In[]:=
split=StringSplit[unprocessedImport,"\n"];
In[]:=
pattern=__~~WordCharacter...~~StringExpression@@Riffle[Table[NumberString,9]," "];​​Short[unprocessedMenuItems=Select[split,StringContainsQ[pattern]]]
Out[]//Short=
{3 Chicken Strips 1032 247 13.7 4.8 15.8 0.5 0.7 16.8 1.2,5 Chicken Strips 1721 411 22.8 8.0 26.3 0.9 1.1 28.0 2.0,176,Thick Shake – Salted Caramel 1333 319 6.3 3.4 57.5 54.1 0.2 7.9 0.2}
From there I process each string into an Association, giving these converting these values in Quantities and adding a key.
In[]:=
allWimpyMenuItems=Dataset[Association@@StringCases[name__~~WordCharacter...~~" "~~energy:NumberString~~" "~~energyKcal:NumberString~~" "~~fat:NumberString~~" "~~sats:NumberString~~" "~~carbs:NumberString~~" "~~sugars:NumberString~~" "~~fibre:NumberString~~" "~~prot:NumberString~~" "~~salt:NumberString:>StringReplace[name,"– "->""]-><|"Calories"->Quantity[energyKcal//ToExpression,"DietaryCalories"],"Fat"->Quantity[fat//ToExpression,"Grams"],"Saturates"->Quantity[sats//ToExpression,"Grams"],"Sugars"->Quantity[sugars//ToExpression,"Grams"],"Carbohydrates"->Quantity[carbs//ToExpression,"Grams"],"Fibre"->Quantity[fibre//ToExpression,"Grams"],"Protein"->Quantity[prot//ToExpression,"Grams"],"Salt"->Quantity[salt//ToExpression,"Grams"]|>][unprocessedMenuItems]]
Out[]=
Calories
Fat
Saturates
Sugars
Carbohydrates
Fibre
Protein
Salt
3 Chicken Strips
247Cal
13.7g
4.8g
0.5g
15.8g
0.7g
16.8g
1.2g
5 Chicken Strips
411Cal
22.8g
8.g
0.9g
26.3g
1.1g
28.g
2.g
10 Chicken Strips
823Cal
45.5g
16.g
1.8g
52.5g
2.3g
56.g
3.9g
4 Mozzarella Melts
323Cal
17.7g
5.9g
2.1g
28.1g
1.2g
12.5g
0.9g
6 Mozzarella Melts
485Cal
26.5g
8.8g
3.1g
42.1g
1.9g
18.7g
1.4g
6 Onion Rings
238Cal
13.3g
4.3g
3.7g
24.4g
3.2g
3.3g
0.6g
10 Onion Rings
396Cal
22.1g
7.1g
6.1g
40.6g
5.3g
5.4g
1.g
Cheesy Chips
464Cal
23.4g
8.7g
0.5g
52.5g
5.6g
15.4g
0.9g
Sweet Potato Chips
295Cal
14.3g
2.g
11.4g
41.3g
5.7g
0.g
0.5g
Wimpy Chips
318Cal
11.8g
1.4g
0.4g
51.6g
5.6g
4.1g
0.2g
Heinz® Baked Beans
81Cal
0.2g
0.g
5.3g
13.1g
3.9g
4.8g
0.7g
Peas
75Cal
0.g
0.g
1.9g
9.7g
5.7g
6.2g
0.g
Mushrooms
106Cal
11.g
0.8g
0.4g
0.4g
1.7g
1.4g
0.g
Wimpy Hamburger
393Cal
16.6g
6.9g
8.3g
40.g
2.4g
20.g
1.5g
Wimpy Cheeseburger Single
434Cal
19.8g
8.4g
8.6g
41.3g
2.4g
21.9g
2.1g
Wimpy Cheeseburger Double
649Cal
36.5g
15.7g
9.g
42.7g
2.4g
36.9g
3.2g
Wimpy Cheeseburger Triple
865Cal
53.2g
23.1g
9.3g
44.1g
2.5g
51.8g
4.3g
Quarterpounder Bacon & Cheese Single
612Cal
32.4g
13.5g
10.6g
43.6g
2.6g
35.6g
3.5g
Quarterpounder Bacon & Cheese Double
918Cal
56.1g
23.9g
10.9g
65.1g
2.7g
57.3g
5.g
Quarterpounder Bacon & Cheese Triple
1224Cal
79.8g
34.2g
11.3g
46.6g
2.7g
79.g
6.4g
rows 1–20 of 146
To get the nutritional information of my meal, I can give it a list of my menu items.
In[]:=
meal=allWimpyMenuItems[{"3 Chicken Strips","Wimpy Chips","Pepsi Max"}]
Out[]=
Calories
Fat
Saturates
Sugars
Carbohydrates
Fibre
Protein
Salt
3 Chicken Strips
247Cal
13.7g
4.8g
0.5g
15.8g
0.7g
16.8g
1.2g
Wimpy Chips
318Cal
11.8g
1.4g
0.4g
51.6g
5.6g
4.1g
0.2g
Pepsi Max
1Cal
0.g
0.g
0.g
0.g
0.g
0.g
0.1g
To include a total of these values, I can append to the Dataset like so.
In[]:=
mealWithTotal=Append[meal,<|"Total"->Normal[meal[Total]]|>]
Out[]=
Calories
Fat
Saturates
Sugars
Carbohydrates
Fibre
Protein
Salt
3 Chicken Strips
247Cal
13.7g
4.8g
0.5g
15.8g
0.7g
16.8g
1.2g
Wimpy Chips
318Cal
11.8g
1.4g
0.4g
51.6g
5.6g
4.1g
0.2g
Pepsi Max
1Cal
0.g
0.g
0.g
0.g
0.g
0.g
0.1g
Total
566Cal
25.5g
6.2g
0.9g
67.4g
6.3g
20.9g
1.5g
I want to be able to use this on my phone, so I’ve chosen to make a FormPage. I’ve made a field called “MenuItems” that contains a List of all the menu items, whose values will show up in PopupMenu. I have wrapped this in RepeatingElement so that I can select multiple menu items. The function uses the code above to create my Dataset with totals as above. Finally I wrap ExportForm around the result to return a PNG (On the Cloud only). You test the FormPage first in a notebook if you want.
nutritionForm=FormPage​​ {"MenuItems"->RepeatingElement[Sort[Normal[Keys[allWimpyMenuItems]]],{1,Infinity}]},​​ Module​​ {meal,mealWithTotal},​​ meal=allWimpyMenuItems[#MenuItems];​​ mealWithTotal=Append[meal,<|"Total"->Normal[meal[Total]]|>];​​ ExportForm[mealWithTotal,"PNG"]​​ &​​
Finally, I deploy this FormPage so I can access this on all my devices.
In[]:=
CloudDeploy[nutritionForm,"WimpyNutritionalInformation",Permissions->"Public"]
Out[]=
CloudObject[
https://www.wolframcloud.com/obj/az/WimpyNutritionalInformation
]

Submitting Wimpy Visit Data

The other important aspect of my tour is record keeping, so I need an application that can log each Wimpy visit.
From my previous post I can easily extract the names of all the Wimpys. I’ve just given the List here for convenience.
In[]:=
allWimpyNames={"Addlestone","Aldershot","Ashford Middlesex","Ashford Kent","Aylesbury","Barnstaple","Basingstoke","Beckenham","Benfleet","Bermondsey","Bexleyheath","Bicester","Birkenhead","Borehamwood","Bourne End","Brentwood","Cheshunt","Clacton-on-Sea","Colchester","Dartford","Dingwall","Dorking","Eastbourne","Eltham","Farnborough","Felixstowe","Fraserburgh","Grays Lakeside","Grays","Harlow","High Wycombe","Hornchurch","Horsham","Huddersfield","Kilmarnock","King's Lynn","Leigh-on-Sea","Littlehampton","Watney Market","Loughton","Lowestoft","Maidstone","Milford","Morden","Orpington","Portslade","Rayleigh","Rickmansworth","Rotherham","Ruislip","Shrewsbury","Sittingbourne","Southend Churchill Square","Southsea","Streatham","Strood","Swanage","Tonbridge","Upminster","Wembley","Westcliff-on-Sea","Woolwich","Worthing"};
I want to give my meals some sort of rating, and have elected to give it a tier system, from S (best) to F (worst), a popular way to rank things.
In[]:=
$Tiers={"S","A","B","C","D","E","F"};
The information I want to record is a date, the Wimpy, the food I ate, the tier and an optional image and notes. Below is a FormFunction which contains all those elements. All data is put into a CloudSymbol called “WimpyVisitData”.
wimpyVisitForm=FormFunction​​ ​​ (*Addapre-filledvaluetoDatewhichistoday'sdate*)​​ "Date"-><|"Input"->DateString[Today],"Interpreter"->"Date"|>,​​ "Wimpy"->allWimpyNames,​​ "MenuItems"->RepeatingElement[Sort[Normal[Keys[allWimpyMenuItems]]],{1,Infinity}],​​ "Tier"->$Tiers,​​ (*AllowimagestobeuploadedasaCloudObject*)​​ "Image"->Restricted["UploadedFile","Image"]->None,​​ "Notes"->"String"->None​​ ,​​ Module​​ {data=#},​​ (*Createsymbolifitdoesnotexist*)​​ If​​ FailureQ[CloudSymbol["WimpyVisitData"]],​​ CloudSymbol["WimpyVisitData"]={}​​ ;​​ (*AdddatatoCloudSymbol*)​​ AppendTo[CloudSymbol["WimpyVisitData"],data]​​ &​​
You can check your submission by calling the CloudSymbol.
And I can deploy this like my nutritional FormPage, which allows me to easily submit data from my phone.

Creating the Tier List Generator

Now that I can submit my information, I want to display some of my findings. I created a tier list generator below. You need to specify a list of tiers and tier data. The tier data needs to be a list of Associations which contain an image and a tier. It uses the ImageSaliencyCrop ResourceFunction to make a square aspect ratio.
I’ve made an example here for you to try out the function:
I will say that these aren’t the greatest pictures of all time, as the food I have eaten at Wimpy so far has been extremely limited.
And that’s it! I’ve now got 2 Wolfram Cloud web applications and a visualisation function to display some of my data in the form of a tier list. I plan to create a ResourceFunction for my tier list generator, but before I do that I want to add some more functionality. Enjoy!

CITE THIS NOTEBOOK

Creating nutritional information cloud apps for the Wimpy Tour​
by Anthony Zupnik​
Wolfram Community, STAFF PICKS, June 25, 2024
​https://community.wolfram.com/groups/-/m/t/3199317