-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
2,085 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
echo "Logging in to ECR" | ||
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com | ||
|
||
echo "Building image" | ||
docker build --no-cache --platform=linux/amd64 -t $REGISTRY_NAME . | ||
|
||
echo "Tagging image" | ||
docker tag $REGISTRY_NAME:$TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REGISTRY_NAME:$TAG | ||
|
||
echo "Pushing image to ECR" | ||
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REGISTRY_NAME:$TAG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM --platform=linux/amd64 python:3.11-slim | ||
|
||
WORKDIR /app | ||
|
||
COPY . /app | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
EXPOSE 80 | ||
|
||
# Start the app with Python | ||
CMD ["python", "-m", "uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "80"] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[tool.poetry] | ||
name = "trackflow-api" | ||
version = "0.1.0" | ||
description = "" | ||
authors = [] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.11" | ||
fastapi = "^0.115.4" | ||
uvicorn = "^0.32.0" | ||
supabase = "^2.10.0" | ||
python-dotenv = "^1.0.1" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
|
||
docker build -t trackflow . | ||
docker tag trackflow:latest 498969721544.dkr.ecr.us-east-1.amazonaws.com/trackflow:latest | ||
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 498969721544.dkr.ecr.us-east-1.amazonaws.com | ||
docker push 498969721544.dkr.ecr.us-east-1.amazonaws.com/trackflow:latest | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from fastapi import FastAPI, HTTPException | ||
from src.supabase_client import TrainingWeek, get_training_week | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.get("/training_week/{athlete_id}", response_model=TrainingWeek) | ||
async def training_week_endpoint(athlete_id: int): | ||
""" | ||
Retrieve the most recent training_week row by athlete_id. | ||
""" | ||
try: | ||
return get_training_week(athlete_id) | ||
except ValueError as e: | ||
raise HTTPException(status_code=404, detail=str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
import os | ||
from enum import StrEnum | ||
from typing import List | ||
|
||
from dotenv import load_dotenv | ||
from pydantic import BaseModel, Field | ||
from supabase import Client, create_client | ||
|
||
load_dotenv() | ||
|
||
|
||
class Day(StrEnum): | ||
MON = "Mon" | ||
TUES = "Tues" | ||
WED = "Wed" | ||
THURS = "Thurs" | ||
FRI = "Fri" | ||
SAT = "Sat" | ||
SUN = "Sun" | ||
|
||
|
||
class SessionType(StrEnum): | ||
EASY = "easy run" | ||
LONG = "long run" | ||
SPEED = "speed workout" | ||
REST = "rest day" | ||
MODERATE = "moderate run" | ||
|
||
|
||
class TrainingSession(BaseModel): | ||
day: Day | ||
session_type: SessionType | ||
distance: float = Field(description="Distance in miles") | ||
notes: str = Field( | ||
description="Detailed yet concise notes about the session from the coach's perspective" | ||
) | ||
completed: bool = Field(description="Whether the session has been completed") | ||
|
||
|
||
class TrainingWeek(BaseModel): | ||
sessions: List[TrainingSession] | ||
|
||
@property | ||
def total_mileage(self) -> float: | ||
return sum(session.distance for session in self.sessions) | ||
|
||
@property | ||
def progress(self) -> float: | ||
return (self.completed_sessions.total_mileage / self.total_mileage) * 100 | ||
|
||
@property | ||
def completed_sessions(self) -> TrainingWeek: | ||
return TrainingWeek( | ||
sessions=[session for session in self.sessions if session.completed is True] | ||
) | ||
|
||
|
||
def init() -> Client: | ||
url = os.getenv("SUPABASE_URL") | ||
key = os.getenv("SUPABASE_KEY") | ||
return create_client(url, key) | ||
|
||
|
||
client = init() | ||
|
||
|
||
def get_training_week(athlete_id: int) -> TrainingWeek: | ||
""" | ||
Get the most recent training_week row by athlete_id. | ||
""" | ||
table = client.table("training_week") | ||
response = ( | ||
table.select("training_week") | ||
.eq("athlete_id", athlete_id) | ||
.order("created_at", desc=True) | ||
.limit(1) | ||
.execute() | ||
) | ||
|
||
try: | ||
response_data = response.data[0] | ||
return TrainingWeek(**json.loads(response_data["training_week"])) | ||
except IndexError: | ||
raise ValueError( | ||
f"Could not find training_week row for athlete_id {athlete_id}" | ||
) |