WIP
This commit is contained in:
BIN
_db.sqlite3
Normal file
BIN
_db.sqlite3
Normal file
Binary file not shown.
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
18
exercise/migrations/0007_exercise_estimated_rep_duration.py
Normal file
18
exercise/migrations/0007_exercise_estimated_rep_duration.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-07-25 15:22
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('exercise', '0006_alter_exercise_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='exercise',
|
||||||
|
name='estimated_rep_duration',
|
||||||
|
field=models.FloatField(blank=True, max_length=255, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -21,6 +21,7 @@ class Exercise(models.Model):
|
|||||||
equipment_required = models.CharField(null=True, blank=True, max_length=255)
|
equipment_required = models.CharField(null=True, blank=True, max_length=255)
|
||||||
muscle_groups = models.CharField(null=True, blank=True, max_length=255)
|
muscle_groups = models.CharField(null=True, blank=True, max_length=255)
|
||||||
synonyms = models.CharField(null=True, blank=True, max_length=255)
|
synonyms = models.CharField(null=True, blank=True, max_length=255)
|
||||||
|
estimated_rep_duration = models.FloatField(null=True, blank=True, max_length=255)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('name',)
|
ordering = ('name',)
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ from . import views
|
|||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# path('sync_equipment/', views.sync_equipment, name='sync_equipment'),
|
path('sync_equipment/', views.sync_equipment, name='sync_equipment'),
|
||||||
# path('sync_muscle_groups/', views.sync_muscle_groups, name='sync_equipment'),
|
path('sync_muscle_groups/', views.sync_muscle_groups, name='sync_equipment'),
|
||||||
]
|
]
|
||||||
@@ -15,7 +15,7 @@ def sync_equipment(request):
|
|||||||
for equipment in all_equipment:
|
for equipment in all_equipment:
|
||||||
if len(equipment) > 0:
|
if len(equipment) > 0:
|
||||||
try:
|
try:
|
||||||
equipment_obj = Equipment.objects.get(name=equipment)
|
equipment_obj = Equipment.objects.get(name=equipment.lower())
|
||||||
WorkoutEquipment.objects.create(exercise=exercise, equipment=equipment_obj).save()
|
WorkoutEquipment.objects.create(exercise=exercise, equipment=equipment_obj).save()
|
||||||
except Equipment.DoesNotExist:
|
except Equipment.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
@@ -32,7 +32,7 @@ def sync_muscle_groups(request):
|
|||||||
if len(muscle_group) > 0:
|
if len(muscle_group) > 0:
|
||||||
try:
|
try:
|
||||||
print(muscle_group)
|
print(muscle_group)
|
||||||
muscle_obj = Muscle.objects.get(name=muscle_group)
|
muscle_obj = Muscle.objects.get(name=muscle_group.lower())
|
||||||
print(muscle_obj)
|
print(muscle_obj)
|
||||||
ExerciseMuscle.objects.create(exercise=exercise, muscle=muscle_obj).save()
|
ExerciseMuscle.objects.create(exercise=exercise, muscle=muscle_obj).save()
|
||||||
except MuscleGroup.DoesNotExist:
|
except MuscleGroup.DoesNotExist:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class SupersetExerciseInline(admin.StackedInline):
|
|||||||
|
|
||||||
@admin.register(Superset)
|
@admin.register(Superset)
|
||||||
class SupersetAdmin(ImportExportModelAdmin):
|
class SupersetAdmin(ImportExportModelAdmin):
|
||||||
list_display = ("name", "workout", "order", "rounds", "get_workout_id",)
|
list_display = ("name", "workout", "order", "rounds", "get_workout_id", "estimated_time",)
|
||||||
ordering = ("order",)
|
ordering = ("order",)
|
||||||
inlines = [
|
inlines = [
|
||||||
SupersetExerciseInline,
|
SupersetExerciseInline,
|
||||||
|
|||||||
20
superset/migrations/0006_alter_superset_workout.py
Normal file
20
superset/migrations/0006_alter_superset_workout.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-07-25 15:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('workout', '0011_alter_completedworkout_notes'),
|
||||||
|
('superset', '0005_supersetexercise_order'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='superset',
|
||||||
|
name='workout',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='superset_workout', to='workout.workout'),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
superset/migrations/0007_superset_estimated_time.py
Normal file
18
superset/migrations/0007_superset_estimated_time.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-07-25 16:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('superset', '0006_alter_superset_workout'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='superset',
|
||||||
|
name='estimated_time',
|
||||||
|
field=models.FloatField(blank=True, max_length=255, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -10,11 +10,13 @@ class Superset(models.Model):
|
|||||||
|
|
||||||
workout = models.ForeignKey(
|
workout = models.ForeignKey(
|
||||||
Workout,
|
Workout,
|
||||||
on_delete=models.CASCADE
|
on_delete=models.CASCADE,
|
||||||
|
related_name='superset_workout'
|
||||||
)
|
)
|
||||||
|
|
||||||
rounds = models.IntegerField(max_length=3, blank=False, null=False)
|
rounds = models.IntegerField(max_length=3, blank=False, null=False)
|
||||||
order = models.IntegerField(max_length=3, blank=False, null=False)
|
order = models.IntegerField(max_length=3, blank=False, null=False)
|
||||||
|
estimated_time = models.FloatField(max_length=255, blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name #+ " : " + self.description + " | by: " + self.registered_user.nick_name
|
return self.name #+ " : " + self.description + " | by: " + self.registered_user.nick_name
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ urlpatterns = [
|
|||||||
path('muscle/', include('muscle.urls')),
|
path('muscle/', include('muscle.urls')),
|
||||||
path('equipment/', include('equipment.urls')),
|
path('equipment/', include('equipment.urls')),
|
||||||
path('registered_user/', include('registered_user.urls')),
|
path('registered_user/', include('registered_user.urls')),
|
||||||
path('.well-known/apple-app-site-association', TemplateView.as_view(template_name='frontend/apple-app-site-association', content_type='application/json',))
|
path('.well-known/apple-app-site-association', TemplateView.as_view(template_name='frontend/apple-app-site-association', content_type='application/json',)),
|
||||||
# path('scripts/', include('scripts.urls')),
|
# path('scripts/', include('scripts.urls')),
|
||||||
] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
|
] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class SupersetInline(admin.StackedInline):
|
|||||||
|
|
||||||
@admin.register(Workout)
|
@admin.register(Workout)
|
||||||
class WorkoutAdmin(ImportExportModelAdmin):
|
class WorkoutAdmin(ImportExportModelAdmin):
|
||||||
list_display = ("name", "description", "registered_user", "created_at", "updated_at")
|
list_display = ("name", "description", "estimated_time", "registered_user", "created_at", "updated_at")
|
||||||
inlines = [
|
inlines = [
|
||||||
SupersetInline,
|
SupersetInline,
|
||||||
]
|
]
|
||||||
|
|||||||
18
workout/migrations/0012_workout_estimated_time.py
Normal file
18
workout/migrations/0012_workout_estimated_time.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-07-25 16:43
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('workout', '0011_alter_completedworkout_notes'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='workout',
|
||||||
|
name='estimated_time',
|
||||||
|
field=models.FloatField(blank=True, max_length=255, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -20,6 +20,7 @@ class Workout(models.Model):
|
|||||||
RegisteredUser,
|
RegisteredUser,
|
||||||
on_delete=models.CASCADE
|
on_delete=models.CASCADE
|
||||||
)
|
)
|
||||||
|
estimated_time = models.FloatField(max_length=255, blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name #+ " : " + self.description + " | by: " + self.registered_user.nick_name
|
return self.name #+ " : " + self.description + " | by: " + self.registered_user.nick_name
|
||||||
|
|||||||
16510
workout/sample_workout.json
Normal file
16510
workout/sample_workout.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -82,7 +82,7 @@ class WorkoutDetailSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Workout
|
model = Workout
|
||||||
fields = ('id', 'name', 'description', 'supersets', 'registered_user', 'male_videos', 'female_videos', 'both_videos')
|
fields = ('id', 'name', 'description', 'supersets', 'registered_user', 'male_videos', 'female_videos', 'both_videos', 'estimated_time', )
|
||||||
depth = 1
|
depth = 1
|
||||||
|
|
||||||
def get_supersets(self, obj):
|
def get_supersets(self, obj):
|
||||||
|
|||||||
@@ -10,4 +10,6 @@ urlpatterns = [
|
|||||||
path('create/', views.add_workout, name='create new workout'),
|
path('create/', views.add_workout, name='create new workout'),
|
||||||
path('planned_workouts/', views.workouts_planned_by_logged_in_user, name='planned workout for user'),
|
path('planned_workouts/', views.workouts_planned_by_logged_in_user, name='planned workout for user'),
|
||||||
path('plan_workout/', views.plan_workout, name='plan workout'),
|
path('plan_workout/', views.plan_workout, name='plan workout'),
|
||||||
|
|
||||||
|
path('add_from_files/', views.add_from_files, name='plan workout'),
|
||||||
]
|
]
|
||||||
100
workout/views.py
100
workout/views.py
@@ -26,8 +26,8 @@ def all_workouts(request):
|
|||||||
|
|
||||||
@api_view(['GET'])
|
@api_view(['GET'])
|
||||||
def workout_details(request, workout_id):
|
def workout_details(request, workout_id):
|
||||||
users = Workout.objects.get(pk=workout_id)
|
workout = Workout.objects.get(pk=workout_id)
|
||||||
serializer = WorkoutDetailSerializer(users, many=False)
|
serializer = WorkoutDetailSerializer(workout, many=False)
|
||||||
return Response(data=serializer.data, status=status.HTTP_200_OK)
|
return Response(data=serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
@api_view(['POST'])
|
@api_view(['POST'])
|
||||||
@@ -73,6 +73,7 @@ def add_workout(request):
|
|||||||
workout = serializer.save(registered_user=registered_user)
|
workout = serializer.save(registered_user=registered_user)
|
||||||
workout.save()
|
workout.save()
|
||||||
|
|
||||||
|
workout_total_time = 0
|
||||||
for superset in exercise_data:
|
for superset in exercise_data:
|
||||||
name = superset["name"]
|
name = superset["name"]
|
||||||
rounds = superset["rounds"]
|
rounds = superset["rounds"]
|
||||||
@@ -87,6 +88,7 @@ def add_workout(request):
|
|||||||
)
|
)
|
||||||
superset.save()
|
superset.save()
|
||||||
|
|
||||||
|
superset_total_time = 0
|
||||||
for exercise in exercises:
|
for exercise in exercises:
|
||||||
exercise_id = exercise["id"]
|
exercise_id = exercise["id"]
|
||||||
exercise_obj = Exercise.objects.get(pk=exercise_id)
|
exercise_obj = Exercise.objects.get(pk=exercise_id)
|
||||||
@@ -102,11 +104,21 @@ def add_workout(request):
|
|||||||
supersetExercise.weight = exercise["weight"]
|
supersetExercise.weight = exercise["weight"]
|
||||||
if "reps" in exercise:
|
if "reps" in exercise:
|
||||||
supersetExercise.reps = exercise["reps"]
|
supersetExercise.reps = exercise["reps"]
|
||||||
|
superset_total_time += exercise["reps"] * exercise_obj.estimated_rep_duration
|
||||||
if "duration" in exercise:
|
if "duration" in exercise:
|
||||||
supersetExercise.duration = exercise["duration"]
|
supersetExercise.duration = exercise["duration"]
|
||||||
|
superset_total_time += exercise["duration"]
|
||||||
|
|
||||||
supersetExercise.save()
|
supersetExercise.save()
|
||||||
|
|
||||||
|
superset.estimated_time = superset_total_time
|
||||||
|
superset.save()
|
||||||
|
|
||||||
|
workout_total_time += (superset_total_time * rounds)
|
||||||
|
|
||||||
superset_order += 1
|
superset_order += 1
|
||||||
|
workout.estimated_time = workout_total_time
|
||||||
|
workout.save()
|
||||||
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
@@ -132,3 +144,87 @@ def plan_workout(request):
|
|||||||
serializer.save()
|
serializer.save()
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
|
@api_view(['GET'])
|
||||||
|
def add_from_files(request):
|
||||||
|
with open("/Users/treyt/Desktop/code/werkout/werkout_api/workout/sample_workout.json") as user_file:
|
||||||
|
file_contents = user_file.read()
|
||||||
|
parsed_json = json.loads(file_contents)
|
||||||
|
|
||||||
|
for item in parsed_json:
|
||||||
|
workout_name = item["name"]
|
||||||
|
workout_description = item["description"]
|
||||||
|
workout_created = item["created"]
|
||||||
|
|
||||||
|
workout_obj = Workout.objects.create(
|
||||||
|
registered_user = RegisteredUser.objects.get(pk=2),
|
||||||
|
description = workout_description,
|
||||||
|
name = workout_name,
|
||||||
|
created_at = workout_created
|
||||||
|
)
|
||||||
|
|
||||||
|
workout_obj.save()
|
||||||
|
workout_obj.created_at = workout_created
|
||||||
|
workout_obj.save(update_fields=['created_at'])
|
||||||
|
workout_total_time = 0
|
||||||
|
|
||||||
|
supersets = item["supersets"]
|
||||||
|
superset_order = 1
|
||||||
|
for superset in supersets:
|
||||||
|
superset_name = superset["name"]
|
||||||
|
superset_rounds = superset["rounds"]
|
||||||
|
|
||||||
|
superset_obj = Superset.objects.create(
|
||||||
|
workout=workout_obj,
|
||||||
|
name=superset_name,
|
||||||
|
rounds=superset_rounds,
|
||||||
|
order=superset_order
|
||||||
|
)
|
||||||
|
|
||||||
|
superset_obj.save()
|
||||||
|
|
||||||
|
superset_order += 1
|
||||||
|
|
||||||
|
exercises = superset["exercises"]
|
||||||
|
exercise_order = 1
|
||||||
|
|
||||||
|
superset_total_time = 0
|
||||||
|
for exercise in exercises:
|
||||||
|
side = exercise["side"]
|
||||||
|
name = exercise["name"]
|
||||||
|
|
||||||
|
duration = exercise["duration"]
|
||||||
|
reps = exercise["reps"]
|
||||||
|
side = exercise["side"]
|
||||||
|
|
||||||
|
exercise_obj = None
|
||||||
|
if len(side) > 0:
|
||||||
|
exercise_obj = Exercise.objects.get(name=name, side=side)
|
||||||
|
else:
|
||||||
|
exercise_obj = Exercise.objects.get(name=name, side="")
|
||||||
|
|
||||||
|
supersetExercise = SupersetExercise.objects.create(
|
||||||
|
superset=superset_obj,
|
||||||
|
exercise=exercise_obj,
|
||||||
|
order=exercise_order
|
||||||
|
)
|
||||||
|
|
||||||
|
if reps != 0:
|
||||||
|
supersetExercise.reps = reps
|
||||||
|
superset_total_time += reps * exercise_obj.estimated_rep_duration
|
||||||
|
if reps == 0 and duration != 0:
|
||||||
|
supersetExercise.duration = duration
|
||||||
|
superset_total_time += exercise["duration"]
|
||||||
|
supersetExercise.save()
|
||||||
|
|
||||||
|
exercise_order += 1
|
||||||
|
|
||||||
|
superset_obj.estimated_time = superset_total_time
|
||||||
|
superset_obj.save()
|
||||||
|
|
||||||
|
workout_total_time += (superset_total_time * superset_rounds)
|
||||||
|
|
||||||
|
workout_obj.estimated_time = workout_total_time
|
||||||
|
workout_obj.save()
|
||||||
|
|
||||||
|
return Response(status=status.HTTP_200_OK)
|
||||||
Reference in New Issue
Block a user