{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "63f43af5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b0ee2af1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Smoothed columns created:\n",
      "['VO2(ml/min)_smoothed', 'VCO2(ml/min)_smoothed', 'HR(bpm)_smoothed', 'VT(l)_smoothed', 'BF(bpm)_smoothed', 'VE(l/min)_smoothed', 'VO2 Pulse_smoothed', 'VO2 Breath_smoothed', 'CHO_smoothed', 'FAT_smoothed']\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_393367/3054964805.py:3: FutureWarning: errors='ignore' is deprecated and will raise in a future version. Use to_numeric without passing `errors` and catch exceptions explicitly instead\n",
      "  df = df.apply(pd.to_numeric, errors='ignore')\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv('data/Pnoe_20250729_1550-Moran_Keirstyn.csv', delimiter=';')\n",
    "# Convert all columns to numeric where possible, coercing errors to NaN\n",
    "df = df.apply(pd.to_numeric, errors='ignore')\n",
    "df['VO2 Pulse'] = df['VO2(ml/min)'] / df['HR(bpm)']  # VO2 Pulse in mL/beat\n",
    "df['VO2 Breath'] = df['VO2(ml/min)'] / df['BF(bpm)']  # VO2 per Breath in mL/breath\n",
    "df['CHO'] = df['EE(kcal/min)'] * df['CARBS(%)']/100\n",
    "df['FAT'] = df['EE(kcal/min)'] * df['FAT(%)']/100\n",
    "# Smooth key columns using rolling window\n",
    "window_size = 10\n",
    "\n",
    "# List of columns to smooth\n",
    "columns_to_smooth = ['VO2(ml/min)', 'VCO2(ml/min)', 'HR(bpm)', 'VT(l)', 'BF(bpm)', 'VE(l/min)', 'VO2 Pulse', 'VO2 Breath', 'CHO', 'FAT']\n",
    "\n",
    "# Apply smoothing to each column\n",
    "for col in columns_to_smooth:\n",
    "    if col in df.columns:\n",
    "        df[f'{col}_smoothed'] = df[col].rolling(window=window_size).mean()\n",
    "\n",
    "print(\"Smoothed columns created:\")\n",
    "print([col for col in df.columns if '_smoothed' in col])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fbd292c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "22.369999999999997\n"
     ]
    }
   ],
   "source": [
    "print(df['VO2 Pulse'].max())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ef8bc7ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 72344 characters]",
      "text/plain": [
       "<Figure size 1800x500 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "first_unique_phase = df.drop_duplicates(subset='PHASE')\n",
    "phase_times = first_unique_phase['T(sec)'].tolist()\n",
    "\n",
    "plt.figure(figsize=(18, 5))\n",
    "ax1 = plt.subplot()\n",
    "\n",
    "\n",
    "# Plot VT with step-like appearance\n",
    "line1 = sns.lineplot(data=df, x='T(sec)', y='VT(l)_smoothed', label='VT (L)')\n",
    "ax1.set_xlabel('Time (sec)')\n",
    "ax1.set_ylabel('VT (L)')\n",
    "ax1.set_title('Respiratory')\n",
    "ax1.grid(True, alpha=0.1)\n",
    "ax1.set_ylim(0, 2.5)\n",
    "\n",
    "# Plot speed as step function on secondary y-axis\n",
    "ax2 = ax1.twinx()\n",
    "ax1.set_xticks(np.arange(0, df['T(sec)'].max() + 200, 200))\n",
    "line2 = sns.lineplot(data=df, x='T(sec)', y='Speed', color='green', ax=ax2, \n",
    "             drawstyle='steps-post', linewidth=2, label='Speed')\n",
    "ax2.set_ylabel('Speed')\n",
    "ax2.set_ylim(0, 9)\n",
    "\n",
    "# Remove default legends first\n",
    "ax1.get_legend().remove()\n",
    "ax2.get_legend().remove()\n",
    "\n",
    "# Combine legends from both axes in the top left\n",
    "lines1, labels1 = ax1.get_legend_handles_labels()\n",
    "lines2, labels2 = ax2.get_legend_handles_labels()\n",
    "ax1.legend(lines1 + lines2, labels1 + labels2, loc='upper left')\n",
    "\n",
    "# Add colored background regions if you have phase information\n",
    "ax1.axvspan(0, phase_times[1], alpha=0.2, color='lightblue')\n",
    "ax1.axvspan(phase_times[1], phase_times[2], alpha=0.2, color='purple')\n",
    "ax1.axvspan(phase_times[2], phase_times[3], alpha=0.2, color='lightgreen')\n",
    "ax1.axvspan(phase_times[3], df['T(sec)'].max(), alpha=0.2, color='blue')\n",
    "\n",
    "plt.savefig('graphs/respiratory.png')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "06244aa2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 111948 characters]",
      "text/plain": [
       "<Figure size 1500x800 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "# Group by speed and calculate mean for numeric columns only\n",
    "speed_groups = df.groupby('Speed').mean(numeric_only=True).round(1)\n",
    "\n",
    "# Drop the first and last row from speed_groups\n",
    "speed_groups = speed_groups.iloc[1:-1]\n",
    "\n",
    "# Filter data to only include speeds in the desired range\n",
    "filtered_data = speed_groups[(speed_groups.index >= 3.5) & (speed_groups.index <= 7.5)]\n",
    "\n",
    "# Create figure with specific size\n",
    "plt.figure(figsize=(15, 8))\n",
    "plt.style.use('default')\n",
    "\n",
    "# Create stage labels and positions\n",
    "stage_labels = [f'Stage {i}' for i in range(1, len(filtered_data) + 1)]\n",
    "x_positions = np.arange(len(filtered_data))\n",
    "\n",
    "# Calculate fat and carbs energy expenditure from percentages\n",
    "fat_ee = filtered_data['EE(kcal/min)'] * filtered_data['FAT(%)'] / 100\n",
    "carbs_ee = filtered_data['EE(kcal/min)'] * filtered_data['CARBS(%)'] / 100\n",
    "\n",
    "# Create the main axis for the stacked bars\n",
    "ax1 = plt.gca()\n",
    "\n",
    "# Create stacked bar chart with colors\n",
    "bars_fat = ax1.bar(x_positions, fat_ee, color='#1f77b4', alpha=0.8, width=0.6, label='Fat')\n",
    "bars_carbs = ax1.bar(x_positions, carbs_ee, bottom=fat_ee, color='#ff7f0e', alpha=0.8, width=0.6, label='Carbs')\n",
    "\n",
    "# Set labels and formatting for primary axis\n",
    "ax1.set_xlabel('', fontsize=12)\n",
    "ax1.set_ylabel('Fuel (kcal/min)', fontsize=12)\n",
    "ax1.set_ylim(0, 20)\n",
    "\n",
    "# Add individual values on each bar segment\n",
    "for i, (fat_val, carb_val, total_val) in enumerate(zip(fat_ee, carbs_ee, filtered_data['EE(kcal/min)'])):\n",
    "    if fat_val > 0.3:  # Fat value\n",
    "        ax1.text(i, fat_val/2, f'{fat_val:.1f}', ha='center', va='center',\n",
    "                 fontsize=9, fontweight='bold', color='white')\n",
    "    if carb_val > 0.3:  # Carbs value\n",
    "        ax1.text(i, fat_val + carb_val/2, f'{carb_val:.1f}', ha='center', va='center',\n",
    "                 fontsize=9, fontweight='bold', color='white')\n",
    "    # Total EE\n",
    "    ax1.text(i, total_val + 0.5, f'{total_val:.1f} kcal', ha='center', va='bottom',\n",
    "             fontsize=10, fontweight='bold', color='black')\n",
    "\n",
    "# Add speed labels below x-axis\n",
    "for i, speed in enumerate(filtered_data.index):\n",
    "    ax1.text(i, -1.5, f'{speed:.1f} mph', ha='center', va='top', fontsize=9)\n",
    "    ax1.text(i, -2.8, f'{speed*1.609:.1f} min/km', ha='center', va='top', fontsize=8, color='gray')\n",
    "\n",
    "# Create secondary y-axis for heart rate\n",
    "ax2 = ax1.twinx()\n",
    "\n",
    "# Plot heart rate line (no manual offset)\n",
    "hr_line = ax2.plot(x_positions, filtered_data['HR(bpm)'],\n",
    "                   marker='o', linewidth=3, markersize=8, color='red', label='Heart Rate')\n",
    "\n",
    "# Set heart rate axis formatting\n",
    "ax2.set_ylabel('Heart Rate (bpm)', fontsize=12, color='red')\n",
    "ax2.tick_params(axis='y', labelcolor='red')\n",
    "\n",
    "# Dynamically adjust HR axis to float above bars\n",
    "max_bar_height = max(filtered_data['EE(kcal/min)'])\n",
    "ax2.set_ylim(0, 220)  # ensures HR line is above bars\n",
    "\n",
    "\n",
    "# Add HR values above the points\n",
    "for i, hr in enumerate(filtered_data['HR(bpm)']):\n",
    "    ax2.text(i, hr + 10, f'{int(hr)}bpm', ha='center', va='bottom',\n",
    "             fontsize=10, fontweight='bold', color='red')\n",
    "\n",
    "# Set x-axis formatting\n",
    "ax1.set_xticks(x_positions)\n",
    "ax1.set_xticklabels(stage_labels, fontsize=11)\n",
    "\n",
    "# Add title\n",
    "plt.suptitle('Fuel Utilization Report - Institute of Science, Health and Performance',\n",
    "             fontsize=14, fontweight='bold', y=0.95)\n",
    "\n",
    "# Create legend\n",
    "lines1, labels1 = ax1.get_legend_handles_labels()\n",
    "lines2, labels2 = ax2.get_legend_handles_labels()\n",
    "ax1.legend(lines1 + lines2, labels1 + labels2, loc='upper left',\n",
    "           frameon=True, fancybox=True, shadow=True)\n",
    "\n",
    "# Add grid\n",
    "ax1.grid(True, alpha=0.3, linestyle='-', linewidth=0.5)\n",
    "ax1.set_axisbelow(True)\n",
    "\n",
    "# Adjust layout\n",
    "plt.tight_layout()\n",
    "plt.subplots_adjust(bottom=0.1, top=0.9)\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8a1878a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 120296 characters]",
      "text/plain": [
       "<Figure size 1800x500 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "first_unique_phase = df.drop_duplicates(subset='PHASE')\n",
    "phase_times = first_unique_phase['T(sec)'].tolist()\n",
    "\n",
    "plt.figure(figsize=(18, 5))\n",
    "ax1 = plt.subplot()\n",
    "\n",
    "# Plot VO2 Pulse\n",
    "#\n",
    "line1 = sns.lineplot(data=df, x='T(sec)', y='VO2 Pulse_smoothed', label='VO2 Pulse (mL/beat)', color='blue')\n",
    "ax1.set_xlabel('Time (sec)')\n",
    "ax1.set_ylabel('VO2 Pulse (mL/beat)')\n",
    "ax1.set_title('VO2 Pulse, Heart Rate, and Speed Over Time')\n",
    "ax1.set_ylim(0, df['VO2 Pulse'].max())\n",
    "ax1.grid(True, alpha=0.1)\n",
    "\n",
    "# Create second y-axis for heart rate\n",
    "#\n",
    "ax2 = ax1.twinx()\n",
    "line2 = sns.lineplot(data=df, x='T(sec)', y='HR(bpm)_smoothed', color='red', ax=ax2, \n",
    "                     linewidth=2, label='Heart Rate (bpm)')\n",
    "ax2.set_ylabel('Heart Rate (bpm)', color='red')\n",
    "ax2.tick_params(axis='y', labelcolor='red')\n",
    "\n",
    "# Create third y-axis for speed\n",
    "ax3 = ax1.twinx()\n",
    "ax3.spines['right'].set_position(('outward', 60))\n",
    "\n",
    "line3 = sns.lineplot(data=df, x='T(sec)', y='Speed', color='green', ax=ax3, \n",
    "                     drawstyle='steps-post', linewidth=2, label='Speed')\n",
    "ax3.set_ylabel('Speed', color='green')\n",
    "ax3.tick_params(axis='y', labelcolor='green')\n",
    "\n",
    "ax1.set_xticks(np.arange(0, df['T(sec)'].max() + 200, 200))\n",
    "\n",
    "# Remove default legends first\n",
    "if ax1.get_legend():\n",
    "    ax1.get_legend().remove()\n",
    "if ax2.get_legend():\n",
    "    ax2.get_legend().remove()\n",
    "if ax3.get_legend():\n",
    "    ax3.get_legend().remove()\n",
    "\n",
    "# Combine legends from all axes in the top left\n",
    "lines1, labels1 = ax1.get_legend_handles_labels()\n",
    "lines2, labels2 = ax2.get_legend_handles_labels()\n",
    "lines3, labels3 = ax3.get_legend_handles_labels()\n",
    "ax1.legend(lines1 + lines2 + lines3, labels1 + labels2 + labels3, loc='upper left')\n",
    "\n",
    "# Add colored background regions if you have phase information\n",
    "ax1.axvspan(0, phase_times[1], alpha=0.2, color='lightblue')\n",
    "ax1.axvspan(phase_times[1], phase_times[2], alpha=0.2, color='purple')\n",
    "ax1.axvspan(phase_times[2], phase_times[3], alpha=0.2, color='lightgreen')\n",
    "ax1.axvspan(phase_times[3], df['T(sec)'].max(), alpha=0.2, color='blue')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7361fb05",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 98884 characters]",
      "text/plain": [
       "<Figure size 1800x500 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "first_unique_phase = df.drop_duplicates(subset='PHASE')\n",
    "phase_times = first_unique_phase['T(sec)'].tolist()\n",
    "\n",
    "plt.figure(figsize=(18, 5))\n",
    "ax1 = plt.subplot()\n",
    "\n",
    "# Plot VT with step-like appearance\n",
    "line1 = sns.lineplot(data=df, x='T(sec)', y='VO2 Breath_smoothed', label='VO2 per Breath (mL/breath)')\n",
    "ax1.set_xlabel('Time (sec)')\n",
    "ax1.set_ylabel('VO2 per Breath (mL/breath)')\n",
    "ax1.set_title('VO2 per Breath and Speed Over Time')\n",
    "ax1.grid(True, alpha=0.1)\n",
    "\n",
    "# Plot speed as step function on secondary y-axis\n",
    "ax2 = ax1.twinx()\n",
    "ax1.set_xticks(np.arange(0, df['T(sec)'].max() + 200, 200))\n",
    "line2 = sns.lineplot(data=df, x='T(sec)', y='Speed', color='green', ax=ax2, \n",
    "             drawstyle='steps-post', linewidth=2, label='Speed')\n",
    "ax2.set_ylabel('Speed')\n",
    "\n",
    "# Remove default legends first\n",
    "ax1.get_legend().remove()\n",
    "ax2.get_legend().remove()\n",
    "\n",
    "# Combine legends from both axes in the top left\n",
    "lines1, labels1 = ax1.get_legend_handles_labels()\n",
    "lines2, labels2 = ax2.get_legend_handles_labels()\n",
    "ax1.legend(lines1 + lines2, labels1 + labels2, loc='upper left')\n",
    "\n",
    "# Add colored background regions if you have phase information\n",
    "ax1.axvspan(0, phase_times[1], alpha=0.2, color='lightblue')\n",
    "ax1.axvspan(phase_times[1], phase_times[2], alpha=0.2, color='purple')\n",
    "ax1.axvspan(phase_times[2], phase_times[3], alpha=0.2, color='lightgreen')\n",
    "ax1.axvspan(phase_times[3], df['T(sec)'].max(), alpha=0.2, color='blue')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c89478ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 114084 characters]",
      "text/plain": [
       "<Figure size 1800x500 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "first_unique_phase = df.drop_duplicates(subset='PHASE')\n",
    "phase_times = first_unique_phase['T(sec)'].tolist()\n",
    "\n",
    "plt.figure(figsize=(18, 5))\n",
    "ax1 = plt.subplot()\n",
    "\n",
    "df['CHO']\n",
    "# Plot VT with step-like appearance\n",
    "line1 = sns.lineplot(data=df, x='T(sec)', y='CHO_smoothed', label='CHO (kcal/min)')\n",
    "ax1.set_xlabel('Time (sec)')\n",
    "ax1.set_ylabel('CHO (g/min)')\n",
    "ax1.set_title('CHO and Speed Over Time')\n",
    "ax1.grid(True, alpha=0.1)\n",
    "\n",
    "# Plot speed as step function on secondary y-axis\n",
    "ax2 = ax1.twinx()\n",
    "ax1.set_xticks(np.arange(0, df['T(sec)'].max() + 200, 200))\n",
    "line2 = sns.lineplot(data=df, x='T(sec)', y='FAT_smoothed', color='green', ax=ax2, label='FAT (kcal/min)')\n",
    "ax2.set_ylabel('FAT (kcal/min)')\n",
    "\n",
    "ax2.set_ylim(0, 15)  # ensures HR line is above bars\n",
    "\n",
    "# Remove default legends first\n",
    "ax1.get_legend().remove()\n",
    "ax2.get_legend().remove()\n",
    "\n",
    "# Combine legends from both axes in the top left\n",
    "lines1, labels1 = ax1.get_legend_handles_labels()\n",
    "lines2, labels2 = ax2.get_legend_handles_labels()\n",
    "ax1.legend(lines1 + lines2, labels1 + labels2, loc='upper left')\n",
    "\n",
    "# Add colored background regions if you have phase information\n",
    "ax1.axvspan(0, phase_times[1], alpha=0.2, color='lightblue')\n",
    "ax1.axvspan(phase_times[1], phase_times[2], alpha=0.2, color='purple')\n",
    "ax1.axvspan(phase_times[2], phase_times[3], alpha=0.2, color='lightgreen')\n",
    "ax1.axvspan(phase_times[3], df['T(sec)'].max(), alpha=0.2, color='blue')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "1db16040",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 171108 characters]",
      "text/plain": [
       "<Figure size 1800x500 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "first_unique_phase = df.drop_duplicates(subset='PHASE')\n",
    "phase_times = first_unique_phase['T(sec)'].tolist()\n",
    "\n",
    "plt.figure(figsize=(18, 5))\n",
    "ax1 = plt.subplot()\n",
    "\n",
    "# Plot VO2 Pulse\n",
    "line1 = sns.lineplot(data=df, x='T(sec)', y='VCO2(ml/min)_smoothed', label='VCO2 (ml/min)', color='blue')\n",
    "ax1.set_xlabel('Time (sec)')\n",
    "ax1.set_ylabel('VO2 Pulse (mL/beat)')\n",
    "ax1.set_title('VO2 Pulse, Heart Rate, and Speed Over Time')\n",
    "ax1.set_ylim(0, df['VCO2(ml/min)'].max())\n",
    "ax1.grid(True, alpha=0.1)\n",
    "\n",
    "# Create second y-axis for heart rate\n",
    "ax2 = ax1.twinx()\n",
    "line2 = sns.lineplot(data=df, x='T(sec)', y='HR(bpm)_smoothed', color='red', ax=ax2, \n",
    "                     linewidth=2, label='Heart Rate (bpm)')\n",
    "ax2.set_ylabel('Heart Rate (bpm)', color='red')\n",
    "ax2.tick_params(axis='y', labelcolor='red')\n",
    "\n",
    "# Create third y-axis for speed\n",
    "ax3 = ax1.twinx()\n",
    "ax3.spines['right'].set_position(('outward', 60))\n",
    "line3 = sns.lineplot(data=df, x='T(sec)', y='BF(bpm)_smoothed', color='green', ax=ax3, linewidth=2, label='BF (bpm)')\n",
    "ax3.set_ylabel('BF (bpm)', color='green')\n",
    "ax3.tick_params(axis='y', labelcolor='green')\n",
    "\n",
    "ax1.set_xticks(np.arange(0, df['T(sec)'].max() + 200, 200))\n",
    "\n",
    "# Remove default legends first\n",
    "if ax1.get_legend():\n",
    "    ax1.get_legend().remove()\n",
    "if ax2.get_legend():\n",
    "    ax2.get_legend().remove()\n",
    "if ax3.get_legend():\n",
    "    ax3.get_legend().remove()\n",
    "\n",
    "# Combine legends from all axes in the top left\n",
    "lines1, labels1 = ax1.get_legend_handles_labels()\n",
    "lines2, labels2 = ax2.get_legend_handles_labels()\n",
    "lines3, labels3 = ax3.get_legend_handles_labels()\n",
    "ax1.legend(lines1 + lines2 + lines3, labels1 + labels2 + labels3, loc='upper left')\n",
    "\n",
    "# Add colored background regions if you have phase information\n",
    "ax1.axvspan(0, phase_times[1], alpha=0.2, color='lightblue')\n",
    "ax1.axvspan(phase_times[1], phase_times[2], alpha=0.2, color='purple')\n",
    "ax1.axvspan(phase_times[2], phase_times[3], alpha=0.2, color='lightgreen')\n",
    "ax1.axvspan(phase_times[3], df['T(sec)'].max(), alpha=0.2, color='blue')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "52642f49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MeasurementDate</th>\n",
       "      <th>Comment</th>\n",
       "      <th>ExternalDeviceId</th>\n",
       "      <th>ExternalPatientId</th>\n",
       "      <th>FirstName</th>\n",
       "      <th>LastName</th>\n",
       "      <th>BirthDate</th>\n",
       "      <th>Age</th>\n",
       "      <th>Ethnicity</th>\n",
       "      <th>Gender</th>\n",
       "      <th>...</th>\n",
       "      <th>Child_XC</th>\n",
       "      <th>Child_XC_Unit</th>\n",
       "      <th>Child_BIVA_ZRh</th>\n",
       "      <th>Child_BIVA_ZXcH</th>\n",
       "      <th>Child_PhA</th>\n",
       "      <th>Child_PhA_Unit</th>\n",
       "      <th>Child_REE_Kcal</th>\n",
       "      <th>Child_REE_MJ</th>\n",
       "      <th>Child_TEE_Kcal</th>\n",
       "      <th>Child_TEE_MJ</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2025-09-05T14:56:27.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>LD5163301170</td>\n",
       "      <td>Lucy</td>\n",
       "      <td>Dibenedetto</td>\n",
       "      <td>1997-08-28T00:00:00.0000000Z</td>\n",
       "      <td>28</td>\n",
       "      <td>Caucasian</td>\n",
       "      <td>Female</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2025-09-03T13:16:22.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>NS6479273340</td>\n",
       "      <td>Niyanta</td>\n",
       "      <td>Shah</td>\n",
       "      <td>1985-03-11T00:00:00.0000000Z</td>\n",
       "      <td>40</td>\n",
       "      <td>Other</td>\n",
       "      <td>Female</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2025-09-03T13:14:23.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1985-03-11T00:00:00.0000000Z</td>\n",
       "      <td>40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2025-08-27T20:57:32.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1996-04-05T00:00:00.0000000Z</td>\n",
       "      <td>29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2025-08-20T14:01:13.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>MW4167267833</td>\n",
       "      <td>Monica</td>\n",
       "      <td>Wong</td>\n",
       "      <td>1985-02-17T00:00:00.0000000Z</td>\n",
       "      <td>40</td>\n",
       "      <td>Asian</td>\n",
       "      <td>Female</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>2025-04-10T14:10:28.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>6473915195</td>\n",
       "      <td>Tristan</td>\n",
       "      <td>Walsh</td>\n",
       "      <td>1995-12-01T00:00:00.0000000Z</td>\n",
       "      <td>29</td>\n",
       "      <td>Caucasian</td>\n",
       "      <td>Female</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>2025-04-02T21:19:51.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>WSC4168020667</td>\n",
       "      <td>Scott</td>\n",
       "      <td>Christie</td>\n",
       "      <td>1968-08-19T00:00:00.0000000Z</td>\n",
       "      <td>56</td>\n",
       "      <td>Caucasian</td>\n",
       "      <td>Male</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>2025-04-02T15:23:54.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>6478809838</td>\n",
       "      <td>Lauren</td>\n",
       "      <td>Karatanevski</td>\n",
       "      <td>1984-07-07T00:00:00.0000000Z</td>\n",
       "      <td>40</td>\n",
       "      <td>Caucasian</td>\n",
       "      <td>Female</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>2025-03-26T15:47:42.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2002-07-10T00:00:00.0000000Z</td>\n",
       "      <td>22</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>2025-03-19T15:10:21.0000000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10000001583275_0055003f5631501320313557</td>\n",
       "      <td>6478809838</td>\n",
       "      <td>Lauren</td>\n",
       "      <td>Karatanevski</td>\n",
       "      <td>1984-07-07T00:00:00.0000000Z</td>\n",
       "      <td>40</td>\n",
       "      <td>Caucasian</td>\n",
       "      <td>Female</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>63 rows × 147 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 MeasurementDate  Comment  \\\n",
       "0   2025-09-05T14:56:27.0000000Z      NaN   \n",
       "1   2025-09-03T13:16:22.0000000Z      NaN   \n",
       "2   2025-09-03T13:14:23.0000000Z      NaN   \n",
       "3   2025-08-27T20:57:32.0000000Z      NaN   \n",
       "4   2025-08-20T14:01:13.0000000Z      NaN   \n",
       "..                           ...      ...   \n",
       "58  2025-04-10T14:10:28.0000000Z      NaN   \n",
       "59  2025-04-02T21:19:51.0000000Z      NaN   \n",
       "60  2025-04-02T15:23:54.0000000Z      NaN   \n",
       "61  2025-03-26T15:47:42.0000000Z      NaN   \n",
       "62  2025-03-19T15:10:21.0000000Z      NaN   \n",
       "\n",
       "                           ExternalDeviceId ExternalPatientId FirstName  \\\n",
       "0   10000001583275_0055003f5631501320313557      LD5163301170      Lucy   \n",
       "1   10000001583275_0055003f5631501320313557      NS6479273340   Niyanta   \n",
       "2   10000001583275_0055003f5631501320313557               NaN       NaN   \n",
       "3   10000001583275_0055003f5631501320313557               NaN       NaN   \n",
       "4   10000001583275_0055003f5631501320313557      MW4167267833    Monica   \n",
       "..                                      ...               ...       ...   \n",
       "58  10000001583275_0055003f5631501320313557        6473915195   Tristan   \n",
       "59  10000001583275_0055003f5631501320313557     WSC4168020667     Scott   \n",
       "60  10000001583275_0055003f5631501320313557        6478809838    Lauren   \n",
       "61  10000001583275_0055003f5631501320313557               NaN       NaN   \n",
       "62  10000001583275_0055003f5631501320313557        6478809838    Lauren   \n",
       "\n",
       "        LastName                     BirthDate  Age  Ethnicity  Gender  ...  \\\n",
       "0    Dibenedetto  1997-08-28T00:00:00.0000000Z   28  Caucasian  Female  ...   \n",
       "1           Shah  1985-03-11T00:00:00.0000000Z   40      Other  Female  ...   \n",
       "2            NaN  1985-03-11T00:00:00.0000000Z   40        NaN     NaN  ...   \n",
       "3            NaN  1996-04-05T00:00:00.0000000Z   29        NaN     NaN  ...   \n",
       "4           Wong  1985-02-17T00:00:00.0000000Z   40      Asian  Female  ...   \n",
       "..           ...                           ...  ...        ...     ...  ...   \n",
       "58         Walsh  1995-12-01T00:00:00.0000000Z   29  Caucasian  Female  ...   \n",
       "59      Christie  1968-08-19T00:00:00.0000000Z   56  Caucasian    Male  ...   \n",
       "60  Karatanevski  1984-07-07T00:00:00.0000000Z   40  Caucasian  Female  ...   \n",
       "61           NaN  2002-07-10T00:00:00.0000000Z   22        NaN     NaN  ...   \n",
       "62  Karatanevski  1984-07-07T00:00:00.0000000Z   40  Caucasian  Female  ...   \n",
       "\n",
       "    Child_XC Child_XC_Unit  Child_BIVA_ZRh Child_BIVA_ZXcH  Child_PhA  \\\n",
       "0        NaN           NaN             NaN             NaN        NaN   \n",
       "1        NaN           NaN             NaN             NaN        NaN   \n",
       "2        NaN           NaN             NaN             NaN        NaN   \n",
       "3        NaN           NaN             NaN             NaN        NaN   \n",
       "4        NaN           NaN             NaN             NaN        NaN   \n",
       "..       ...           ...             ...             ...        ...   \n",
       "58       NaN           NaN             NaN             NaN        NaN   \n",
       "59       NaN           NaN             NaN             NaN        NaN   \n",
       "60       NaN           NaN             NaN             NaN        NaN   \n",
       "61       NaN           NaN             NaN             NaN        NaN   \n",
       "62       NaN           NaN             NaN             NaN        NaN   \n",
       "\n",
       "   Child_PhA_Unit  Child_REE_Kcal  Child_REE_MJ Child_TEE_Kcal  Child_TEE_MJ  \n",
       "0             NaN             NaN           NaN            NaN           NaN  \n",
       "1             NaN             NaN           NaN            NaN           NaN  \n",
       "2             NaN             NaN           NaN            NaN           NaN  \n",
       "3             NaN             NaN           NaN            NaN           NaN  \n",
       "4             NaN             NaN           NaN            NaN           NaN  \n",
       "..            ...             ...           ...            ...           ...  \n",
       "58            NaN             NaN           NaN            NaN           NaN  \n",
       "59            NaN             NaN           NaN            NaN           NaN  \n",
       "60            NaN             NaN           NaN            NaN           NaN  \n",
       "61            NaN             NaN           NaN            NaN           NaN  \n",
       "62            NaN             NaN           NaN            NaN           NaN  \n",
       "\n",
       "[63 rows x 147 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_2 = pd.read_excel('data/SECA body comp for all patients.xlsx')\n",
    "df_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "2056096d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 19044 characters]",
      "text/plain": [
       "<Figure size 1200x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "body_fat_chart = {\n",
    "    \"male\": {\n",
    "        \"20-39\": {\n",
    "            \"bad\": [(0, 5), (25, 50)],\n",
    "            \"okay\": [(5, 10), (20, 25)],\n",
    "            \"good\": [(10, 20)]\n",
    "        },\n",
    "        \"40-59\": {\n",
    "            \"bad\": [(0, 5), (30, 50)],\n",
    "            \"okay\": [(5, 10), (20, 30)],\n",
    "            \"good\": [(10, 20)]\n",
    "        },\n",
    "        \"60-79\": {\n",
    "            \"bad\": [(0, 5), (30, 50)],\n",
    "            \"okay\": [(5, 10), (20, 25)],\n",
    "            \"good\": [(10, 25)]\n",
    "        }\n",
    "    },\n",
    "    \"female\": {\n",
    "        \"20-39\": {\n",
    "            \"bad\": [(0, 15), (40, 50)],\n",
    "            \"okay\": [(15, 20), (35, 40)],\n",
    "            \"good\": [(20, 35)]\n",
    "        },\n",
    "        \"40-59\": {\n",
    "            \"bad\": [(0, 20), (40, 50)],\n",
    "            \"okay\": [(20, 25), (35, 40)],\n",
    "            \"good\": [(25, 35)]\n",
    "        },\n",
    "        \"60-79\": {\n",
    "            \"bad\": [(0, 20), (40, 50)],\n",
    "            \"okay\": [(20, 25), (35, 40)],\n",
    "            \"good\": [(25, 35)]\n",
    "        }\n",
    "    }\n",
    "}\n",
    "\n",
    "def create_body_fat_visualization(gender, age, body_fat_percentage):\n",
    "    # Determine age group\n",
    "    if 20 <= age <= 39:\n",
    "        age_group = \"20-39\"\n",
    "    elif 40 <= age <= 59:\n",
    "        age_group = \"40-59\"\n",
    "    elif 60 <= age <= 79:\n",
    "        age_group = \"60-79\"\n",
    "    else:\n",
    "        return \"Age out of range (20-79)\"\n",
    "    \n",
    "    # Get ranges for the specific gender and age group\n",
    "    ranges = body_fat_chart[gender.lower()][age_group]\n",
    "    \n",
    "    # Create figure\n",
    "    fig, ax = plt.subplots(figsize=(12, 3))\n",
    "    \n",
    "    # Define colors for different categories\n",
    "    colors = {'bad': '#ff6b6b', 'okay': '#ffeb3b', 'good': '#90ee90'}\n",
    "    \n",
    "    # Create the horizontal segments\n",
    "    bar_height = 0.4\n",
    "    y_position = 0\n",
    "    \n",
    "    # Plot each category's ranges\n",
    "    for category, ranges_list in ranges.items():\n",
    "        for range_tuple in ranges_list:\n",
    "            start, end = range_tuple\n",
    "            width = end - start\n",
    "            ax.barh(y_position, width, left=start, height=bar_height, \n",
    "                    color=colors[category], alpha=0.9, edgecolor='black', linewidth=0.5)\n",
    "    \n",
    "    # Add the user's body fat percentage marker (triangle pointing down)\n",
    "    ax.plot(body_fat_percentage, y_position + bar_height / 2 + 0.05, 'v', markersize=15, color='black')\n",
    "    \n",
    "    # Customize the chart\n",
    "    ax.set_xlim(0, 50)\n",
    "    ax.set_ylim(-1, 1)\n",
    "    ax.set_xlabel('')\n",
    "    ax.set_title(f'Body Fat Percent - {body_fat_percentage:.1f}%', fontsize=16, fontweight='bold', pad=20)\n",
    "    \n",
    "    # Add age group and gender label on the left side\n",
    "    ax.text(-5, y_position, f'{age_group}\\n({gender[0].upper()})', ha='center', va='center', fontsize=12)\n",
    "    \n",
    "    # Adjust x-axis ticks to match the image\n",
    "    ax.set_xticks(range(0, 51, 5))\n",
    "    ax.set_xticklabels([f'{i}%' for i in range(0, 51, 5)])\n",
    "    \n",
    "    # Draw vertical lines for the tick marks\n",
    "    for tick in range(0, 51, 5):\n",
    "        ax.plot([tick, tick], [y_position - bar_height / 2, y_position - bar_height / 2 - 0.1], color='black', linewidth=1.5)\n",
    "    \n",
    "    # Remove y-axis and top/right spines\n",
    "    ax.set_yticks([])\n",
    "    ax.spines['left'].set_visible(False)\n",
    "    ax.spines['right'].set_visible(False)\n",
    "    ax.spines['top'].set_visible(False)\n",
    "    ax.spines['bottom'].set_visible(False)\n",
    "    \n",
    "    plt.tight_layout()\n",
    "    plt.savefig('graphs/page_1_body_fat.png')\n",
    "    plt.show()\n",
    "\n",
    "# Create the chart using Keirstyn's data\n",
    "gender = 'female'\n",
    "age = 25\n",
    "fat_percentage = 22.4\n",
    "create_body_fat_visualization(gender, age, fat_percentage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf55717b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 51752 characters]",
      "text/plain": [
       "<Figure size 800x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Filter df_2 for Keirstyn Moran\n",
    "keirstyn_data = df_2[df_2['LastName'].str.contains('Moran', case=False, na=False)]\n",
    "# Get the fat mass percentage for Keirstyn\n",
    "fat_percentage = keirstyn_data['Adult_FMP'].iloc[0]\n",
    "weight_kg = keirstyn_data['Weight'].iloc[0]\n",
    "age = keirstyn_data['Age'].iloc[0]\n",
    "gender = keirstyn_data['Gender'].iloc[0]\n",
    "lean_percentage = 100 - fat_percentage\n",
    "\n",
    "# Create donut chart\n",
    "fat_mass_lbs = 27.6\n",
    "lean_mass_lbs = 95.4\n",
    "\n",
    "# Calculate percentages from the provided weights\n",
    "total_weight = fat_mass_lbs + lean_mass_lbs\n",
    "fat_percentage = (fat_mass_lbs / total_weight) * 100\n",
    "lean_percentage = (lean_mass_lbs / total_weight) * 100\n",
    "\n",
    "# Data for the chart\n",
    "sizes = [fat_percentage, lean_percentage]\n",
    "labels = ['Fat Mass (27.6lbs)', 'Lean Mass (95.4lbs)']\n",
    "colors = ['#fde3ac', '#ff9966'] # Light yellow/tan and orange from the image\n",
    "\n",
    "plt.figure(figsize=(8, 8))\n",
    "# Create the donut chart\n",
    "wedges, texts, autotexts = plt.pie(sizes,\n",
    "                                   autopct='%1.1f%%',\n",
    "                                   startangle=90,\n",
    "                                   wedgeprops=dict(width=0.5, edgecolor='w'),\n",
    "                                   colors=colors)\n",
    "\n",
    "# Customize the text for labels and percentages\n",
    "for i, (text, autotext) in enumerate(zip(texts, autotexts)):\n",
    "    # Set the label text to be the full label, not just the percentage\n",
    "    text.set_text(labels[i])\n",
    "    text.set_fontsize(14)\n",
    "    text.set_color('black')\n",
    "\n",
    "    # Position the percentage text inside the donut\n",
    "    autotext.set_fontsize(14)\n",
    "    autotext.set_color('black')\n",
    "\n",
    "# Set the title\n",
    "plt.title('Body Composition', fontsize=18, fontweight='bold')\n",
    "plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle\n",
    "plt.savefig('graphs/page_1_body_composition.png')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21c1c0a5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "report_generation",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
