Skip to content

Commit

Permalink
Merge pull request #410 from freezingsaddles/daily-ride-totals
Browse files Browse the repository at this point in the history
Add daily ride total to person page
  • Loading branch information
obscurerichard authored Jan 18, 2025
2 parents c869ffc + 6f2f2be commit 09503ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 10 additions & 4 deletions freezing/web/templates/people/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ <h5 class="ps-2">
Total Rides: <span class="float-end">{{ data.totalrides }}</span>
</li>
<li class="list-group-item">
Total Mileage: <span class="float-end">{{ data.totaldist | round(1) }}</span>
Total Mileage: <span class="float-end">{{ data.totaldist | round(2) }}</span>
</li>
<li class="list-group-item">
Average Ride: <span class="float-end">
{% if data.totalrides > 0 %}
{{ (data.totaldist / data.totalrides) | round(1) }}
{{ (data.totaldist / data.totalrides) | round(2) }}
{% else %}
N/A
{% endif %}
Expand All @@ -142,16 +142,22 @@ <h5 class="ps-2">
Rides This Week: <span class="float-end">{{ data.weekrides }}</span>
</li>
<li class="list-group-item">
Mileage This Week: <span class="float-end">{{ data.weektotal | round(1) }}</span>
Mileage This Week: <span class="float-end">{{ data.weektotal | round(2) }}</span>
</li>
<li class="list-group-item">
Average Ride This Week: <span class="float-end">
{% if data.weekrides > 0 %}
{{ (data.weektotal / data.weekrides) | round(1) }}
{{ (data.weektotal / data.weekrides) | round(2) }}
{% else %}
N/A
{% endif %}
</span>
<li class="list-group-item">
Rides Today: <span class="float-end">{{ data.todayrides }}</span>
</li>
<li class="list-group-item">
Mileage Today: <span class="float-end">{{ data.todaydist | round(2) }}</span>
</li>
</li>
</ul>
</div>
Expand Down
7 changes: 7 additions & 0 deletions freezing/web/views/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def people_show_person(user_id):
today = get_today()
week_start = today.date() - timedelta(days=(today.weekday()) % 7)
week_end = week_start + timedelta(days=6)
today_dist = 0
today_rides = 0
weekly_dist = 0
weekly_rides = 0
total_rides = 0
Expand All @@ -91,6 +93,9 @@ def people_show_person(user_id):
if week_start <= ride_date <= week_end:
weekly_dist += r.distance
weekly_rides += 1
if ride_date == today.date():
today_dist += r.distance
today_rides += 1

tribal_groups = load_tribes()
my_tribes = query_tribes(user_id)
Expand All @@ -102,6 +107,8 @@ def people_show_person(user_id):
"environment": config.ENVIRONMENT,
"my_tribes": my_tribes,
"team": our_team,
"todaydist": today_dist,
"todayrides": today_rides,
"totaldist": total_dist,
"totalrides": total_rides,
"tribal_groups": tribal_groups,
Expand Down

0 comments on commit 09503ea

Please sign in to comment.