-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #80
- Loading branch information
Showing
30 changed files
with
600 additions
and
38 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
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
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,11 @@ | ||
class AdminWeeklyReportJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform | ||
# Queue all eligible users and let the is_active (or other) logic determine if they should really receive it | ||
users = User.where(receive_weekly_report: true) | ||
users.each do |user| | ||
AdminMailer.weekly_report(user.id).deliver_later | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class AdminMailer < ApplicationMailer | ||
include Roadie::Rails::Automatic | ||
add_template_helper(HackathonManagerHelper) | ||
|
||
layout "admin_mailer" | ||
|
||
def weekly_report(user_id) | ||
# Don't send emails more than 7 days after event starts | ||
stop_date = Date.parse(HackathonConfig["event_start_date"]) + 7.days | ||
return if Date.today > stop_date | ||
|
||
@user = User.find_by_id(user_id) | ||
|
||
return unless @user.safe_receive_weekly_report | ||
|
||
@period_start = 7.days.ago.at_beginning_of_day | ||
@period_end = 1.day.ago.at_end_of_day | ||
@period = @period_start..@period_end | ||
|
||
@applications = report_metric(Questionnaire, :created_at) | ||
@rsvp_confirmed = report_metric(Questionnaire.where(acc_status: "rsvp_confirmed"), :acc_status_date) | ||
@rsvp_denied = report_metric(Questionnaire.where(acc_status: "rsvp_denied"), :acc_status_date) | ||
|
||
@bus_metrics = BusList.all.map do |bus_list| | ||
{ | ||
name: bus_list.name, | ||
total: bus_list.passengers.count, | ||
} | ||
end | ||
|
||
@messages_sent = Message.bulk.where(delivered_at: @period).count | ||
|
||
@new_admissions_metrics = [@applications, @rsvp_confirmed, @rsvp_denied].any? { |x| x[:new].positive? } | ||
@new_communication_metrics = @messages_sent.positive? | ||
|
||
# Don't send email if no new activity | ||
return if !@new_admissions_metrics && !@new_bus_list_metrics && !@new_communication_metrics | ||
|
||
mail( | ||
to: pretty_email(@user.full_name, @user.email), | ||
subject: "Your Weekly Report", | ||
) | ||
end | ||
|
||
private | ||
|
||
def report_metric(query_base, new_query_field) | ||
{ | ||
new: query_base.where(new_query_field => @period).count, | ||
total: query_base.count, | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: -> { HackathonConfig['email_from'] } | ||
layout 'mailer' | ||
default from: -> { HackathonConfig["email_from"] } | ||
layout "mailer" | ||
|
||
def pretty_email(name, email) | ||
return email if name.blank? | ||
|
||
"\"#{name}\" <#{email}>" | ||
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
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,50 @@ | ||
%h1 Your Weekly Report | ||
|
||
%p | ||
For the week of | ||
%strong | ||
= @period_start.strftime("%A, %B %-d") | ||
– | ||
= @period_end.strftime("%A, %B %-d") | ||
|
||
%h2 Admissions | ||
|
||
- if @new_admissions_metrics | ||
%p | ||
📥 | ||
%strong= @applications[:new] | ||
new applications (#{@applications[:total]} total) | ||
|
||
%p | ||
✅ | ||
%strong= @rsvp_confirmed[:new] | ||
new RSVP confirmations (#{@rsvp_confirmed[:total]} total) | ||
|
||
%p | ||
❌ | ||
%strong= @rsvp_denied[:new] | ||
new RSVP denials (#{@rsvp_denied[:total]} total) | ||
- else | ||
%p | ||
%em No change from last week | ||
|
||
%h2 Transportation | ||
|
||
- @bus_metrics.each do |bus_metric| | ||
%p | ||
%u= bus_metric[:name] | ||
%br | ||
🚌 | ||
%strong= bus_metric[:total] | ||
total passengers | ||
|
||
%h2 Communication | ||
|
||
- if @new_communication_metrics | ||
%p | ||
✉️ | ||
%strong= @messages_sent | ||
new bulk emails sent out | ||
- else | ||
%p | ||
%em No new bulk emails sent |
Oops, something went wrong.