forked from hackclub/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send recap emails to Athul with overview of Indian check-in
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# frozen_string_literal: true | ||
|
||
class AthulClubMailer < ApplicationMailer | ||
def check_in_recap | ||
india_clubs = Club.india | ||
|
||
@weeks = [] | ||
@clubs = [] | ||
@stats = {} | ||
|
||
4.times.each do |i| | ||
week_num = i + 1 # start counting at 1, not 0 | ||
|
||
week_start = week_num.weeks.ago.beginning_of_week | ||
week_end = week_start.end_of_week | ||
|
||
week_name = week_start.strftime('%m/%d') + ' - ' + \ | ||
week_end.strftime('%m/%d') | ||
|
||
@weeks.push( | ||
name: week_name, | ||
start: week_start, | ||
end: week_end | ||
) | ||
end | ||
|
||
india_clubs.each do |club| | ||
club_obj = { | ||
name: club.name, | ||
check_ins: [] | ||
} | ||
|
||
@weeks.each do |week| | ||
check_in = club.check_ins.find_by( | ||
'? <= meeting_date AND meeting_date >= ?', | ||
week[:start], week[:end] | ||
) | ||
|
||
if check_in.present? | ||
club_obj[:check_ins].push(check_in.attendance) | ||
else | ||
club_obj[:check_ins].push('N/A') | ||
end | ||
end | ||
|
||
@clubs.push(club_obj) | ||
end | ||
|
||
most_recent_check_ins = india_clubs.map do |c| | ||
current_week = @weeks.first | ||
|
||
c.check_ins.find_by( | ||
'? <= meeting_date AND meeting_date >= ?', | ||
current_week[:start], current_week[:end] | ||
) | ||
end.compact | ||
|
||
@stats[:club_count] = india_clubs.count | ||
@stats[:checked_in_count] = most_recent_check_ins.count | ||
@stats[:attendance] = most_recent_check_ins.map(&:attendance).sum | ||
|
||
mail to: '[email protected]', | ||
cc: ['[email protected]', '[email protected]'], | ||
subject: 'Indian Clubs Check-In Recap' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<p>Hello!</p> | ||
|
||
<p>Hope you had a great week. Here is a report of check-ins from Indian clubs over the past 4 weeks:</p> | ||
|
||
<table> | ||
<tr> | ||
<th></th> | ||
<% @weeks.each do |week| %> | ||
<th><%= week[:name] %></th> | ||
<% end %> | ||
</tr> | ||
<% @clubs.each do |club| %> | ||
<tr> | ||
<th><%= club[:name] %></th> | ||
<% club[:check_ins].each do |check_in| %> | ||
<td><%= check_in %></td> | ||
<% end %> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<p> | ||
Total Indian clubs: <b><%= @stats[:club_count] %></b><br /> | ||
Total Indian clubs that checked in: <b><%= @stats[:checked_in_count] %></b><br /> | ||
Total attendance last week: <b><%= @stats[:attendance] %></b><br /> | ||
</p> | ||
|
||
<p>- Monolith</p> |