Skip to content

Edward-Chin/MealPlanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MealPlanner

MealPlanner is a personal scheduling tool that calculates optimal times for your meals and workouts based on your daily routine and biological rhythms. Instead of guessing when to eat or dealing with the discomfort of poor timing, let science do the planning for you.

Why Use MealPlanner?

Timing your meals properly has significant health benefits:

  • Reduces hunger by spacing meals at intervals that match your body's natural digestive cycles
  • Prevents workout nausea by ensuring enough time between eating and exercising
  • Improves sleep quality by avoiding late-night eating that can cause acid reflux and disrupt rest
  • Eliminates decision fatigue by providing a clear, optimized schedule you can follow daily

How It Works

MealPlanner uses research-backed biological principles to determine ideal time gaps between activities. The algorithm works by:

  1. Defining ideal gap weights based on chronobiological research - representing the optimal proportional duration of gaps between events (not including event durations themselves):

    • Wake → Breakfast gap: Weight 1.0 (~60 min for cortisol stabilization)
    • Breakfast → Lunch gap: Weight 4.5 (~270 min for cognitive peak and glucose homeostasis)
    • Lunch → Workout gap: Weight 3.0 (~180 min for gastric emptying and hemodynamic safety)
    • Workout → Dinner gap: Weight 1.5 (~90 min for anabolic window and parasympathetic return)
    • Dinner → Sleep gap: Weight 4.0 (~240 min for GERD prevention and sleep architecture)
  2. Calculating available gap time by taking your total awake time and subtracting all event durations (breakfast, lunch, workout, dinner)

  3. Distributing gaps proportionally based on the ideal weights while fitting your actual schedule constraints

Key insight: Gaps are measured from the end of one event to the start of the next. This ensures activities never overlap and that timing recommendations account for how long each activity actually takes.

Quick Start Guide

  1. Edit constraints.txt with your known schedule information, then save the file (see instructions below)
  2. Run the tool using the instructions below for your operating system
  3. Check schedule.txt for your complete optimized schedule with all times filled in

What Are .txt Files?

The .txt extension means "text file"—these are simple files that contain plain text without any special formatting (no bold, italics, or colors). Think of them like a basic notepad.

How to open and edit .txt files:

  • On Mac: Double-click the file to open it in TextEdit (or right-click → Open With → TextEdit)
  • On Windows: Double-click the file to open it in Notepad (or right-click → Open With → Notepad)
  • Alternative: You can also use any text editor like Visual Studio Code, Sublime Text, or Atom if you have them installed.

After you make changes to a .txt file, you need to save it so your edits are stored.

How to Fill Out constraints.txt

Open constraints.txt in any text editor and fill in your schedule information following these rules:

Important: After editing, remember to save the file!

  • On Mac: Press Cmd + S (⌘ + S) or go to File → Save
  • On Windows/Linux: Press Ctrl + S or go to File → Save

Required Fields

  • wake - The time you wake up (e.g., 7:15 AM)
  • sleep - The time you go to sleep (e.g., 11:20 PM)

Event Fields

For each event (breakfast, lunch, workout, dinner), you have three related fields:

  • [event]Start - When the event begins
  • [event]Duration - How long it lasts (in minutes)
  • [event]End - When the event finishes

Valid Combinations

For each event, you can provide:

  • Only duration - Let the tool calculate optimal start and end times
  • start + end - The tool will calculate duration
  • start + duration - The tool will calculate end time
  • duration + end - The tool will calculate start time

Invalid Combinations

  • Only start - Not enough information
  • Only end - Not enough information
  • All three blank - Must provide at least some information
  • All three filled - Over-constrained (just pick two!)

Example constraints.txt

wake: 7:00 AM
breakfastStart: 
breakfastDuration: 20
breakfastEnd: 
lunchStart: 
lunchDuration: 30
lunchEnd: 
workoutStart: 
workoutDuration: 45
workoutEnd: 
dinnerStart: 
dinnerDuration: 40
dinnerEnd: 
sleep: 11:00 PM

In this example, you're only specifying how long each activity takes, and the tool will calculate all the optimal start and end times.

Running the Tool

On Mac/Linux

  1. Navigate to the MealPlanner directory in Terminal:

    cd /path/to/MealPlanner
  2. First time only: Make the script executable:

    chmod +x ./main.sh
  3. Run the program:

    ./main.sh

On Windows

  1. Install Swift for Windows (one-time setup):

  2. Navigate to the MealPlanner directory in Command Prompt or PowerShell:

    cd C:\path\to\MealPlanner
    
  3. Run the program:

    swift main.swift
    

    Note: Windows users don't need the chmod step or main.sh file—just run Swift directly!

Viewing Your Schedule

After running the tool, open schedule.txt to see your complete optimized schedule. All the blank fields from your input will now be filled with calculated optimal times.

Example schedule.txt Output

wake: 7:00 AM
breakfastStart: 7:45 AM
breakfastDuration: 20
breakfastEnd: 8:05 AM
lunchStart: 12:35 PM
lunchDuration: 30
lunchEnd: 1:05 PM
workoutStart: 4:35 PM
workoutDuration: 45
workoutEnd: 5:20 PM
dinnerStart: 6:20 PM
dinnerDuration: 40
dinnerEnd: 7:00 PM
sleep: 11:00 PM

Understanding the Algorithm

The optimization algorithm (found in main.swift lines 39-67) works in four steps:

  1. Define Ideal Biological Intervals - Uses research-based time gaps between activities (45 min after waking, 4.5 hours between meals, etc.)

  2. Calculate Available Time - Determines how much time you have awake (sleep time minus wake time) and subtracts the time spent on fixed activities

  3. Calculate Scaling Factor - Proportionally adjusts the ideal gaps to fit your actual schedule while maintaining biological ratios. The scale factor has a minimum of 0.5 to prevent unsafe compression (like eating immediately before swimming)

  4. Generate Schedule - Applies the scaled gaps to calculate all start and end times, working forward from your wake time through each activity

This approach ensures that even if your schedule is packed or relaxed, the relative proportions between activities remain scientifically sound.

Tips for Best Results

  • Be consistent with your wake and sleep times—your body thrives on routine
  • If you have fixed commitments (like lunch at work), enter those specific times in constraints.txt
  • Adjust durations to match your actual eating and workout speeds
  • Re-run the tool whenever your schedule changes to get a new optimized plan

Troubleshooting

  • "File not found" error: Make sure you're in the MealPlanner directory when running the command
  • Swift not found on Windows: Install Swift from the official website
  • Times seem off: Double-check that you entered times in 12-hour format with AM/PM
  • Durations are 0: If you leave duration blank without providing start and end, it defaults to 0

Note: This tool provides general guidance based on biological research. Individual needs may vary. Consult with healthcare professionals for personalized dietary and exercise advice.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published