Skip to content

Commit

Permalink
Statistics for Workouts
Browse files Browse the repository at this point in the history
- Change manager_settings table to include a "moved" column
- Calculate the tonnage moved in set.py
- Work in progress
  • Loading branch information
gsahaij committed Apr 26, 2024
1 parent e62000a commit 6bc31ce
Show file tree
Hide file tree
Showing 24 changed files with 262 additions and 16 deletions.
Binary file added .DS_Store
Binary file not shown.
11 changes: 6 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Proposed Changes

-
-
-
- Change manager_settings table to include a "moved" column
- Calculate the tonnage moved in set.py
- Work in progress

## Please check that the PR fulfills these requirements

- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Added yourself to AUTHORS.rst
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Added yourself to AUTHORS.rst

### Other questions

* Do users need to run some commmands in their local instances due to this PR
(e.g. database migration)?
yes. Run make migrations, there are database contributions.
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
26 changes: 26 additions & 0 deletions notes_DELETE_THIS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
WGER NOTES

Dynamic Measurements:

When you call the front page, these are the APIs you hit
"GET /api/v2/meal/?plan=1 HTTP/1.1" 200 52
"GET /api/v2/nutritiondiary/?plan=1&limit=999 HTTP/1.1" 200 311
"GET /api/v2/setting-repetitionunit/ HTTP/1.1" 200 245
"GET /api/v2/setting-weightunit/ HTTP/1.1" 200 219

When you enter the bmi calculator screen:
Therefore, no APIS get called (super interesting, maybe we should add height to the database?)
If height is added to the database, then we can access it later to make it part of the measurement
"GET /en/nutrition/calculator/bmi/ HTTP/1.1" 200 31265
"GET /nutrition/calculator/bmi/chart-data HTTP/1.1" 302 0
"GET /en/nutrition/calculator/bmi/chart-data HTTP/1.1" 200 1031
"POST /en/nutrition/calculator/bmi/calculate HTTP/1.1" 200 53

Line 192 in urls.py has the weight-entry
we should run a "heightentry" as well to get height

We should also maybe look at adding height as a one time thing



Encrypting Inputs:
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.

0 comments on commit 6bc31ce

Please sign in to comment.