Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature statistics #1645

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Developers
* Alexandra Rhodes - https://github.com/arhodes130
* Jayanth Bontha - https://github.com/JayanthBontha
* Ethan Winters - https://github.com/ebwinters
* Sahaij Gadhri - https://github.com/gsahaij

Translators
-----------
Expand Down
Binary file added wger/.DS_Store
Binary file not shown.
Binary file added wger/manager/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions wger/manager/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class Meta:
'rir',
'order',
'comment',
'moved',
]


Expand Down
6 changes: 4 additions & 2 deletions wger/manager/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ def get_queryset(self):
# REST API generation
if getattr(self, 'swagger_fake_view', False):
return Setting.objects.none()

print(Setting.objects.filter(set__exerciseday__training__user=self.request.user))
print("API ACCESS HERE")
return Setting.objects.filter(set__exerciseday__training__user=self.request.user)

def perform_create(self, serializer):
Expand Down Expand Up @@ -403,16 +404,17 @@ class WorkoutLogViewSet(WgerOwnerObjectModelViewSet):
'workout',
'repetition_unit',
'weight_unit',
'moved',
)

def get_queryset(self):
"""
Only allow access to appropriate objects
"""
print("API CALL HERE?")
# REST API generation
if getattr(self, 'swagger_fake_view', False):
return WorkoutLog.objects.none()

return WorkoutLog.objects.filter(user=self.request.user)

def perform_create(self, serializer):
Expand Down
10 changes: 7 additions & 3 deletions wger/manager/fixtures/test-workout-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@
"weight_unit_id": 1,
"weight": null,
"order": 1,
"exercise_base": 2
"exercise_base": 2,
"moved": null
}
},


{
"pk": 1,
"model": "manager.workoutlog",
Expand All @@ -170,7 +172,8 @@
"reps": 8,
"user": 1,
"date": "2012-10-01",
"exercise_base": 1
"exercise_base": 1,
"moved": 100
}
},
{
Expand All @@ -194,7 +197,8 @@
"reps": 8,
"user": 1,
"date": "2013-10-30",
"exercise_base": 1
"exercise_base": 1,
"moved": null
}
},
{
Expand Down
7 changes: 7 additions & 0 deletions wger/manager/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ class WorkoutLogForm(ModelForm):
choices=RIR_OPTIONS,
required=False,
)
moved = DecimalField(
label=_('Moved'),
initial=0,
required=False,
)


class Meta:
model = WorkoutLog
Expand All @@ -210,6 +216,7 @@ def __init__(self, *args, **kwargs):
Column('weight', css_class='col-2'),
Column('weight_unit', css_class='col-3'),
Column('rir', css_class='col-2'),
Column('moved',css_class='col-2'),
css_class='form-row',
),
)
Expand Down
19 changes: 19 additions & 0 deletions wger/manager/migrations/0018_setting_moved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.6 on 2024-04-19 18:47

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('manager', '0017_alter_workoutlog_exercise_base'),
]

operations = [
migrations.AddField(
model_name='setting',
name='moved',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=6, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1500)], verbose_name='Weight-Moved'),
),
]
20 changes: 20 additions & 0 deletions wger/manager/migrations/0019_alter_setting_moved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.6 on 2024-04-20 04:42

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('manager', '0018_setting_moved'),
]

operations = [
migrations.AlterField(
model_name='setting',
name='moved',
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=6, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1500)], verbose_name='Weight-Moved'),
preserve_default=False,
),
]
19 changes: 19 additions & 0 deletions wger/manager/migrations/0020_alter_setting_moved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.6 on 2024-04-20 05:12

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('manager', '0019_alter_setting_moved'),
]

operations = [
migrations.AlterField(
model_name='setting',
name='moved',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=6, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1500)], verbose_name='Weight-Moved'),
),
]
19 changes: 19 additions & 0 deletions wger/manager/migrations/0021_alter_setting_moved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.6 on 2024-04-20 05:14

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('manager', '0020_alter_setting_moved'),
]

operations = [
migrations.AlterField(
model_name='setting',
name='moved',
field=models.DecimalField(decimal_places=2, max_digits=6, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1500)], verbose_name='Weight-Moved'),
),
]
19 changes: 19 additions & 0 deletions wger/manager/migrations/0022_alter_setting_moved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.6 on 2024-04-20 16:23

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('manager', '0021_alter_setting_moved'),
]

operations = [
migrations.AlterField(
model_name='setting',
name='moved',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=6, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1500)], verbose_name='Weight-Moved'),
),
]
20 changes: 20 additions & 0 deletions wger/manager/migrations/0023_alter_setting_moved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.6 on 2024-04-20 16:25

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('manager', '0022_alter_setting_moved'),
]

