Start to refactor away from using camel case (Not sure why I did this in the first place)
This commit is contained in:
8
app.py
8
app.py
@@ -39,7 +39,7 @@ def response_minify(response):
|
||||
def dashboard():
|
||||
all_topsets = db.get_all_topsets()
|
||||
|
||||
exercises = db.get_exercises()
|
||||
exercises = db.get_all_exercises()
|
||||
people = db.get_people()
|
||||
tags = db.get_tags_for_dashboard()
|
||||
|
||||
@@ -51,7 +51,7 @@ def dashboard():
|
||||
selected_exercise_ids = [int(i)
|
||||
for i in request.args.getlist('exercise_id')]
|
||||
if not selected_exercise_ids and htmx.trigger_name != 'exercise_id':
|
||||
selected_exercise_ids = [e['ExerciseId'] for e in exercises]
|
||||
selected_exercise_ids = [e['exercise_id'] for e in exercises]
|
||||
|
||||
min_date = convert_str_to_date(request.args.get(
|
||||
'min_date'), '%Y-%m-%d') or min([t['StartDate'] for t in all_topsets])
|
||||
@@ -195,7 +195,7 @@ def get_topset(person_id, workout_id, topset_id):
|
||||
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/topset/<int:topset_id>/edit_form", methods=['GET'])
|
||||
@ validate_topset
|
||||
def get_topset_edit_form(person_id, workout_id, topset_id):
|
||||
exercises = db.get_exercises()
|
||||
exercises = db.get_all_exercises()
|
||||
topset = db.get_topset(person_id, workout_id, topset_id)
|
||||
return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercises=exercises, exercise_name=topset['ExerciseName'], repetitions=topset['Repetitions'], weight=topset['Weight'], exercise_id=topset['ExerciseId'], is_edit=True)
|
||||
|
||||
@@ -301,7 +301,7 @@ def delete_exercise(exercise_id):
|
||||
@ app.route("/settings")
|
||||
def settings():
|
||||
people = db.get_people()
|
||||
exercises = db.get_exercises()
|
||||
exercises = db.get_all_exercises()
|
||||
if htmx:
|
||||
return render_block(app.jinja_env, "settings.html", "content", people=people, exercises=exercises), 200, {"HX-Trigger": "updatedPeople"}
|
||||
return render_template('settings.html', people=people, exercises=exercises)
|
||||
|
||||
10
db.py
10
db.py
@@ -52,11 +52,6 @@ class DataBase():
|
||||
|
||||
return (rv[0] if rv else None) if one else rv
|
||||
|
||||
def get_exercises(self):
|
||||
exercises = self.execute(
|
||||
'SELECT exercise_id AS "ExerciseId", name AS "Name" FROM exercise')
|
||||
return [{"ExerciseId": e['ExerciseId'], "Name": e['Name']} for e in exercises]
|
||||
|
||||
def get_exercise(self, exercise_id):
|
||||
exercise = self.execute(
|
||||
'SELECT exercise_id AS "ExerciseId", name AS "Name" FROM exercise WHERE exercise_id=%s LIMIT 1', [exercise_id], one=True)
|
||||
@@ -503,10 +498,11 @@ class DataBase():
|
||||
|
||||
# Calculate viewBox dimensions
|
||||
date_range = max_date - min_date
|
||||
total_span = date_range.days or 1
|
||||
e1rm_range = (max_e1rm - min_e1rm) or 1
|
||||
reps_range = (max_reps - min_reps) or 1
|
||||
weight_range = (max_weight - min_weight) or 1
|
||||
vb_width, vb_height = date_range.days, e1rm_range
|
||||
vb_width, vb_height = total_span, e1rm_range
|
||||
vb_width *= 200 / vb_width # Scale to 200px width
|
||||
vb_height *= 75 / vb_height # Scale to 75px height
|
||||
|
||||
@@ -514,7 +510,7 @@ class DataBase():
|
||||
estimated_1rm_scaled = [((value - min_e1rm) / e1rm_range) * vb_height for value in estimated_1rm]
|
||||
repetitions_scaled = [((value - min_reps) / reps_range) * vb_height for value in repetitions]
|
||||
weight_scaled = [((value - min_weight) / weight_range) * vb_height for value in weight]
|
||||
total_span = date_range.days or 1
|
||||
|
||||
relative_positions = [(date - min_date).days / total_span for date in start_dates]
|
||||
|
||||
# Convert relative positions and scaled estimated 1RM values to numpy arrays
|
||||
|
||||
@@ -46,10 +46,8 @@
|
||||
})
|
||||
end">
|
||||
{% for e in exercises %}
|
||||
<option value="{{ e['ExerciseId'] }}" {% if e['ExerciseId'] in selected_exercise_ids
|
||||
%}selected{% endif %}>{{
|
||||
e['Name']
|
||||
}}</option>
|
||||
<option value="{{ e.exercise_id }}" {% if e.exercise_id in selected_exercise_ids
|
||||
%}selected{% endif %}>{{ e.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
})
|
||||
end">
|
||||
{% for exercise in exercises|default([], true) %}
|
||||
<option value="{{ exercise['ExerciseId'] }}" {% if exercise['ExerciseId']==exercise_id %}selected{%
|
||||
endif %}>{{
|
||||
exercise['Name']
|
||||
}}</option>
|
||||
<option value="{{ exercise.exercise_id }}" {% if exercise.exercise_id==exercise_id %}selected{% endif
|
||||
%}>{{ exercise.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -28,12 +28,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="flex">
|
||||
{% set exercise_list = person['FilteredExercises'] %}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap mb-1">
|
||||
<div class="w-full md:w-1/3 px-2 md:px-3 mb-6 md:mb-0">
|
||||
<div class="mb-1 w-full">
|
||||
@@ -121,7 +115,7 @@
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Date
|
||||
</th>
|
||||
{% for e in exercise_list %}
|
||||
{% for e in person['FilteredExercises'] %}
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
{{ e['ExerciseName'] }}
|
||||
@@ -138,7 +132,7 @@
|
||||
{{ w['StartDate'] | strftime("%b %d %Y") }}
|
||||
</td>
|
||||
|
||||
{% for e in exercise_list %}
|
||||
{% for e in person['FilteredExercises'] %}
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
{% set topset_exercise = w['TopSets'] |
|
||||
get_first_element_from_list_with_matching_attribute('ExerciseId',
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
</svg>
|
||||
</div>
|
||||
<input type="search" id="people-search"
|
||||
class="block w-full p-4 pl-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
|
||||
class="block w-full p-4 pl-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500"
|
||||
placeholder="Search users..." _="on input
|
||||
show <tbody>tr/> in closest <table/>
|
||||
when its textContent.toLowerCase() contains my value.toLowerCase()
|
||||
@@ -125,7 +125,7 @@
|
||||
</svg>
|
||||
</div>
|
||||
<input type="search" id="exercise-search"
|
||||
class="block w-full p-4 pl-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
|
||||
class="block w-full p-4 pl-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500"
|
||||
placeholder="Search exercises..." _="on input
|
||||
show <tbody>tr/> in closest <table/>
|
||||
when its textContent.toLowerCase() contains my value.toLowerCase()
|
||||
@@ -137,9 +137,9 @@
|
||||
</thead>
|
||||
<tbody class="bg-white" id="new-exercise" hx-target="closest tr"
|
||||
hx-swap="outerHTML swap:0.5s">
|
||||
{% for e in exercises %}
|
||||
{{ render_partial('partials/exercise.html', exercise_id=e['ExerciseId'],
|
||||
name=e['Name'])}}
|
||||
{% for exercise in exercises %}
|
||||
{{ render_partial('partials/exercise.html', exercise_id=exercise.exercise_id,
|
||||
name=exercise.name)}}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
4
utils.py
4
utils.py
@@ -201,10 +201,6 @@ def get_date_info(input_date, selected_view):
|
||||
last_day_of_year = input_date.replace(
|
||||
year=input_date.year+1, month=1, day=1) - timedelta(days=1)
|
||||
|
||||
# Next/previous week
|
||||
next_week = input_date + timedelta(weeks=1)
|
||||
prev_week = input_date - timedelta(weeks=1)
|
||||
|
||||
# Next/previous month
|
||||
year, month = divmod(input_date.year * 12 + input_date.month, 12)
|
||||
next_month = date(year, month + 1, 1)
|
||||
|
||||
Reference in New Issue
Block a user