init
This commit is contained in:
commit
66729f7d08
24 files changed
+907
No files matched your search
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,40 @@
|
||||
# exercise_tracker/models.py
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Session(models.Model):
|
||||
name = models.CharField(max_length=100, blank=True)
|
||||
date = models.DateField()
|
||||
location = models.CharField(max_length=100, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name or 'Workout'} ({self.date})"
|
||||
|
||||
|
||||
class Exercise(models.Model):
|
||||
session = models.ForeignKey(Session, related_name='exercises', on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} in {self.session.name or 'Workout'}"
|
||||
|
||||
|
||||
class Set(models.Model):
|
||||
exercise = models.ForeignKey(Exercise, related_name='sets', on_delete=models.CASCADE)
|
||||
|
||||
reps = models.IntegerField(null=True, blank=True)
|
||||
weight_kg = models.FloatField(null=True, blank=True)
|
||||
|
||||
distance_meters = models.FloatField(null=True, blank=True)
|
||||
duration_seconds = models.IntegerField(null=True, blank=True)
|
||||
|
||||
is_personal_record = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
if self.distance_meters is not None:
|
||||
mins = self.duration_seconds // 60 if self.duration_seconds else 0
|
||||
secs = self.duration_seconds % 60 if self.duration_seconds else 0
|
||||
return f"Cardio: {self.exercise.name} ({mins}m {secs}s, {self.distance_meters / 1000:.2f}km)"
|
||||
reps_str = self.reps or "∞"
|
||||
weight_str = f"{self.weight_kg:.1f}" if self.weight_kg is not None else ""
|
||||
return f"{reps_str}x{weight_str}kg ({self.exercise.name})"
|
||||
@@ -0,0 +1,72 @@
|
||||
# exercise_tracker/tasks.py
|
||||
from core.base import TaskModule
|
||||
from .models import Session, Exercise, Set
|
||||
|
||||
|
||||
class ExerciseTracker(TaskModule):
|
||||
MODULE_NAME = "exercise_tracker"
|
||||
DESCRIPTION = "Log workouts, exercises, and training sets (strength & cardio)"
|
||||
|
||||
TOOLS = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "log_workout",
|
||||
"description": "Record a complete workout session with exercises and sets",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"session_name": {"type": "string"},
|
||||
"date": {"type": "string", "format": "date"},
|
||||
"exercises": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"exercise_name": {"type": "string"},
|
||||
"sets": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
# Strength options
|
||||
"reps": {"type": "integer"},
|
||||
"weight_kg": {"type": "number"},
|
||||
|
||||
# Cardio options
|
||||
"duration_seconds": {"type": "integer"},
|
||||
"distance_meters": {"type": "number"}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["exercise_name"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["session_name", "date", "exercises"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def execute_tool(cls, tool_name: str, arguments: dict) -> dict:
|
||||
if tool_name == "log_workout":
|
||||
session = Session.objects.create(name=arguments["session_name"], date=arguments["date"])
|
||||
|
||||
for ex_data in arguments.get("exercises", []):
|
||||
exercise = Exercise.objects.create(session=session, name=ex_data["exercise_name"])
|
||||
|
||||
for set_data in ex_data.get("sets", []):
|
||||
Set.objects.create(
|
||||
exercise=exercise,
|
||||
reps=set_data.get("reps"),
|
||||
weight_kg=set_data.get("weight_kg"),
|
||||
duration_seconds=set_data.get("duration_seconds"),
|
||||
distance_meters=set_data.get("distance_meters")
|
||||
)
|
||||
|
||||
return {"status": "success", "message": f"Logged workout: {session.name}"}
|
||||
|
||||
raise ValueError(f"Unknown tool: {tool_name}")
|
||||
Reference in new issue
Block a user