diff options
-rw-r--r-- | README.md | 1 | ||||
-rwxr-xr-x | convert.py | 3 | ||||
-rw-r--r-- | index.html | 57 | ||||
-rwxr-xr-x | read.py | 38 | ||||
-rw-r--r-- | requirements.txt | 1 | ||||
-rw-r--r-- | static/data.js | 1 | ||||
-rw-r--r-- | static/favicon.ico | bin | 0 -> 318 bytes | |||
-rw-r--r-- | static/script.js | 68 | ||||
-rw-r--r-- | static/styles.css | 3 |
9 files changed, 172 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..5df38b1 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# sweetgreen calculator diff --git a/convert.py b/convert.py new file mode 100755 index 0000000..a7d1965 --- /dev/null +++ b/convert.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python +import tabula +tabula.convert_into('nutrition.pdf', 'out.csv', output_format='csv', pages='3-5') diff --git a/index.html b/index.html new file mode 100644 index 0000000..8b9a888 --- /dev/null +++ b/index.html @@ -0,0 +1,57 @@ +<!DOCTYPE html> +<html> + <head> + <title>Sweetgreen Calculator</title> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="stylesheet" type="text/css" href="/static/styles.css"> + <link rel="stylesheet" type="text/css" href="/sweetgreen-calculator/static/styles.css"> + <link rel="shortcut icon" type="image/x-icon" href="/sweetgreen-calculator/static/favicon.ico"> + </head> + <body> + <div class="container"> + <div> + <div class="home"> + <a href="/sweetgreen-calculator" class="home-title">Sweetgreen Calculator</a> + <span> at </span><a href="/">cyfraeviolae.org</a> + </div> + <div class="crumbs"> + <a href="/git/sweetgreen-calculator">source code</a> + </div> + </div> + <br> + <noscript>Sorry, JavaScript is required to run Sweetgreen Calculator.</noscript> + <form action="/" method="none" id="form"> + <fieldset> + <legend>Bases</legend> + <div id="checkboxes"> + <div class="ingredient"> + <input type="checkbox" id="ingredient0" x-ingredient="0"> + <label for="ingredient0">Spinach</label> + </div> + <div class="ingredient"> + <input type="checkbox" id="ingredient0" x-ingredient="0"> + <label for="ingredient0">Arugula</label> + </div> + </div> + </fieldset> + <fieldset> + <legend>Signature Ingredients</legend> + <div id="checkboxes"> + <div class="ingredient"> + <input type="checkbox" id="ingredient0" x-ingredient="0"> + <label for="ingredient0">Spinach</label> + </div> + <div class="ingredient"> + <input type="checkbox" id="ingredient0" x-ingredient="0"> + <label for="ingredient0">Arugula</label> + </div> + </div> + </fieldset> + </form> + <div id="nutrition"></div> + </div> + <script src="/sweetgreen-calculator/static/data.js"></script> + <script src="/sweetgreen-calculator/static/script.js"></script> + </body> +</html> @@ -0,0 +1,38 @@ +#!/usr/bin/env python +from collections import defaultdict +import pandas as pd + +columns = ['name', 'serving_size', 'calories', 'calories_from_fat', 'total_fat', + 'saturated_fat', 'trans_fat', 'cholesterol', 'sodium', + 'total_carbs', 'dietary_fiber', 'sugars', 'protein'] +bases = [] +signature_ingredients = [] +premium_ingredients = [] +dressings = [] + +with open('out.csv') as fh: + lines = fh.readlines() + +tables = defaultdict(list) +tablemap = {'BASES': 'Bases', + 'SIGNATURE INGREDIENTS': 'Signature ingredients', + 'PREMIUM INGREDIENTS': 'Premium ingredients', + '"DRESSINGS': 'Dressings'} +title = None +for line in lines: + line = line.strip() + if 'SIGNATURE MENU' in line: + break + if '(g)' in line: + title = line.split(',')[0] + continue + if title in tablemap: + cells = line.split(',') + cells = [cells[0]] + [int(cell) for cell in cells[1:]] + tables[tablemap[title]].append(cells) + +dfs = {name: pd.DataFrame(data=table, columns=columns) for name, table in tables.items()} + +import json +jdfs = {name: df.to_dict('records') for name, df in dfs.items()} +print('let data = ' + json.dumps(jdfs)) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3ed9998 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +PyPDF2~=2.0 diff --git a/static/data.js b/static/data.js new file mode 100644 index 0000000..130842d --- /dev/null +++ b/static/data.js @@ -0,0 +1 @@ +let data = {"Bases": [{"name": "Arugula", "serving_size": 48, "calories": 15, "calories_from_fat": 9, "total_fat": 1, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 15, "total_carbs": 2, "dietary_fiber": 1, "sugars": 1, "protein": 1}, {"name": "Baby Spinach", "serving_size": 53, "calories": 15, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 40, "total_carbs": 2, "dietary_fiber": 1, "sugars": 0, "protein": 1}, {"name": "Chopped Romaine", "serving_size": 75, "calories": 15, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 5, "total_carbs": 2, "dietary_fiber": 2, "sugars": 1, "protein": 1}, {"name": "Shredded Kale", "serving_size": 43, "calories": 20, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 15, "total_carbs": 4, "dietary_fiber": 2, "sugars": 1, "protein": 2}, {"name": "Spring Mix", "serving_size": 48, "calories": 10, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Warm Quinoa", "serving_size": 100, "calories": 160, "calories_from_fat": 27, "total_fat": 3, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 167, "total_carbs": 28, "dietary_fiber": 4, "sugars": 2, "protein": 6}, {"name": "Warm Wild Rice", "serving_size": 95, "calories": 155, "calories_from_fat": 18, "total_fat": 2, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 150, "total_carbs": 31, "dietary_fiber": 2, "sugars": 0, "protein": 3}], "Signature ingredients": [{"name": "Apples", "serving_size": 29, "calories": 15, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 4, "dietary_fiber": 1, "sugars": 3, "protein": 0}, {"name": "Basil", "serving_size": 7, "calories": 0, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Black Lentils", "serving_size": 55, "calories": 60, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 65, "total_carbs": 7, "dietary_fiber": 4, "sugars": 1, "protein": 8}, {"name": "Chickpeas", "serving_size": 43, "calories": 45, "calories_from_fat": 14, "total_fat": 2, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 250, "total_carbs": 7, "dietary_fiber": 0, "sugars": 0, "protein": 2}, {"name": "Cilantro", "serving_size": 5, "calories": 0, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Crispy Rice", "serving_size": 26, "calories": 80, "calories_from_fat": 14, "total_fat": 2, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 260, "total_carbs": 14, "dietary_fiber": 0, "sugars": 1, "protein": 2}, {"name": "Cucumbers", "serving_size": 40, "calories": 5, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Fresh Herbs (TX)", "serving_size": 5, "calories": 0, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Hummus", "serving_size": 47, "calories": 80, "calories_from_fat": 41, "total_fat": 5, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 180, "total_carbs": 7, "dietary_fiber": 0, "sugars": 0, "protein": 4}, {"name": "Parmesan Crisps", "serving_size": 20, "calories": 100, "calories_from_fat": 72, "total_fat": 8, "saturated_fat": 5, "trans_fat": 0, "cholesterol": 25, "sodium": 480, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 6}, {"name": "Olives", "serving_size": 39, "calories": 40, "calories_from_fat": 36, "total_fat": 4, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 250, "total_carbs": 2, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Raw Pecans", "serving_size": 14, "calories": 90, "calories_from_fat": 81, "total_fat": 9, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 1, "dietary_fiber": 1, "sugars": 0, "protein": 1}, {"name": "Raw Beets", "serving_size": 40, "calories": 15, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 30, "total_carbs": 3, "dietary_fiber": 1, "sugars": 3, "protein": 1}, {"name": "Raw Carrots", "serving_size": 23, "calories": 10, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 15, "total_carbs": 2, "dietary_fiber": 1, "sugars": 1, "protein": 0}, {"name": "Red Onions", "serving_size": 7, "calories": 5, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Roasted Almonds", "serving_size": 14, "calories": 80, "calories_from_fat": 54, "total_fat": 6, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 3, "dietary_fiber": 2, "sugars": 1, "protein": 3}, {"name": "Roasted Sweet Potatoes", "serving_size": 39, "calories": 65, "calories_from_fat": 9, "total_fat": 1, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 301, "total_carbs": 13, "dietary_fiber": 2, "sugars": 7, "protein": 1}, {"name": "Shredded Cabbage", "serving_size": 25, "calories": 10, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 5, "total_carbs": 2, "dietary_fiber": 1, "sugars": 1, "protein": 0}, {"name": "Spicy Broccoli", "serving_size": 33, "calories": 25, "calories_from_fat": 9, "total_fat": 1, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 120, "total_carbs": 3, "dietary_fiber": 1, "sugars": 1, "protein": 1}, {"name": "Sunflower Seeds", "serving_size": 13, "calories": 70, "calories_from_fat": 54, "total_fat": 6, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 55, "total_carbs": 2, "dietary_fiber": 1, "sugars": 0, "protein": 2}, {"name": "Tomatoes", "serving_size": 46, "calories": 10, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 10, "total_carbs": 2, "dietary_fiber": 1, "sugars": 1, "protein": 1}, {"name": "Tortilla Chips", "serving_size": 16, "calories": 80, "calories_from_fat": 36, "total_fat": 4, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 10, "total_carbs": 10, "dietary_fiber": 1, "sugars": 0, "protein": 1}, {"name": "Za'atar Breadcrumbs", "serving_size": 15, "calories": 65, "calories_from_fat": 18, "total_fat": 2, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 201, "total_carbs": 9, "dietary_fiber": 1, "sugars": 0, "protein": 3}], "Premium ingredients": [{"name": "Avocado", "serving_size": 87, "calories": 160, "calories_from_fat": 117, "total_fat": 13, "saturated_fat": 3, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 8, "dietary_fiber": 9, "sugars": 0, "protein": 3}, {"name": "Blackened Catfish", "serving_size": 77, "calories": 125, "calories_from_fat": 72, "total_fat": 8, "saturated_fat": 2, "trans_fat": 0, "cholesterol": 53, "sodium": 276, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 13}, {"name": "Blackened Chicken", "serving_size": 80, "calories": 140, "calories_from_fat": 54, "total_fat": 6, "saturated_fat": 2, "trans_fat": 0, "cholesterol": 99, "sodium": 334, "total_carbs": 1, "dietary_fiber": 1, "sugars": 0, "protein": 21}, {"name": "Blue Cheese", "serving_size": 30, "calories": 110, "calories_from_fat": 81, "total_fat": 9, "saturated_fat": 6, "trans_fat": 0, "cholesterol": 25, "sodium": 340, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 6}, {"name": "Goat Cheese", "serving_size": 34, "calories": 90, "calories_from_fat": 63, "total_fat": 7, "saturated_fat": 5, "trans_fat": 0, "cholesterol": 15, "sodium": 160, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 7}, {"name": "Hard Boiled Egg", "serving_size": 50, "calories": 70, "calories_from_fat": 45, "total_fat": 5, "saturated_fat": 2, "trans_fat": 0, "cholesterol": 190, "sodium": 70, "total_carbs": 1, "dietary_fiber": 0, "sugars": 1, "protein": 7}, {"name": "Hot Roasted Sweet Potatoes", "serving_size": 72, "calories": 85, "calories_from_fat": 22, "total_fat": 2, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 220, "total_carbs": 15, "dietary_fiber": 2, "sugars": 2, "protein": 2}, {"name": "Parmesan Crisps", "serving_size": 20, "calories": 100, "calories_from_fat": 72, "total_fat": 8, "saturated_fat": 5, "trans_fat": 0, "cholesterol": 25, "sodium": 480, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 6}, {"name": "Pickled Carrots + Celery", "serving_size": 30, "calories": 5, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 250, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Roasted Chicken", "serving_size": 78, "calories": 110, "calories_from_fat": 18, "total_fat": 2, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 58, "sodium": 254, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 21}, {"name": "Roasted Tofu", "serving_size": 75, "calories": 100, "calories_from_fat": 63, "total_fat": 7, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 250, "total_carbs": 2, "dietary_fiber": 1, "sugars": 0, "protein": 7}, {"name": "Roasted Shrimp (MIA)", "serving_size": 79, "calories": 65, "calories_from_fat": 9, "total_fat": 1, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 133, "sodium": 271, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 14}, {"name": "Roasted Shrimp (TX)", "serving_size": 70, "calories": 65, "calories_from_fat": 9, "total_fat": 1, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 133, "sodium": 271, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 14}, {"name": "Roasted Steelhead", "serving_size": 86, "calories": 170, "calories_from_fat": 90, "total_fat": 10, "saturated_fat": 2, "trans_fat": 0, "cholesterol": 50, "sodium": 172, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 20}, {"name": "Salmon", "serving_size": 86, "calories": 170, "calories_from_fat": 90, "total_fat": 10, "saturated_fat": 2, "trans_fat": 0, "cholesterol": 50, "sodium": 172, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 20}, {"name": "Shaved Parmesan", "serving_size": 12, "calories": 45, "calories_from_fat": 36, "total_fat": 4, "saturated_fat": 2, "trans_fat": 0, "cholesterol": 0, "sodium": 150, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 3}, {"name": "Turkey Meatballs", "serving_size": 85, "calories": 90, "calories_from_fat": 18, "total_fat": 2, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 43, "sodium": 300, "total_carbs": 7, "dietary_fiber": 1, "sugars": 1, "protein": 11}, {"name": "Warm Portobello Mix", "serving_size": 65, "calories": 110, "calories_from_fat": 72, "total_fat": 8, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 498, "total_carbs": 6, "dietary_fiber": 3, "sugars": 0, "protein": 5}], "Dressings": [{"name": "Balsamic Vinegar", "serving_size": 15, "calories": 15, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 3, "dietary_fiber": 0, "sugars": 2, "protein": 0}, {"name": "Balsamic Vinaigrette", "serving_size": 30, "calories": 150, "calories_from_fat": 126, "total_fat": 14, "saturated_fat": 2, "trans_fat": 0, "cholesterol": 0, "sodium": 210, "total_carbs": 6, "dietary_fiber": 0, "sugars": 3, "protein": 0}, {"name": "Caesar Dressing", "serving_size": 30, "calories": 100, "calories_from_fat": 90, "total_fat": 10, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 10, "sodium": 330, "total_carbs": 2, "dietary_fiber": 0, "sugars": 0, "protein": 1}, {"name": "Extra Virgin Olive Oil", "serving_size": 15, "calories": 130, "calories_from_fat": 126, "total_fat": 14, "saturated_fat": 2, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Green Goddess Ranch", "serving_size": 30, "calories": 145, "calories_from_fat": 135, "total_fat": 15, "saturated_fat": 3, "trans_fat": 0, "cholesterol": 10, "sodium": 300, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 1}, {"name": "Hot Honey Mustard Sauce", "serving_size": 30, "calories": 120, "calories_from_fat": 90, "total_fat": 10, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 240, "total_carbs": 7, "dietary_fiber": 0, "sugars": 4, "protein": 0}, {"name": "Lemon Squeeze", "serving_size": 15, "calories": 0, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Lime Cilantro Jalape\u00f1o Vinaigrette", "serving_size": 30, "calories": 110, "calories_from_fat": 108, "total_fat": 12, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 50, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Lime Squeeze", "serving_size": 15, "calories": 5, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Miso Sesame Ginger Dressing", "serving_size": 30, "calories": 120, "calories_from_fat": 108, "total_fat": 12, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 200, "total_carbs": 0, "dietary_fiber": 0, "sugars": 2, "protein": 1}, {"name": "Nuoc Cham Dressing", "serving_size": 30, "calories": 25, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 870, "total_carbs": 5, "dietary_fiber": 0, "sugars": 4, "protein": 1}, {"name": "Pesto Vinaigrette", "serving_size": 30, "calories": 85, "calories_from_fat": 81, "total_fat": 9, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 125, "total_carbs": 1, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Spicy Cashew Dressing", "serving_size": 30, "calories": 100, "calories_from_fat": 81, "total_fat": 9, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 200, "total_carbs": 4, "dietary_fiber": 1, "sugars": 2, "protein": 1}, {"name": "Ceviche Dressing", "serving_size": 30, "calories": 80, "calories_from_fat": 54, "total_fat": 6, "saturated_fat": 1, "trans_fat": 0, "cholesterol": 0, "sodium": 220, "total_carbs": 6, "dietary_fiber": 0, "sugars": 0, "protein": 0}, {"name": "Sweetgreen Hot Sauce", "serving_size": 28, "calories": 10, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 170, "total_carbs": 2, "dietary_fiber": 1, "sugars": 1, "protein": 1}, {"name": "Sesame Teriyaki Dressing", "serving_size": 30, "calories": 140, "calories_from_fat": 117, "total_fat": 13, "saturated_fat": 2, "trans_fat": 0, "cholesterol": 0, "sodium": 630, "total_carbs": 4, "dietary_fiber": 0, "sugars": 3, "protein": 2}, {"name": "Crushed Red Pepper", "serving_size": 1, "calories": 0, "calories_from_fat": 0, "total_fat": 0, "saturated_fat": 0, "trans_fat": 0, "cholesterol": 0, "sodium": 0, "total_carbs": 0, "dietary_fiber": 0, "sugars": 0, "protein": 0}]} diff --git a/static/favicon.ico b/static/favicon.ico Binary files differnew file mode 100644 index 0000000..4e0f88c --- /dev/null +++ b/static/favicon.ico diff --git a/static/script.js b/static/script.js new file mode 100644 index 0000000..ced777c --- /dev/null +++ b/static/script.js @@ -0,0 +1,68 @@ +"use strict"; + +var html = `` +for (var table in data) { + var s = `` + for (var idx in data[table]) { + let tag = table + '|' + idx + s += `<input type="checkbox" id="ingredient${tag}" x-ingredient="${tag}"> + <label for="ingredient${tag}">${data[table][idx].name}</label>` + } + html += `<fieldset><legend>${table}</legend>${s}</fieldset>` +} +html += `<fieldset><legend>Dressing amount</legend> + <input type="radio" name="dressing-amount" id="light" value="light"> + <label for="light">Light</label><br> + <input type="radio" name="dressing-amount" id="medium" value="medium"> + <label for="medium">Medium</label><br> + <input type="radio" name="dressing-amount" id="heavy" value="heavy"> + <label for="heavy">Heavy</label><br> + </fieldset>` + +nutrition = document.getElementById('nutrition') +form = document.getElementById('form') +form.innerHTML = html + +let multipliers = {'none': 0, 'light': 1, 'medium': 2, 'heavy': 3} + +function calculateNutrition() { + let total = {} + let dressingAmount = form.elements['dressing-amount'].value || 'none' + for (var el of document.querySelectorAll('input:checked')) { + if (el.getAttribute('type') == 'radio') { + continue + } + let tag = el.getAttribute('x-ingredient') + let table = tag.split('|')[0] + let idx = tag.split('|')[1] + let row = data[table][idx] + for (var [name, val] of Object.entries(row)) { + if (typeof val == 'string') { + continue + } + if (!total[name]) { + total[name] = 0 + } + let multiplier = 1 + if (table == 'Dressings') { + multiplier = multipliers[dressingAmount] + } + if (multiplier > 0) { + total[name] += multiplier*val + } + } + } + return total +} + +form.addEventListener('change', function() { + let total = calculateNutrition() + var s = ` + Calories: ${total.calories}<br> + Carbohydrates (g): ${total.total_carbs}<br> + Dietary fiber (g): ${total.dietary_fiber}<br> + Fat (g): ${total.total_fat}<br> + Protein (g): ${total.protein}<br> + ` + nutrition.innerHTML = s +}) diff --git a/static/styles.css b/static/styles.css new file mode 100644 index 0000000..f388180 --- /dev/null +++ b/static/styles.css @@ -0,0 +1,3 @@ +label { + margin-right: 18px; +} |