Macro Nutrient

Lester Vecsey

Overview

The goal here is to create a software program to assist with the collection of nutrition label information (per serving), into individual meals.

Example nutrition file

You can create nutrition files such as breakfast.csv, recovery_meal.csv, lunch.csv, and dinner.csv.

Use an editor such as emacs or Libreoffice Calc.

breakfast.csv

Food Item, Carb Grams, Protein Grams, Fat Grams
Eggs (1 serving), 1.6, 6, 5
Banana (1 servings), 28, 1, 0

Python calculation

Next, a Python program will show some nutriant stats such as calorie count for the meal (based on the provided spreadsheet file), and the percentages of carbs, protein, and fat.

Nutrient Calories for each gram
Carbohydrates 3.75
Protein 4
Fat 9

The program can output the following:

Using the program

In general, for most meals you should end up with something like 50% to 60% carbs. Protein can be around 15% and Fat around 30%.

So basically each meal should have nutrients without any extremes, favoring carbs, then fats, then protein, and at the end of the day you should have the percentages in those same ratios.

Basically you can have a subfolder called combined and created a dated .csv file, which is the combined entries for all your meals for the day.

Run the nutrition stats program and you should be good to go.

Daily Nutrition

I also encourage the creation of a Daily Nutrition document that goes over your current meal plan. Just paste in the nutrition summary for each meal, using the program output.

Code Listing

#!/usr/bin/python3

import sys
import os

import pandas as pd

def show_results(carb, protein, fat):

    print(f"{carb:.2f}" + ', ' + f"{protein:.2f}" + ', ' + f"{fat:.2f}")

    calories = [ (3.75 * carb), (4 * protein), (9 * fat) ]
    
    total_calories = calories[0] + calories[1] + calories[2]

    print('Total Calories: ' + str(total_calories))
    
    percents = [ calories[0] / total_calories, calories[1] / total_calories, calories[2] / total_calories ]
    
    print(f"{100.0*percents[0]:02.2f}%" + ', ' + f"{100.0*percents[1]:02.2f}%" + ', ' + f"{100.0*percents[2]:02.2f}%")

def main(foodlist_csv):

    df = pd.read_csv(foodlist_csv)

    carb = 0
    protein = 0
    fat = 0
    
    for ind in df.index:
        carb += df.iloc[:, 1][ind]
        protein += df.iloc[:, 2][ind]
        fat += df.iloc[:, 3][ind]        

    show_results(carb, protein, fat)        
        
if __name__ == '__main__':

    args = sys.argv[1:]
    
    foodlist_csv = args[0]

    main(foodlist_csv)

License

GPLv3