Self hosted FLOSS fitness/workout, nutrition and weight tracker
Filter data for weight log chart
Roland Geider96839b7687b1
diff --git a/manager/models.py b/manager/models.pyindex 56268f7c2..763c9b49d 100644--- a/manager/models.py+++ b/manager/models.py@@ -199,10 +199,12 @@ class WorkoutLog(models.Model):Processes and regroups a list of log entries so they can be renderedand passed to the D3 library to render a chart'''+reps = []entry_log = SortedDict()chart_data = []-+ max_weight = {}+# Group by datefor entry in logs:if entry.reps not in reps:@@ -212,17 +214,34 @@ class WorkoutLog(models.Model):entry_log[entry.date] = []entry_log[entry.date].append(entry)- # Group by repetition and return as a dictionary+ # Find the maximum weight per date per repetition.+ # If on a day there are several entries with the same number of+ # repetitions, but different weights, only the entry with the+ # higher weight is shown in the chart+ if not max_weight.get(entry.date):+ max_weight[entry.date] = {entry.reps: entry.weight}++ if not max_weight[entry.date].get(entry.reps):+ max_weight[entry.date][entry.reps] = entry.weight++ if entry.weight > max_weight[entry.date][entry.reps]:+ max_weight[entry.date][entry.reps] = entry.weight++ # Group by repetitionsfor entry in logs:temp = {'date': '%s' % entry.date,'id': 'workout-log-%s' % entry.id}+for rep in reps:if entry.reps == rep:- temp[rep] = entry.weight++ # Only add if entry is the maximum for the day+ if entry.weight == max_weight[entry.date][entry.reps]:+ temp[rep] = entry.weightelse:temp[rep] = 0chart_data.append(temp)-+return (entry_log, json.dumps(chart_data, cls=DecimalJsonEncoder))diff --git a/manager/templates/workout/log.html b/manager/templates/workout/log.htmlindex 7ba4c3fb4..98b86caaf 100644--- a/manager/templates/workout/log.html+++ b/manager/templates/workout/log.html@@ -92,13 +92,16 @@ function custom_modal_init()</a></p>-<h3>{% trans "Note" %}</h3>-<p>{% blocktrans %}-This page shows the weight logs belonging to this workout only. Click on an-exercise to see all the historical data for it.-{% endblocktrans %}</p>--<p>{% blocktrans %}-Click on a value on a chart to edit the log entry.-{% endblocktrans %}</p>+<h3>{% trans "Notes" %}</h3>+<p>{% blocktrans %}This page shows the weight logs belonging to this workout+only. Click on an exercise to see all the historical data for+it.{% endblocktrans %}</p>++<p>{% blocktrans %}Click on a value on a chart to edit the log+entry.{% endblocktrans %}</p>++<p>{% blocktrans %}If on a single day there is more than one entry with the+same number of repetitions, but different weights, only the entry with the+higher weight is shown in the diagram.{% endblocktrans %}</p>+{% endblock %}