Skip to content

Commit 3cc1eff

Browse files
committed
Include average particpants in location stats
1 parent 58faf9f commit 3cc1eff

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/models/concerns/home_statistics.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ def location_statistics_data
5454

5555
sorted_times = times.sort
5656
total_participants = location.events.joins(:results).count + location.events.joins(:volunteers).count
57+
events_count = location.events.finalised.count
5758

5859
{
5960
location: location,
6061
quickest_time: sorted_times.first,
6162
average_time: (times.sum.to_f / times.size).round,
6263
median_time: sorted_times[sorted_times.size / 2],
63-
total_participants: total_participants
64+
total_participants: total_participants,
65+
events_count: events_count,
66+
average_participants: events_count.positive? ? (total_participants.to_f / events_count).round : 0
6467
}
6568
end.compact
6669
end

app/views/shared/_statistics_widget.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
<dt class="text-gray-600">Total Participants:</dt>
4646
<dd class="font-medium text-gray-950"><%= loc_stat[:total_participants] %></dd>
4747
</div>
48+
<div class="flex justify-between">
49+
<dt class="text-gray-600">Average Participants:</dt>
50+
<dd class="font-medium text-gray-950"><%= loc_stat[:average_participants] %></dd>
51+
</div>
4852
<div class="flex justify-between">
4953
<dt class="text-gray-600">Fastest Time:</dt>
5054
<dd class="font-medium text-gray-950"><%= format_pace_time(loc_stat[:quickest_time]) %></dd>

0 commit comments

Comments
 (0)