"""
Coach AI capstone — original analysis notebook (Google Colab, March 2026)
Code cells only, exported unchanged for the portfolio. Outputs removed; the Colab upload step is kept as written.
Ran on the 32 recovery days logged at the time (Feb 9 – Mar 13, 2026).
"""

# %% [cell 0]
from google.colab import files
uploaded = files.upload()

# %% [cell 1]
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

from scipy.stats import pearsonr
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score

plt.rcParams['figure.figsize'] = (10,6)
sns.set_style("whitegrid")

# %% [cell 2]
# !ls

# %% [cell 3]
sprint_df = pd.read_csv("CIS 627 Athlete Performance Capstone - sprint_data.csv")
strength_df = pd.read_csv("CIS 627 Athlete Performance Capstone - strength_data.csv")
recovery_df = pd.read_csv("CIS 627 Athlete Performance Capstone - recovery_data.csv")

# %% [cell 4]
print("Sprint Data")
print(sprint_df.head())

print("\nStrength Data")
print(strength_df.head())

print("\nRecovery Data")
print(recovery_df.head())

# %% [cell 5]
print("Recovery Summary")
print(recovery_df.describe())

print("\nStrength Summary")
print(strength_df.describe())

print("\nSprint Summary")
print(sprint_df.describe())

# %% [cell 6]
corr = recovery_df.drop('Date', axis=1).corr()

sns.heatmap(corr, annot=True, cmap="coolwarm")

plt.title("Recovery Metrics Correlation")
plt.show()

# %% [cell 7]
sns.scatterplot(x="sleep_hours", y="fatigue", data=recovery_df)

plt.title("Sleep vs Fatigue")
plt.xlabel("Sleep Hours")
plt.ylabel("Fatigue")

plt.show()

# %% [cell 8]
sns.scatterplot(x="hrv", y="fatigue", data=recovery_df)

plt.title("HRV vs Fatigue")
plt.xlabel("HRV")
plt.ylabel("Fatigue")

plt.show()

# %% [cell 9]
X = recovery_df[["sleep_hours","hrv","resting_hr"]]
y = recovery_df["fatigue"]

# Combine X and y, drop rows with NaN values, then separate them again
df_for_model = pd.concat([X, y], axis=1).dropna()
X_clean = df_for_model[X.columns]
y_clean = df_for_model[y.name]

model = LinearRegression()
model.fit(X_clean, y_clean)

predictions = model.predict(X_clean)

print("R² Score:", r2_score(y_clean,predictions))
