--- name: meal-energy-and-macros description: Adds up the energy (kcal), protein, fat and carbohydrate of a meal from measured USDA FoodData Central values per 100 g (Foundation Foods), and sets the meal's energy against the energy of a walk (2024 Compendium METs with the ACSM slope term). Use it when someone lists foods with weights and asks for the meal's calories or macros, or how the meal compares with a walk. --- # Meal energy and macros against a walk ## When to use - Someone lists foods with their weights and asks the meal's energy, protein, fat or carbohydrate. - Someone asks how a meal's energy compares with a walk of given length, speed and slope. - Not for setting calorie or macro targets: this page adds up and compares, nothing more. ## Steps 1. Write down each food and its weight in grams (ounces × 28.349523). Use the weight as the food is listed: raw, or dry for rice, pasta, oats and lentils. 2. Find each food in the figures below (values per 100 g). If a food is not there, read the dataset at https://mysi.dev/food-nutrients-common/ ; if you cannot open it, ask the user for the food's per-100 g values. Never use nutrient values from memory. 3. For each food, multiply each per-100 g value by its grams and divide by 100. Write each result down. 4. Add the foods together, one nutrient at a time: energy in kcal, protein, fat and carbohydrate in g. Round only the final totals, to one decimal. 5. For the walk call `walking_calorie(weight_kg, speed, duration_minutes, incline)`. `speed` is slow (2.0 mph), moderate (3.0), brisk (3.5), fast (4.0) or very-fast (4.5); `incline` is flat (0%), slight (2%), moderate (5%) or steep (10%). 6. Take `calories` (gross energy of the walk). If the user asks for energy above resting, take `netCalories` instead and say so. 7. Subtract the walk's energy from the meal's energy (meal minus walk) and keep the sign. 8. Report the meal totals, the walk's energy with which figure was used (gross or net), and the difference, in kcal. ## Mistakes this prevents - Using cooked-weight values for rice, pasta, oats or lentils listed dry (or the reverse): the figures below for these foods are per 100 g raw or dry, and the dataset holds no cooked items. - Using remembered label values instead of the USDA figures below. - Counting a walk at a flat MET: the slope adds energy, and the function carries the 2024 Compendium METs and the ACSM slope term. - Mixing gross and net walking energy: gross includes the energy a body burns at rest. ## Tell the user - Food values are USDA FoodData Central Foundation Foods figures per 100 g, rounded to three significant figures; a given product or recipe can differ. - Walking energy is a population-average estimate; an individual can differ by 20% or more. ## Figures: Energy and macronutrients of common foods - Apples, gala, with skin, raw, per 100 g: 54.9 kcal (Atwater specific factors), 0.133 g protein, 0.15 g fat, 14.8 g carbohydrate, 2.11 g fibre, 11.8 g sugars, 0.279 mg sodium; FoodData Central ID 1750341. - Avocado, Hass, peeled, raw, per 100 g: 206 kcal (Atwater specific factors), 1.81 g protein, 20.3 g fat, 8.32 g carbohydrate, 0 mg sodium; FoodData Central ID 2710824. - Bananas, ripe and slightly ripe, raw, per 100 g: 97 kcal (energy as reported), 0.74 g protein, 0.29 g fat, 23 g carbohydrate, 1.7 g fibre, 15.8 g sugars, 0 mg sodium; FoodData Central ID 1105314. - Beef, ground, 90% lean meat / 10% fat, raw, per 100 g: 190 kcal (Atwater specific factors), 18.2 g protein, 12.8 g fat, 0 g carbohydrate, 61.6 mg sodium; FoodData Central ID 2514743. - Blueberries, raw, per 100 g: 57.4 kcal (Atwater specific factors), 0.703 g protein, 0.306 g fat, 14.6 g carbohydrate, 9.36 g sugars, 0 mg sodium; FoodData Central ID 2346411. - Broccoli, raw, per 100 g: 31 kcal (energy as reported), 2.57 g protein, 0.34 g fat, 6.27 g carbohydrate, 2.4 g fibre, 1.4 g sugars, 36 mg sodium; FoodData Central ID 747447. - Carrots, mature, raw, per 100 g: 45 kcal (Atwater specific factors), 0.941 g protein, 0.351 g fat, 10.3 g carbohydrate, 3.1 g fibre, 86.6 mg sodium; FoodData Central ID 2258586. - Cheese, cheddar, per 100 g: 408 kcal (energy as reported), 23.3 g protein, 34 g fat, 2.44 g carbohydrate, 0.33 g sugars, 654 mg sodium; FoodData Central ID 328637. - Chicken, breast, boneless, skinless, raw, per 100 g: 112 kcal (Atwater specific factors), 22.5 g protein, 1.93 g fat, 0 g carbohydrate, 65.8 mg sodium; FoodData Central ID 2646170. - Eggs, Grade A, Large, egg whole, per 100 g: 148 kcal (energy as reported), 12.4 g protein, 9.96 g fat, 0.96 g carbohydrate, 0 g fibre, 0.2 g sugars, 129 mg sodium; FoodData Central ID 748967. - Fish, salmon, Atlantic, farm raised, raw, per 100 g: 203 kcal (Atwater specific factors), 20.3 g protein, 13.1 g fat, 0 g carbohydrate, 49.5 mg sodium; FoodData Central ID 2684441. - Lentils, dry, per 100 g: 351 kcal (Atwater specific factors), 23.6 g protein, 1.92 g fat, 62.2 g carbohydrate, 0 mg sodium; FoodData Central ID 2644283. - Milk, reduced fat, fluid, 2% milkfat, with added vitamin A and vitamin D, per 100 g: 50 kcal (energy as reported), 3.36 g protein, 1.9 g fat, 4.9 g carbohydrate, 4.89 g sugars, 39 mg sodium; FoodData Central ID 746778. - Milk, whole, 3.25% milkfat, with added vitamin D, per 100 g: 60 kcal (energy as reported), 3.27 g protein, 3.2 g fat, 4.63 g carbohydrate, 4.81 g sugars, 38 mg sodium; FoodData Central ID 746782. - Nuts, almonds, whole, raw, per 100 g: 584 kcal (Atwater specific factors), 21.5 g protein, 51.1 g fat, 20 g carbohydrate, 10.8 g fibre, 0 mg sodium; FoodData Central ID 2346393. - Oats, whole grain, rolled, old fashioned, per 100 g: 379 kcal (Atwater specific factors), 13.5 g protein, 5.89 g fat, 68.7 g carbohydrate, 0.668 mg sodium; FoodData Central ID 2346396. - Onions, yellow, raw, per 100 g: 38 kcal (energy as reported), 0.83 g protein, 0.05 g fat, 8.61 g carbohydrate, 1.9 g fibre, 5.82 g sugars, 1 mg sodium; FoodData Central ID 790646. - Oranges, raw, navels, per 100 g: 47 kcal (energy as reported), 0.91 g protein, 0.15 g fat, 11.8 g carbohydrate, 2 g fibre, 8.57 g sugars, 9 mg sodium; FoodData Central ID 746771. - Pasta, dry, enriched, spaghetti, per 100 g: 371 kcal (Atwater general factors), 15.1 g protein, 1.85 g fat, 73.5 g carbohydrate, 4.2 g fibre, 10.5 g sugars, 2.41 mg sodium; FoodData Central ID 2758998. - Peanut butter, Creamy, per 100 g: 639 kcal (Atwater general factors), 25.6 g protein, 50.8 g fat, 19.6 g carbohydrate, 5.18 g fibre; FoodData Central ID 2758989. - Potatoes, russet, without skin, raw, per 100 g: 81 kcal (Atwater specific factors), 2.27 g protein, 0.36 g fat, 17.8 g carbohydrate, 0.526 g sugars, 2.74 mg sodium; FoodData Central ID 2346401. - Rice, brown, long grain, unenriched, raw, per 100 g: 368 kcal (Atwater specific factors), 7.25 g protein, 3.31 g fat, 76.7 g carbohydrate, 3.02 g fibre, 0 mg sodium; FoodData Central ID 2512380. - Rice, white, long grain, unenriched, raw, per 100 g: 370 kcal (Atwater specific factors), 7.04 g protein, 1.03 g fat, 80.3 g carbohydrate, 0.149 g fibre, 0.462 mg sodium; FoodData Central ID 2512381. - Spinach, mature, per 100 g: 21.6 kcal (Atwater specific factors), 2.91 g protein, 0.604 g fat, 2.64 g carbohydrate, 1.59 g fibre, 107 mg sodium; FoodData Central ID 1999633. - Strawberries, raw, per 100 g: 32.7 kcal (Atwater specific factors), 0.641 g protein, 0.22 g fat, 7.96 g carbohydrate, 4.86 g sugars, 0 mg sodium; FoodData Central ID 2346409. - Sweet potatoes, orange flesh, without skin, raw, per 100 g: 77.4 kcal (Atwater specific factors), 1.58 g protein, 0.375 g fat, 17.3 g carbohydrate, 6.06 g sugars, 0 mg sodium; FoodData Central ID 2346404. - Tomato, roma, per 100 g: 19 kcal (Atwater specific factors), 0.696 g protein, 0.425 g fat, 3.84 g carbohydrate, 0.971 g fibre, 0 mg sodium; FoodData Central ID 1999634. - Tuna, ahi or yellowfin, frozen, wild caught, per 100 g: 102 kcal (Atwater general factors), 24.7 g protein, 0.388 g fat, -0.104 g carbohydrate, 94.4 mg sodium; FoodData Central ID 2747673. - Turkey, ground, 93% lean/ 7% fat, raw, per 100 g: 158 kcal (Atwater specific factors), 17.3 g protein, 9.59 g fat, 0 g carbohydrate, 80.2 mg sodium; FoodData Central ID 2514747. - Yogurt, Greek, plain, nonfat, per 100 g: 61 kcal (energy as reported), 10.3 g protein, 0.37 g fat, 3.64 g carbohydrate, 3.27 g sugars, 36 mg sodium; FoodData Central ID 330137. Sources read 4 Dec 2026. Current figures: https://mysi.dev/food-nutrients-common/ ## The code Copy each function into your Python tool. Run its check first. ### Walking calories (https://mysi.dev/walking-calorie/) ```python """Walking calories: energy burned on a walk from body weight, a speed band, the time and the slope. The level-walking MET comes from the 2024 Adult Compendium of Physical Activities; the slope adds the grade term of the ACSM walking equation. Inputs: weight_kg (1 to 300), speed (slow, moderate, brisk, fast, very-fast; default moderate), duration_minutes (1 to 600, default 30), incline (flat, slight, moderate, steep; default flat). Returns: calories and netCalories (kcal, 1 decimal), caloriesPerMinute (2 decimals), met (2 decimals), inclineMultiplier (3 decimals), durationHours (2 decimals). mysi, Walking calories, mysi.dev/walking-calorie, version 1, changed 2026-12-04. MIT. """ import math def _walking_calorie_num(name, value, low, high): if isinstance(value, bool) or not isinstance(value, (int, float)) or not low <= value <= high: raise ValueError(f"{name} must be a number from {low} to {high}") return float(value) def _walking_calorie_pick(name, value, table): if not isinstance(value, str) or value not in table: raise ValueError(f"{name} must be one of: {', '.join(table)}") return table[value] def _walking_calorie_round(value, digits): return math.floor(value * 10 ** digits + 0.5) / 10 ** digits # half up, as the old engine def walking_calorie(weight_kg, speed="moderate", duration_minutes=30, incline="flat"): w = _walking_calorie_num("weight_kg", weight_kg, 1, 300) minutes = _walking_calorie_num("duration_minutes", duration_minutes, 1, 600) # speed band: (mph, level MET), 2024 Adult Compendium codes 17152, 17190, 17200, 17220, 17230 mph, level_met = _walking_calorie_pick("speed", speed, { "slow": (2.0, 2.8), "moderate": (3.0, 3.8), "brisk": (3.5, 4.8), "fast": (4.0, 5.5), "very-fast": (4.5, 7.0)}) grade = _walking_calorie_pick("incline", incline, { "flat": 0.0, "slight": 0.02, "moderate": 0.05, "steep": 0.10}) v = mph * 1609.344 / 60 # metres per minute met = level_met + 1.8 * v * grade / 3.5 # ACSM walking grade term, 3.5 ml/kg/min = 1 MET hours = minutes / 60 calories = met * w * hours # 1 MET = 1 kcal per kg per hour return { "calories": _walking_calorie_round(calories, 1), "netCalories": _walking_calorie_round((met - 1) * w * hours, 1), "caloriesPerMinute": _walking_calorie_round(calories / minutes, 2), "met": _walking_calorie_round(met, 2), "inclineMultiplier": _walking_calorie_round(met / level_met, 3), "durationHours": _walking_calorie_round(hours, 2), } WALKING_CALORIE_CASES = [ ({"weight_kg": 70, "speed": "brisk", "duration_minutes": 30, "incline": "slight"}, {"calories": 201.8, "netCalories": 166.8, "met": 5.77}), ({"weight_kg": 60, "speed": "moderate", "duration_minutes": 60, "incline": "flat"}, {"calories": 228.0, "netCalories": 168.0, "met": 3.8}), ({"weight_kg": 80, "speed": "slow", "duration_minutes": 45, "incline": "steep"}, {"calories": 333.5, "netCalories": 273.5, "met": 5.56}), ] def walking_calorie_check(tolerance=1e-3): for given, want in WALKING_CALORIE_CASES: got = walking_calorie(**given) for name, value in want.items(): close = abs(got[name] - value) <= tolerance * max(1, abs(value)) assert close, (name, got[name], value) return "ok" if __name__ == "__main__": import json, sys walking_calorie_check() given = dict(a.split("=", 1) for a in sys.argv[1:] if "=" in a) js = lambda v: v.lstrip("-")[:1].isdigit() or v[:1] in '[{".' or v in ("true", "false", "null") given = {k: json.loads(v) if js(v) else v for k, v in given.items()} if given: print(json.dumps(walking_calorie(**given))) ``` Cite as: mysi, Meal energy and macros against a walk, mysi.dev/meal-energy-and-macros, version 1, changed 2026-12-04. MIT.