From 6bc31ce4f03565752268c622cc574626c2c3d3f9 Mon Sep 17 00:00:00 2001 From: Sahaij Gadhri Date: Fri, 26 Apr 2024 02:58:48 -0400 Subject: [PATCH] Statistics for Workouts - Change manager_settings table to include a "moved" column - Calculate the tonnage moved in set.py - Work in progress --- .DS_Store | Bin 0 -> 8196 bytes .github/pull_request_template.md | 11 ++++---- AUTHORS.rst | 1 + notes_DELETE_THIS.txt | 26 ++++++++++++++++++ wger/.DS_Store | Bin 0 -> 8196 bytes wger/manager/.DS_Store | Bin 0 -> 8196 bytes wger/manager/api/serializers.py | 1 + wger/manager/api/views.py | 6 ++-- wger/manager/fixtures/test-workout-data.json | 10 +++++-- wger/manager/forms.py | 7 +++++ wger/manager/migrations/0018_setting_moved.py | 19 +++++++++++++ .../migrations/0019_alter_setting_moved.py | 20 ++++++++++++++ .../migrations/0020_alter_setting_moved.py | 19 +++++++++++++ .../migrations/0021_alter_setting_moved.py | 19 +++++++++++++ .../migrations/0022_alter_setting_moved.py | 19 +++++++++++++ .../migrations/0023_alter_setting_moved.py | 20 ++++++++++++++ .../migrations/0024_alter_setting_moved.py | 19 +++++++++++++ .../migrations/0025_workoutlog_moved.py | 19 +++++++++++++ wger/manager/models/log.py | 11 ++++++++ wger/manager/models/setting.py | 16 +++++++++-- wger/manager/templates/.DS_Store | Bin 0 -> 6148 bytes wger/manager/views/set.py | 15 ++++++++-- ..._f274b7_gin_nutrition_i_name_8f538f_gin.py | 18 ++++++++++++ wger/settings_global.py | 2 +- 24 files changed, 262 insertions(+), 16 deletions(-) create mode 100644 .DS_Store create mode 100644 notes_DELETE_THIS.txt create mode 100644 wger/.DS_Store create mode 100644 wger/manager/.DS_Store create mode 100644 wger/manager/migrations/0018_setting_moved.py create mode 100644 wger/manager/migrations/0019_alter_setting_moved.py create mode 100644 wger/manager/migrations/0020_alter_setting_moved.py create mode 100644 wger/manager/migrations/0021_alter_setting_moved.py create mode 100644 wger/manager/migrations/0022_alter_setting_moved.py create mode 100644 wger/manager/migrations/0023_alter_setting_moved.py create mode 100644 wger/manager/migrations/0024_alter_setting_moved.py create mode 100644 wger/manager/migrations/0025_workoutlog_moved.py create mode 100644 wger/manager/templates/.DS_Store create mode 100644 wger/nutrition/migrations/0021_rename_nutrition_i_search__f274b7_gin_nutrition_i_name_8f538f_gin.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6a8a773f87c4821f02eb39e66a8eb48e66ddcbcb GIT binary patch literal 8196 zcmeHML2nyH6n>M2#>Q>3X>FQoSMMVhJbrPsW+XUN$L~Su^@5F4g-Z8uD zxM>uWGo1JVaOcDoi9f)FD>uYXfGYCmm+r^T)a_~;^F%k4+Zog8fN6#cnacmY}Y&I~bbU>9+aG;q zYIYO-n*E>~t?8edUDpZ1<>lYl)Vb-G&d+3KGP%sd+83f<3$3shlr8_hys8V~HV3xV z+;(`sVdU3@7g~u!m_ z2_50>J_x{bCFGrowDl9Iyd@e&4Z~moeES5eR7;kFBprSU2iY0C;JCh$YMVe*np740Fw51!e_|bL^ zNqLvHv1vV_Z|OVwfqtf6=y&>){$VrBU~jN%>^gg&-DJ1f$E?a)%w`Vrb%3eCLzY{9 ztT6fcc=(VHYQEz zn&wuG|p+0Jw5M@MdP6?yen<2(>%W>^D2}-pqV&cfRp#h=|pC zt#zU$BC?Q`wM)2+Nvd7tku(w4EW3?1!d1&6K1c3`Zb6Ek#T@yIMbp)frx9yf)gcEgadGO;vcAi(ZjeiyeB^*m!E#B0eS|*R z)I*(vF9@ElQ{NCWy|Gs^y-g?i>G`rRGuSDO4TxuOe`at+%XCLp6_a9;UJ8 zspPCK)t*`!{s6A9mw6==)~Z_rhpx?PoSIIdx^aU=^&A^|1a( z_Un-o^}?DH+*fydQu@td*=g>3yx*`F?nn_ip5TEdcr6adgHJrslKqEZ*H8gl+WIJV{N5;>&=bx^P;s_dHwC(#2TM=Fus+3io*s!j5nb9{Ns` z``e->qeylRogi>To7YYcJXZ=c^I6?3Zg&E%x~$y(!-!d_emE?=W(qb{Oo6CUy=RKn z!mui~thgtn;Fao*sVL%y!cDxUAJIM?(-ZoNzNT;K2l|nIq2K8*R$w-JmEB~w*gNbt z`+$AScA3js%wvJ+U}E^FRWL~;7UCxJs88yF@TF*@MX_e^B5*8)P=_k6?*x`-CP1jg zoLUw|ETA560Ty)}-qH(61*;TeMhBiqqXm{;I6e&M<@$MIxz3O98epr?(A1$}Tu?;- zOpR@!4~dW*Q6HR z^W{*uO^+x_>#KG8Eum8Z*bqohf2z)GGup!>I`Nh~OT|g!%u)&Vz01GzT^tz z3S<;uQ+MlkYp5LVjG1z2>f^IV<27&FVHL0nSOu&CRspNPzn}p2Y%b1*eP7?TwN=0>@Lwvx-w!T~ z(KDE7R9_va)DZw!MYk$w;~bzku0hXWrcqHbranCgLlx$TAv7KLU3Le01~ZMCPD0a3 zn3;t+p$IiQc&>6M;c2wBRlq8+t^l9io9fISQk*-#Up$WFi62QH9{fjj1l#+r3R*-J z8sL;47Q8+eyz0tpOo@6YP#9C(EOg=nbNN2mdKeD4--CkN8&N zFX1^VA75qpX(h`YI>V?DG7Z2gjfpttJZFTgW7sKJBUnsnAui5*mD7aZFV2RU1ZTg> z+5s!XEE8~3w3K#*nOK2U&NeubhAOLqTAaPOn#(>><8v<2=InEv1|s3C$6#<&>uZAC zf5-4=$=E!5U;J?tCTXYhRcuwNwe7l7cbd+t-kF^B(m^^+x`W9JzIrNU z>$k2ylyN!;<6xo);V^*9%jaP{l(Vj!#=}H$d-{gca2owqdpc0=QoO cV2HL0SLS#IGmYp$u`dFY47Rcg{8a^h0I4)3;Q#;t literal 0 HcmV?d00001 diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.py index cae87e09d..df278247e 100644 --- a/wger/manager/api/serializers.py +++ b/wger/manager/api/serializers.py @@ -145,6 +145,7 @@ class Meta: 'rir', 'order', 'comment', + 'moved', ] diff --git a/wger/manager/api/views.py b/wger/manager/api/views.py index 3026f2503..d6b15975b 100644 --- a/wger/manager/api/views.py +++ b/wger/manager/api/views.py @@ -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): @@ -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): diff --git a/wger/manager/fixtures/test-workout-data.json b/wger/manager/fixtures/test-workout-data.json index 9a5f7bc9b..20e5ea636 100644 --- a/wger/manager/fixtures/test-workout-data.json +++ b/wger/manager/fixtures/test-workout-data.json @@ -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", @@ -170,7 +172,8 @@ "reps": 8, "user": 1, "date": "2012-10-01", - "exercise_base": 1 + "exercise_base": 1, + "moved": 100 } }, { @@ -194,7 +197,8 @@ "reps": 8, "user": 1, "date": "2013-10-30", - "exercise_base": 1 + "exercise_base": 1, + "moved": null } }, { diff --git a/wger/manager/forms.py b/wger/manager/forms.py index c64780a13..694bfb11e 100644 --- a/wger/manager/forms.py +++ b/wger/manager/forms.py @@ -192,6 +192,12 @@ class WorkoutLogForm(ModelForm): choices=RIR_OPTIONS, required=False, ) + moved = DecimalField( + label=_('Moved'), + initial=0, + required=False, + ) + class Meta: model = WorkoutLog @@ -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', ), ) diff --git a/wger/manager/migrations/0018_setting_moved.py b/wger/manager/migrations/0018_setting_moved.py new file mode 100644 index 000000000..7d00f036a --- /dev/null +++ b/wger/manager/migrations/0018_setting_moved.py @@ -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'), + ), + ] diff --git a/wger/manager/migrations/0019_alter_setting_moved.py b/wger/manager/migrations/0019_alter_setting_moved.py new file mode 100644 index 000000000..f2588fa4e --- /dev/null +++ b/wger/manager/migrations/0019_alter_setting_moved.py @@ -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, + ), + ] diff --git a/wger/manager/migrations/0020_alter_setting_moved.py b/wger/manager/migrations/0020_alter_setting_moved.py new file mode 100644 index 000000000..5e1c1ddb9 --- /dev/null +++ b/wger/manager/migrations/0020_alter_setting_moved.py @@ -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'), + ), + ] diff --git a/wger/manager/migrations/0021_alter_setting_moved.py b/wger/manager/migrations/0021_alter_setting_moved.py new file mode 100644 index 000000000..2e7d54e0d --- /dev/null +++ b/wger/manager/migrations/0021_alter_setting_moved.py @@ -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'), + ), + ] diff --git a/wger/manager/migrations/0022_alter_setting_moved.py b/wger/manager/migrations/0022_alter_setting_moved.py new file mode 100644 index 000000000..ff954adb7 --- /dev/null +++ b/wger/manager/migrations/0022_alter_setting_moved.py @@ -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'), + ), + ] diff --git a/wger/manager/migrations/0023_alter_setting_moved.py b/wger/manager/migrations/0023_alter_setting_moved.py new file mode 100644 index 000000000..4ae7b6eb9 --- /dev/null +++ b/wger/manager/migrations/0023_alter_setting_moved.py @@ -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, + ), + ] diff --git a/wger/manager/migrations/0024_alter_setting_moved.py b/wger/manager/migrations/0024_alter_setting_moved.py new file mode 100644 index 000000000..738e38a88 --- /dev/null +++ b/wger/manager/migrations/0024_alter_setting_moved.py @@ -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'), + ), + ] diff --git a/wger/manager/migrations/0025_workoutlog_moved.py b/wger/manager/migrations/0025_workoutlog_moved.py new file mode 100644 index 000000000..c8b218d60 --- /dev/null +++ b/wger/manager/migrations/0025_workoutlog_moved.py @@ -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'), + ), + ] diff --git a/wger/manager/models/log.py b/wger/manager/models/log.py index 4eebf38a7..08601d173 100644 --- a/wger/manager/models/log.py +++ b/wger/manager/models/log.py @@ -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: diff --git a/wger/manager/models/setting.py b/wger/manager/models/setting.py index fc8886402..0a20ea08c 100644 --- a/wger/manager/models/setting.py +++ b/wger/manager/models/setting.py @@ -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'] @@ -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) diff --git a/wger/manager/templates/.DS_Store b/wger/manager/templates/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ce1480f54d05538de8454572c07196cc9959b806 GIT binary patch literal 6148 zcmeHK%Wl&^6upxKGEs$;1xVc>Sz=p3XbTczV?tT5#RwLFf*o6}RpY7rsD+|PUbp|i zFRbgp#g%;Q{-@0n!ALquX)$M=cGL?q#iy%CCE7>~1WS!5s6V(J&Sk>h;EZ%VIrBYe6s)y05G-+nzn@?3< zg=wA?Iv|Y`P~N^y^H?=gRp)W3V*@iFM{+b9?=BXH`;$Fy|G~j>&s#j=`r*OD<#Hr% z-MRPp#q2cukgE&i3lsR)X}e)@1*}>ptMj19GnF4>WEHhyJ9G*-1+Ja~b{~*CS1)y! zu~Wb)@COBWfAHXpzQxv{-a1g|D*$kSZf&UZCnLvr7JZAYL5#qJ2?d%^VXqj%grncH zJl|q#(1eq)mk(iQ7WRfB^z3-Pr|BeogRXQ6I0ZHp=$q!4&;Mt?zyEIrxt3GFDezw@ zAO=Ul(G)4!vvn&uK5ISrdpH~OT7y4BP|-&*xO^1v!nL8_;|kEX*cwC+%zX%G8C>BM I_^S&10F4cmVE_OC literal 0 HcmV?d00001 diff --git a/wger/manager/views/set.py b/wger/manager/views/set.py index c1aa7b128..b47ba34d9 100644 --- a/wger/manager/views/set.py +++ b/wger/manager/views/set.py @@ -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, @@ -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: @@ -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: @@ -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) diff --git a/wger/nutrition/migrations/0021_rename_nutrition_i_search__f274b7_gin_nutrition_i_name_8f538f_gin.py b/wger/nutrition/migrations/0021_rename_nutrition_i_search__f274b7_gin_nutrition_i_name_8f538f_gin.py new file mode 100644 index 000000000..69dc6d997 --- /dev/null +++ b/wger/nutrition/migrations/0021_rename_nutrition_i_search__f274b7_gin_nutrition_i_name_8f538f_gin.py @@ -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', + ), + ] diff --git a/wger/settings_global.py b/wger/settings_global.py index 2cf80e560..82bd7c1ef 100644 --- a/wger/settings_global.py +++ b/wger/settings_global.py @@ -172,7 +172,7 @@ 'django.template.loaders.app_directories.Loader', ], 'debug': - False + True }, }, ]