Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Expose the max RiR over the API

Roland Geider9134649b103e
diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.py
index 199e1a8f8..927ba4254 100644
--- a/wger/manager/api/serializers.py
+++ b/wger/manager/api/serializers.py
@@ -354,6 +354,7 @@ class SetConfigDataSerializer(serializers.Serializer):
reps_unit = serializers.IntegerField()
reps_rounding = serializers.DecimalField(max_digits=4, decimal_places=2)
rir = serializers.DecimalField(max_digits=5, decimal_places=2)
+ max_rir = serializers.DecimalField(max_digits=5, decimal_places=2)
rpe = serializers.DecimalField(max_digits=5, decimal_places=2)
rest = serializers.DecimalField(max_digits=5, decimal_places=2)
max_rest = serializers.DecimalField(max_digits=5, decimal_places=2)
diff --git a/wger/manager/dataclasses.py b/wger/manager/dataclasses.py
index acdc75915..3928c3444 100644
--- a/wger/manager/dataclasses.py
+++ b/wger/manager/dataclasses.py
@@ -48,6 +48,7 @@ class SetConfigData:
weight: Decimal | int | None
reps: Decimal | int | None
rir: Decimal | int | None
+ max_rir: Decimal | int | None
rest: int | None
max_weight: Decimal | int | None = None
@@ -219,8 +220,8 @@ class RoutineLogData:
def round_value(
- x: int | float | Decimal | None,
- base: int | float | Decimal | None = None,
+ x: int | float | Decimal | None,
+ base: int | float | Decimal | None = None,
) -> Decimal | None:
"""
Rounds a value to the nearest base
diff --git a/wger/manager/models/slot_entry.py b/wger/manager/models/slot_entry.py
index 56c558c7f..41fb30c5d 100644
--- a/wger/manager/models/slot_entry.py
+++ b/wger/manager/models/slot_entry.py
@@ -308,6 +308,7 @@ class SlotEntry(models.Model):
# TODO: decide on whether to return None or always the unit
# reps_unit=self.repetition_unit.pk if reps is not None else None,
rir=self.get_rir(iteration),
+ max_rir=self.get_max_rir(iteration),
rest=round_value(rest, 1),
max_rest=round_value(max_rest, 1) if max_rest and rest and max_rest > rest else None,
type=str(self.type),
@@ -369,6 +370,14 @@ class SlotEntry(models.Model):
)
)
+ def get_max_rir(self, iteration: int) -> Decimal | None:
+ return self.calculate_config_value(
+ self.duplicate_configs(
+ iteration,
+ list(self.maxrirconfig_set.filter(iteration__lte=iteration)),
+ )
+ )
+
def get_rest(self, iteration: int) -> Decimal | None:
return self.calculate_config_value(
self.duplicate_configs(