Skip to content

ald0405/whoop-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

77 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ AI-Powered Health Data Platform

Python 3.8+ License: MIT OpenAI LangGraph

A comprehensive AI-powered health data platform that integrates WHOOP and Withings devices with a conversational agent interface. Chat with your health data using natural language queries!

✨ Features

  • πŸ€– AI Health Data Agent - Chat with your data using natural language
  • πŸ“Š Comprehensive Data Integration - WHOOP + Withings APIs
  • 🎾 Sport-Specific Analysis - Tennis, running, and general workout tracking
  • πŸ“ˆ Trend Analysis - Weight, recovery, sleep patterns over time
  • 🌐 REST API - Complete FastAPI backend with documentation
  • πŸ’¬ Web Chat Interface - Beautiful Gradio-powered chat UI

Project Structure

whoop-data/
β”œβ”€β”€ whoopdata/               # Main package directory
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ start.py              # Main application launcher
β”‚   β”œβ”€β”€ etl.py                # ETL pipeline logic
β”‚   β”œβ”€β”€ database.py           # Database setup utilities  
β”‚   β”œβ”€β”€ utils.py              # Database loading utilities
β”‚   β”œβ”€β”€ model_transformation.py # Data transformation functions
β”‚   β”œβ”€β”€ agent/                # πŸ€– AI Agent System
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ graph.py          # LangGraph agent orchestration
β”‚   β”‚   β”œβ”€β”€ nodes.py          # Agent nodes (supervisor, tools)
β”‚   β”‚   β”œβ”€β”€ tools.py          # Health data tools for agent
β”‚   β”‚   β”œβ”€β”€ schemas.py        # Agent state and configuration
β”‚   β”‚   └── settings.py       # Agent configuration
β”‚   β”œβ”€β”€ api/                  # FastAPI routes
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ recovery_routes.py
β”‚   β”‚   β”œβ”€β”€ sleep_routes.py
β”‚   β”‚   β”œβ”€β”€ workout_routes.py
β”‚   β”‚   └── withings_routes.py
β”‚   β”œβ”€β”€ models/               # SQLAlchemy ORM models
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── models.py
β”‚   β”œβ”€β”€ clients/              # API clients for WHOOP and Withings
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ whoop_client.py
β”‚   β”‚   └── withings_client.py
β”‚   β”œβ”€β”€ schemas/              # Pydantic schemas
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ recovery.py
β”‚   β”‚   β”œβ”€β”€ sleep.py
β”‚   β”‚   └── workout.py
β”‚   β”œβ”€β”€ crud/                 # Database CRUD operations
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ recovery.py
β”‚   β”‚   β”œβ”€β”€ sleep.py
β”‚   β”‚   └── workout.py
β”‚   β”œβ”€β”€ utils/                # Utility functions
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ db_loader.py      # Database loading utilities
β”‚   β”‚   β”œβ”€β”€ date_filters.py   # Date filtering utilities
β”‚   β”‚   └── matplotlib_config.py # Chart configuration
β”‚   β”œβ”€β”€ tests/                # Test files
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── test_withings.py
β”‚   └── analysis/             # Analysis scripts and notebooks
β”‚       β”œβ”€β”€ __init__.py
β”‚       └── ...
β”œβ”€β”€ scripts/                  # Helper scripts
β”‚   β”œβ”€β”€ create_tables.py      # Database table creation
β”‚   └── run_etl.py           # Standalone ETL runner
β”œβ”€β”€ chat_app.py              # πŸ’¬ Gradio chat interface
β”œβ”€β”€ start_health_chat.py     # πŸš€ Complete system launcher
β”œβ”€β”€ main.py                   # FastAPI application entry point
β”œβ”€β”€ run_app.py               # Complete data pipeline + API server
β”œβ”€β”€ app.py                    # Main FastAPI application
β”œβ”€β”€ setup.py                 # Package configuration
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ .env                     # Environment variables
β”œβ”€β”€ AGENT_PERSONALITY_GUIDE.md # AI agent coaching style guide
└── README.md

πŸš€ Quick Start Guide

Step 1: Install Dependencies

# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install required packages
pip install -r requirements.txt

Step 2: Set up Environment Variables

Create a .env file with your API credentials:

# WHOOP OAuth 2.0 (Browser-based authentication - no username/password needed!)
WHOOP_CLIENT_ID=your_whoop_client_id
WHOOP_CLIENT_SECRET=your_whoop_client_secret

# Withings OAuth credentials  
WITHINGS_CLIENT_ID=your_withings_client_id
WITHINGS_CLIENT_SECRET=your_withings_client_secret
WITHINGS_CALLBACK_URL=http://localhost:8766/callback