operations = [
migrations.AlterField(
model_name='setting',
name='moved',
field=models.DecimalField(decimal_places=2, default=1, max_digits=6, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1500)], verbose_name='Weight-Moved'),
preserve_default=False,
),
]
19 changes: 19 additions & 0 deletions wger/manager/migrations/0024_alter_setting_moved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.6 on 2024-04-20 16:26

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('manager', '0023_alter_setting_moved'),
]

operations = [
migrations.AlterField(
model_name='setting',
name='moved',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=6, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1500)], verbose_name='Weight-Moved'),
),
]
19 changes: 19 additions & 0 deletions wger/manager/migrations/0025_workoutlog_moved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.6 on 2024-04-20 16:45

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('manager', '0024_alter_setting_moved'),
]

operations = [
migrations.AddField(
model_name='workoutlog',
name='moved',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=6, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Weight-Moved'),
),
]
11 changes: 11 additions & 0 deletions wger/manager/models/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ class WorkoutLog(models.Model):
Reps in reserve, RiR. The amount of reps that could realistically still be
done in the set.
"""
moved = models.DecimalField(
verbose_name=_('Weight-Moved'),
max_digits=6,
decimal_places=2,
blank=True,
null=True,
validators=[MinValueValidator(0)],
)
"""
The tonnage moved during this set
"""

# Metaclass to set some other properties
class Meta:
Expand Down
16 changes: 14 additions & 2 deletions wger/manager/models/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,19 @@ class Setting(models.Model):

order = models.IntegerField(blank=True, verbose_name=_('Order'))
comment = models.CharField(max_length=100, blank=True, verbose_name=_('Comment'))


"""
The tonnage moved during this set
"""
moved = models.DecimalField(
verbose_name=_('Weight-Moved'),
max_digits=6,
decimal_places=2,
blank=True,
null=True,
validators=[MinValueValidator(0), MaxValueValidator(1500)],
)

# Metaclass to set some other properties
class Meta:
ordering = ['order', 'id']
Expand All @@ -127,7 +139,7 @@ def save(self, *args, **kwargs):
reset_workout_canonical_form(self.set.exerciseday.training_id)

# If the user selected "Until Failure", do only 1 "repetition",
# everythin else doesn't make sense.
# everythi else doesn't make sense.
if self.repetition_unit == 2:
self.reps = 1
super(Setting, self).save(*args, **kwargs)
Expand Down
Binary file added wger/manager/templates/.DS_Store
Binary file not shown.
15 changes: 12 additions & 3 deletions wger/manager/views/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# ************************
# Set functions
# ************************
SETTING_FORMSET_FIELDS = ('reps', 'repetition_unit', 'weight', 'weight_unit', 'rir')
SETTING_FORMSET_FIELDS = ('reps', 'repetition_unit', 'weight', 'weight_unit', 'rir', 'moved')

SettingFormset = modelformset_factory(
Setting,
Expand All @@ -78,16 +78,18 @@ def create(request, day_pk):
context = {}
formsets = []
form = SetForm(initial={'sets': Set.DEFAULT_SETS})

print(request.POST)
# If the form and all formsets validate, save them
if request.method == 'POST':
form = SetForm(request.POST)
if form.is_valid():
print(form.cleaned_data)
for base in form.cleaned_data['exercises']:
formset = SettingFormset(
request.POST, queryset=Setting.objects.none(), prefix=f'base{base.id}'
)
formsets.append({'exercise_base': base, 'formset': formset})
print(formsets)
all_valid = True

for formset in formsets:
Expand All @@ -99,7 +101,13 @@ def create(request, day_pk):
max_order = day.set_set.select_related().aggregate(models.Max('order'))
form.instance.order = (max_order['order__max'] or 0) + 1
form.instance.exerciseday = day
set_obj = form.save()
# Need a try acccept for the case where we don't input any value for these
try:
reps = form.cleaned_data['reps']
weight = form.cleaned_data['weight']
except:
form.instance.moved = reps * weight
set_obj = form.save()

order = 1
for formset in formsets:
Expand All @@ -123,6 +131,7 @@ def create(request, day_pk):
context['max_sets'] = Set.MAX_SETS
context['formsets'] = formsets
context['helper'] = WorkoutLogFormHelper()
print(context)
return render(request, 'set/add.html', context)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.6 on 2024-04-19 18:47

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('nutrition', '0020_full_text_search'),
]

operations = [
migrations.RenameIndex(
model_name='ingredient',
new_name='nutrition_i_name_8f538f_gin',
old_name='nutrition_i_search__f274b7_gin',
),
]
2 changes: 1 addition & 1 deletion wger/settings_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
'django.template.loaders.app_directories.Loader',
],
'debug':
False
True
},
},
]
Expand Down