diff --git a/app.py b/app.py index fd6bac6..8d72aa5 100644 --- a/app.py +++ b/app.py @@ -418,6 +418,9 @@ def get_exercise_progress_for_user(person_id, exercise_id): 'max_date'), '%Y-%m-%d') epoch = request.args.get('epoch', default='All') + if epoch == 'Custom' and (min_date is None or max_date is None): + (min_date, max_date) = db.get_exercise_earliest_and_latest_dates(person_id, exercise_id) + exercise_progress = db.get_exercise_progress_for_user(person_id, exercise_id, min_date, max_date, epoch) if not exercise_progress: diff --git a/db.py b/db.py index a19f664..77f479a 100644 --- a/db.py +++ b/db.py @@ -494,7 +494,7 @@ class DataBase(): start_dates = [t['start_date'] for t in topsets] messages = [f'{t["repetitions"]} x {t["weight"]}kg ({t["estimated_1rm"]}kg E1RM) on {t["start_date"].strftime("%d %b %y")}' for t in topsets] - exercise_progress = get_exercise_graph_model(topsets[0]['exercise_name'], estimated_1rm, repetitions, weight, start_dates, messages, epoch, person_id, exercise_id) + exercise_progress = get_exercise_graph_model(topsets[0]['exercise_name'], estimated_1rm, repetitions, weight, start_dates, messages, epoch, person_id, exercise_id, min_date, max_date) return exercise_progress @@ -546,4 +546,30 @@ class DataBase(): # Return a tuple containing the person's name and their workout notes return (person_name, workout_notes_list) + + def get_exercise_earliest_and_latest_dates(self, person_id, exercise_id): + sql_query = """ + SELECT + w.start_date + FROM workout w + INNER JOIN topset t on w.workout_id = t.workout_id + INNER JOIN exercise e on t.exercise_id = e.exercise_id + WHERE w.person_id = %s AND e.exercise_id = %s + ORDER BY w.start_date DESC; + """ + + # Execute the SQL query + workout_exercise_dates = self.execute(sql_query, [person_id, exercise_id]) + + if not workout_exercise_dates: + return None, None + + latest_date = workout_exercise_dates[0]['start_date'] + earliest_date = workout_exercise_dates[-1]['start_date'] + + return earliest_date, latest_date + + + + diff --git a/templates/partials/sparkline.html b/templates/partials/sparkline.html index a89401c..e831c3f 100644 --- a/templates/partials/sparkline.html +++ b/templates/partials/sparkline.html @@ -61,10 +61,65 @@ class="px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-e-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white cursor-pointer" hx-get='{{ url_for("get_exercise_progress_for_user", person_id=person_id, exercise_id=exercise_id, epoch=epoch) }}' hx-target="#svg-plot-{{ unique_id }}" hx-swap="outerHTML" hx-trigger="click" {% endif %}> - {{ epoch}} + {% if epoch == 'Custom' %} + + {% else %} + {{ epoch}} + {% endif %} {% endfor %} + {% if selected_epoch == 'Custom' %} +