# OpenAI API for AI agent functionality
OPENAI_API_KEY=your_openai_api_key

πŸ“ Note: WHOOP uses OAuth 2.0 browser authentication - you'll be redirected to login through their website when needed.

Step 3: Initialize Database & Load Data

The system automatically creates the database and loads your health data:

# Complete setup: Creates database + Loads fresh data + Starts API server
python run_app.py

This will:

  1. πŸ“¦ Create database tables (SQLite in ./db/whoop.db)
  2. πŸ” Authenticate with WHOOP (browser popup for OAuth)
  3. πŸ” Authenticate with Withings (browser popup for OAuth)
  4. πŸ“Š Load your health data (recovery, workouts, sleep, weight, etc.)
  5. 🌐 Start the API server (http://localhost:8000)

Step 4: Start the AI Chat Interface

🎯 Option A: Complete System (Recommended)

# Launches both API server (8000) + Chat interface (7860)
python start_health_chat.py

πŸ’¬ Option B: Chat Interface Only

# Just the chat interface (requires API server running separately)
python chat_app.py

Step 5: Start Chatting with Your Health Data! πŸŽ‰

πŸ€– AI Chat Interface: http://localhost:7860

Example Questions to Try:

  • "Show me my tennis workouts from 2025"
  • "What's my weight trend over the last 30 days?"
  • "How has my recovery been this month?"
  • "Get my latest sleep data and analyze my patterns"
  • "Show me my running performance with TRIMP scores"

🌐 REST API Access:

πŸ“Š Data Pipeline Details

What Gets Loaded

When you run python run_app.py, the system loads:

WHOOP Data:

  • πŸ“Š Recovery scores (HRV, RHR, sleep quality)
  • πŸ‹οΈ Workout data (strain, heart rate zones, sports)
  • 😴 Sleep tracking (stages, efficiency, duration)

Withings Data:

  • βš–οΈ Weight & body composition (BMI, fat ratio, muscle mass)
  • πŸ’— Heart rate & blood pressure (systolic, diastolic)

Database Setup

The system automatically:

  1. Creates SQLite database at ./db/whoop.db
  2. Sets up all required tables
  3. Handles data transformations and relationships
  4. Manages duplicate prevention

Token Management

  • WHOOP: OAuth tokens auto-refresh, occasional re-authentication needed
  • Withings: Long-lived tokens with automatic refresh (rarely need to re-login)
  • Tokens stored securely in hidden files with proper permissions

API Endpoints

WHOOP Data

  • GET /recovery - Recovery scores and metrics
  • GET /recovery/latest - Most recent recovery
  • GET /workout - Workout data and strain
  • GET /workout/latest - Most recent workout
  • GET /sleep - Sleep performance data
  • GET /sleep/latest - Most recent sleep

Withings Data

  • GET /withings/weight - Weight and body composition
  • GET /withings/weight/latest - Most recent weight
  • GET /withings/weight/stats - Weight statistics
  • GET /withings/heart-rate - Heart rate and blood pressure
  • GET /withings/heart-rate/latest - Most recent heart rate
  • GET /withings/summary - Withings data summary

Development

Testing Withings Integration

python whoopdata/tests/test_withings.py

Running ETL Pipeline Only

python scripts/run_etl.py

Creating Database Tables

python scripts/create_tables.py

WHOOP Data Summary

Physiological Cycles

  • Activity is referenced in the context of a Physiological Cycle (Cycle for short).
  • Current Cycle: Only has a Start Time. Past Cycles have both start and end times.
  • A physiological day on WHOOP begins when you fall asleep one night and ends when you fall asleep the following night.

Recovery

  • Daily measure of body preparedness to perform.
  • Recovery score: Percentage between 0 - 100% calculated in the morning.
  • Calculated using previous day's data including RHR, HRV, respiratory rate, sleep quality, etc.
  • GREEN (67-100%): Well recovered and primed to perform.
  • YELLOW (34-66%): Maintaining and ready for moderate strain.
  • RED (0-33%): Indicates the need for rest.

Sleep Tracking

  • Tracks sleep duration and stages: Light, REM, and Deep sleep.
  • Calculates sleep need based on Sleep Debt and previous day's activity.

Strain

Workout Tracking

  • WHOOP tracks workouts and measures accumulated Strain over each workout.

Documentation

Comprehensive documentation is available in the docs/ directory:

For API documentation, visit http://localhost:8000/docs after starting the application.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Packages

No packages published