Skip to content

Commit

Permalink
54 vercel app setup (#56)
Browse files Browse the repository at this point in the history
* initial next commit

* landing page good enough for now

* strava oauth done, exchange code next

* integrating with lambda

* delete next crap

* test deploy

* add local db fix
  • Loading branch information
voynow authored Sep 2, 2024
1 parent 90f5668 commit 558f349
Show file tree
Hide file tree
Showing 17 changed files with 437 additions and 206 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/deploy_lambda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Deploy to Lambda

on:
push:
branches:
- main

jobs:
deploy:
Expand Down
68 changes: 68 additions & 0 deletions scripts/code2clipboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import os
from typing import List

import pyperclip


def get_code_files(directory: str, extensions: List[str]) -> List[str]:
"""
Recursively finds all code files in the given directory with specified extensions,
strictly ignoring any path containing 'node_modules'.
:param directory: Directory to search for code files.
:param extensions: List of file extensions to include.
:return: List of file paths for code files.
"""
code_files = []
for root, _, files in os.walk(directory):
if "node_modules" in root or ".next" in root:
continue

code_files.extend(
os.path.join(root, file)
for file in files
if any(file.endswith(ext) for ext in extensions)
)
return code_files


def read_files(file_paths: List[str], directory: str) -> str:
"""
Reads the content of the given files and returns a combined string.
:param file_paths: List of file paths to read.
:param directory: Base directory for calculating relative paths.
:return: Combined content of all files as a string.
"""
content = []
for file_path in file_paths:
with open(file_path, "r") as file:
relative_path = os.path.relpath(file_path, directory)
content.append(f"--- {relative_path} ---\n")
content.append(file.read())
content.append("\n\n")
return "".join(content)


def copy_code_to_clipboard() -> None:
"""
Copies all code files from the current working directory to the clipboard.
"""
extensions = [
".py",
".js",
".ts",
".html",
".css",
".tsx",
".jsx",
]
directory = os.getcwd()
code_files = get_code_files(directory, extensions)
combined_content = read_files(code_files, directory)
pyperclip.copy(combined_content)


if __name__ == "__main__":
copy_code_to_clipboard()
print("Code files have been copied to the clipboard.")
1 change: 1 addition & 0 deletions src/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def lambda_handler(event, context):
code=event["code"],
)
logging.info(response)
return {"success": True}

elif event.get("end_to_end_test"):
user = get_user(os.environ["JAMIES_ATHLETE_ID"])
Expand Down
171 changes: 110 additions & 61 deletions test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,67 +88,6 @@
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"athlete_id=98390356 token still valid until 2024-08-30 23:49:42+00:00\n"
]
}
],
"source": [
"from src.activities import get_activity_summaries\n",
"from src.auth_manager import get_strava_client\n",
"from src.constants import COACH_ROLE\n",
"from src.supabase_client import get_training_week_with_coaching\n",
"from src.training_week_update import get_updated_training_week\n",
"from src.types.mid_week_analysis import MidWeekAnalysis\n",
"\n",
"\n",
"user = get_user(os.environ[\"JAMIES_ATHLETE_ID\"])\n",
"\n",
"sysmsg_base = f\"{COACH_ROLE}\\nYour client has included the following preferences: {user.preferences}\\n\"\n",
"strava_client = get_strava_client(user.athlete_id)\n",
"\n",
"training_week_with_coaching = get_training_week_with_coaching(user.athlete_id)\n",
"current_weeks_activity_summaries = get_activity_summaries(\n",
" strava_client, num_weeks=1\n",
")\n",
"mid_week_analysis = MidWeekAnalysis(\n",
" activities=current_weeks_activity_summaries,\n",
" training_week=training_week_with_coaching.training_week,\n",
")\n",
"training_week_update_with_planning = get_updated_training_week(\n",
" sysmsg_base=sysmsg_base, mid_week_analysis=mid_week_analysis\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"nan"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mid_week_analysis.activities[0].pace_minutes_per_mile\n",
"# Training week accuracy"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -351,6 +290,116 @@
" print(\".\" * 100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Manual Training Plan Generation"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"raytrip.curtis@gmail.com\n",
"athlete_id=58608268 token still valid until 2024-09-03 02:57:23+00:00\n",
"TrainingWeekWithCoaching(typical_week_training_review=Your current schedule shows a consistent routine with shorter recovery runs on Monday, and longer efforts on Fridays and Sundays indicating potential long runs. Saturdays, based on your preference, should accommodate your long run for marathon preparation, but current mileage suggests a lighter run. Your speed work on Tuesdays aligns well with your preference, but consider shifting your rest days to Monday or Sunday to ensure recovery after these intensive sessions., weekly_mileage_target=Based on your recent training, you're showing consistent higher mileage with alternating long run distances. For next week, aim for a weekly mileage target of about 65-68 miles to maintain momentum while avoiding burnout. Schedule your long run on Saturday with a distance between 18-20 miles, as you've achieved in Week 32 and 34. Keep focusing on quality workouts on Tuesdays, maintaining a pace relevant to your marathon goals, such as around 6m 40s per mile, to further build speed endurance., planning=Planning(weekly_mileage_target=65-68 miles, long_run_distance=19.0, remaining_weekly_mileage=68 - 19 = 49 miles, remaining_weekly_mileage_planning=Let's distribute 49 miles over the remaining 6 days: Tuesday session is 10 miles (49 - 10 = 39 miles remaining). Two sessions of 9 miles on Wednesday and Thursday (39 - 18 = 21 miles remaining). One session of 8 miles on Friday (21 - 8 = 13 miles remaining). One session of 5 miles on Monday (13 - 5 = 8 miles remaining). Easy runs on Sunday of 8 miles (8 - 8 = 0 miles remaining). Monday and Sunday are rest days.), training_week=[TrainingSession(day=<Day.MON: 'mon'>, session_type=<SessionType.EASY: 'easy run'>, distance=5.0, notes='Easy pace for recovery.'), TrainingSession(day=<Day.TUES: 'tues'>, session_type=<SessionType.SPEED: 'speed workout'>, distance=10.0, notes='Intervals at 6m 40s pace, e.g., 6x1mi @ 6m 40s per mile.'), TrainingSession(day=<Day.WED: 'wed'>, session_type=<SessionType.MODERATE: 'moderate run'>, distance=9.0, notes='Steady pace, around 7m 30s per mile.'), TrainingSession(day=<Day.THURS: 'thurs'>, session_type=<SessionType.MODERATE: 'moderate run'>, distance=9.0, notes='Keep a steady pace, around 7m 30s per mile.'), TrainingSession(day=<Day.FRI: 'fri'>, session_type=<SessionType.EASY: 'easy run'>, distance=8.0, notes='Easy pace for recovery, focus on form.'), TrainingSession(day=<Day.SAT: 'sat'>, session_type=<SessionType.LONG: 'long run'>, distance=19.0, notes='Long run at a comfortable pace, aim for endurance.'), TrainingSession(day=<Day.SUN: 'sun'>, session_type=<SessionType.EASY: 'easy run'>, distance=8.0, notes='Easy pace, recover from long run.')])\n"
]
}
],
"source": [
"from freezegun import freeze_time\n",
"from src.activities import get_activities_df, get_day_of_week_summaries, get_weekly_summaries\n",
"from src.auth_manager import get_strava_client\n",
"from src.constants import COACH_ROLE\n",
"from src.new_training_week import generate_training_week_with_coaching\n",
"from src.supabase_client import list_users\n",
"\n",
"@freeze_time(\"2024-09-01\")\n",
"def gen_training_week_wrapper(sysmsg_base, strava_client):\n",
" activities_df = get_activities_df(strava_client)\n",
" day_of_week_summaries = get_day_of_week_summaries(activities_df)\n",
" weekly_summaries = get_weekly_summaries(activities_df)\n",
" return generate_training_week_with_coaching(\n",
" sysmsg_base=sysmsg_base,\n",
" weekly_summaries=weekly_summaries,\n",
" day_of_week_summaries=day_of_week_summaries,\n",
" )\n",
"\n",
"# \"voynow99@gmail.com\", \"jaredpalek8@gmail.com\", \"laurenbrooks01@gmail.com\", \"raytrip.curtis@gmail.com\"\n",
"for user in list_users():\n",
" if user.email == \"raytrip.curtis@gmail.com\":\n",
" print(user.email)\n",
" sysmsg_base = f\"{COACH_ROLE}\\nYour client has included the following preferences: {user.preferences}\\n\"\n",
" strava_client = get_strava_client(user.athlete_id)\n",
" response = gen_training_week_wrapper(sysmsg_base, strava_client)\n",
" print(response)\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"68.0\n",
"Based on your recent training, you're showing consistent higher mileage with alternating long run distances. For next week, aim for a weekly mileage target of about 65-68 miles to maintain momentum while avoiding burnout. Schedule your long run on Saturday with a distance between 18-20 miles, as you've achieved in Week 32 and 34. Keep focusing on quality workouts on Tuesdays, maintaining a pace relevant to your marathon goals, such as around 6m 40s per mile, to further build speed endurance.\n"
]
},
{
"data": {
"text/plain": [
"[TrainingSession(day=<Day.MON: 'mon'>, session_type=<SessionType.EASY: 'easy run'>, distance=5.0, notes='Easy pace for recovery.'),\n",
" TrainingSession(day=<Day.TUES: 'tues'>, session_type=<SessionType.SPEED: 'speed workout'>, distance=10.0, notes='Intervals at 6m 40s pace, e.g., 6x1mi @ 6m 40s per mile.'),\n",
" TrainingSession(day=<Day.WED: 'wed'>, session_type=<SessionType.MODERATE: 'moderate run'>, distance=9.0, notes='Steady pace, around 7m 30s per mile.'),\n",
" TrainingSession(day=<Day.THURS: 'thurs'>, session_type=<SessionType.MODERATE: 'moderate run'>, distance=9.0, notes='Keep a steady pace, around 7m 30s per mile.'),\n",
" TrainingSession(day=<Day.FRI: 'fri'>, session_type=<SessionType.EASY: 'easy run'>, distance=8.0, notes='Easy pace for recovery, focus on form.'),\n",
" TrainingSession(day=<Day.SAT: 'sat'>, session_type=<SessionType.LONG: 'long run'>, distance=19.0, notes='Long run at a comfortable pace, aim for endurance.'),\n",
" TrainingSession(day=<Day.SUN: 'sun'>, session_type=<SessionType.EASY: 'easy run'>, distance=8.0, notes='Easy pace, recover from long run.')]"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(response.total_weekly_mileage)\n",
"print(response.weekly_mileage_target)\n",
"response.training_week"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"APIResponse(data=[{'id': 69, 'athlete_id': 60813108, 'training_week': '[{\"day\": \"mon\", \"session_type\": \"rest day\", \"distance\": 0.0, \"notes\": \"Rest and recovery\"}, {\"day\": \"tues\", \"session_type\": \"easy run\", \"distance\": 6.0, \"notes\": \"Easy pace\"}, {\"day\": \"wed\", \"session_type\": \"speed workout\", \"distance\": 8.0, \"notes\": \"3x1 mile @ 7m 30s with 2 minutes rest\"}, {\"day\": \"thurs\", \"session_type\": \"easy run\", \"distance\": 5.0, \"notes\": \"Easy pace\"}, {\"day\": \"fri\", \"session_type\": \"rest day\", \"distance\": 0.0, \"notes\": \"Rest and recovery\"}, {\"day\": \"sat\", \"session_type\": \"long run\", \"distance\": 14.0, \"notes\": \"Steady pace\"}, {\"day\": \"sun\", \"session_type\": \"easy run\", \"distance\": 5.0, \"notes\": \"Easy pace, recovery run\"}]', 'typical_week_training_review': 'Your training schedule aligns well with your marathon goals, with Wednesdays being optimal for workouts as you consistently cover decent mileage at a relatively brisk 8 minutes and 57 seconds per mile pace. Saturdays are effectively utilized for long runs, averaging 12.7 miles at a steady pace. It appears that you take rest days mostly on Mondays and Fridays, providing recovery between your more intense and longer sessions. Consider incorporating speed work on your lower mileage days if possible to boost overall speed.', 'weekly_mileage_target': \"Based on your recent training data, you've had a couple of fluctuations in mileage, with a peak at 46.98 miles followed by a drop. To balance building endurance while remaining conservative, aim for 36-38 miles next week. For the long run, target 13-14 miles to maintain endurance without pushing too hard beyond your recent averages. This setup should allow for a steady build-up as you prepare for your marathon in October.\", 'created_at': '2024-09-02T20:57:06.260306+00:00', 'planning': 'Planning(weekly_mileage_target=36-38 miles, long_run_distance=14.0, remaining_weekly_mileage=38 miles - 14 miles (long run) = 24 miles remaining, remaining_weekly_mileage_planning=For the remaining 24 miles, we will distribute them across 5 days (Tuesday, Wednesday, Thursday, Sunday) as follows: Tuesday: 6 miles, Wednesday: 8 miles speed workout, Thursday: 5 miles easy, Sunday: 5 miles easy. Monday and Friday will be rest days. Total: 6 + 8 + 5 + 5 = 24 miles.)'}], count=None)"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from src.supabase_client import upsert_training_week_with_coaching\n",
"\n",
"upsert_training_week_with_coaching(user.athlete_id, response)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
1 change: 0 additions & 1 deletion web/public/next.svg

This file was deleted.

Binary file added web/public/powered_by_strava.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added web/public/strava-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion web/public/vercel.svg

This file was deleted.

22 changes: 22 additions & 0 deletions web/src/app/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Image from 'next/image';

const Footer = (): JSX.Element => {
return (
<footer className="mt-32 w-full bg-gray-100 text-gray-400 py-4">
<div className="container flex items-center justify-between">
<Image
src="/powered_by_strava.png"
alt="Powered by Strava"
width={162}
height={30}
className="ml-4"
/>
<p className="text-center flex-grow">
© 2024 TrackFlow. All rights reserved.
</p>
</div>
</footer>
);
};

export default Footer;
40 changes: 40 additions & 0 deletions web/src/app/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Image from 'next/image';
import Link from 'next/link';
import { useState } from 'react';
import SignUp from './SignUp';

export default function Navbar(): JSX.Element {
const [showSignup, setShowSignup] = useState(false);

return (
<>
<nav className="fixed top-0 w-full bg-opacity-0 text-gray-700 z-10">
<div className="px-6">
<div className="flex justify-between h-16">
<div className="flex-shrink-0 flex items-center">
<Link href="/" className="text-2xl font-bold hover:text-gray-500 transition duration-300 ease-in-out">
TrackFlow
</Link>
</div>
<div className="flex items-center">
<button className="text-xl px-6 py-2 rounded-lg hover:bg-white transition duration-300 ease-in-out"
onClick={() => setShowSignup(true)}>
<div className="flex items-center">
<Image
src="/strava-icon.png"
alt="Strava Logo"
width={20}
height={20}
className="mr-2"
/>
Sign Up
</div>
</button>
</div>
</div>
</div>
</nav>
{showSignup && <SignUp onClose={() => setShowSignup(false)} />}
</>
);
}
Loading

0 comments on commit 558f349

Please sign in to comment.