VRFS-1665 mail formatting; bug fixing

This commit is contained in:
Jonathan Kolyer 2014-05-29 16:32:22 +00:00
parent f90f55fb11
commit ff15da9f4e
5 changed files with 85 additions and 46 deletions

View File

@ -391,7 +391,7 @@
end
end
def scheduled_session_daily(receiver, sessions)
def scheduled_session_daily(receiver, sessions_and_latency)
sendgrid_category "Notification"
sendgrid_unique_args :type => "scheduled_session_daily"
@ -399,10 +399,11 @@
sendgrid_substitute('@USERID', [receiver.id])
@user = receiver
@sessions_and_latency = sessions_and_latency
@title = 'New Scheduled Sessions Matched to You'
mail(:to => receiver.email,
:subject => EmailBatchScheduledSessions.subject,
:title => 'New Scheduled Sessions Matched to You') do |format|
:subject => EmailBatchScheduledSessions.subject) do |format|
format.text
format.html
end

View File

@ -1,10 +1,38 @@
<% provide(:title, 'Scheduled Session RSVP') %>
<% provide(:title, @title) %>
<p><%= @body %></p>
<p>
<%= @session_name %><br/>
<%= @session_date %>
<p>Hello <%= @user.first_name %> --
</p>
<p><a style="color: #588C98;" href="<%= @session_url %>">View Session Details</a></p>
<p>The following new sessions that that have been posted during the last 24 hours:
</p>
<ol>
<li>Need someone who plays an instrument that you play</li>
<li>Were posted by someone to whom you have either a good or medium latency connection</li>
</ol>
<p>Take a look through these new sessions below, and just click the RSVP button on the far right side of the row for any session in which you'd like to play. This will let the session organizer know you're interested, and you'll be notified if the session organizer accepts your request to play in that session!
</p>
<table style="margin-top:6px; width:98%; font-size:11px; color:#fff; background-color:#262626; border:solid 1px #4d4d4d;" cellspacing="0" cellpadding="0" border="0">
<!-- header -->
<tr>
<th align="left" width="20%">GENRE</th>
<th align="left" width="60%">DESCRIPTION</th>
<th width="20%" style="text-align:center">LATENCY</th>
</tr>
<!-- session row goes here -->
<% @sessions_and_latency.each do |sess| %>
<tr>
<td><%= sess.genre.description %></td>
<td><%= sess.description %></td>
<td style="text-align:center"><%= sess.latency_store %></td>
</tr>
<% end %>
</table>
<p>To see ALL the scheduled sessions that you might be interested in joining, view our Find Session page at: <a href="http://www.jamkazam.com/client#/findSession">http://www.jamkazam.com/client#/findSession</a>.
</p>
<p>Best Regards,</p>
Team JamKazam

View File

@ -1,23 +1,21 @@
<% provide(:title, @title) %>
<p>Hello <%= @user.first_name %> --
</p>
Hello <%= @user.first_name %> --
<p>The following new sessions that that have been posted during the last 24 hours:
</p>
<ol>
<li>Need someone who plays an instrument that you play</li>
<li>Were posted by someone to whom you have either a good or medium latency connection</li>
</ol>
The following new sessions that that have been posted during the last 24 hours:
<p>Take a look through these new sessions below, and just click the RSVP button on the far right side of the row for any session in which you'd like to play. This will let the session organizer know you're interested, and you'll be notified if the session organizer accepts your request to play in that session!
</p>
1. Need someone who plays an instrument that you play
2. Were posted by someone to whom you have either a good or medium latency connection
HERE WE PRESENT THE SESSIONS IN A TABLE JUST LIKE THE FIND SESSION PAGE
Take a look through these new sessions below, and just click the RSVP button on the far right side of the row for any session in which you'd like to play. This will let the session organizer know you're interested, and you'll be notified if the session organizer accepts your request to play in that session!
<p>To see ALL the scheduled sessions that you might be interested in joining, view our Find Session page at: <a href="http://www.jamkazam.com/client#/findSession">http://www.jamkazam.com/client#/findSession</a>.
</p>
GENRE | DESCRIPTION | LATENCY
<% @sessions_and_latency.each do |sess| %>
<%= sess.genre.description %> | <%= sess.description %> | <%= sess.latency_store %>
<% end %>
<p>Best Regards,</p>
To see ALL the scheduled sessions that you might be interested in joining, view our Find Session page at: http://www.jamkazam.com/client#/findSession.
Best Regards,
Team JamKazam

View File

@ -12,17 +12,18 @@ module JamRuby
"New sessions have been scheduled that may be a good match for you!"
end
def fetch_sessions
objs = []
MusicSession.open_sessions
.where(['created_at > ?', time_since_last_batch(SINCE_DAYS)])
.where(['scheduled_start >= ?', Time.now() + MIN_HOURS_START.hours])
.find_each do |ss|
block_given? ? yield(ss) : objs << ss
end
objs
end
# def fetch_sessions
# objs = []
# MusicSession.open_sessions
# .where(['created_at > ?', time_since_last_batch(SINCE_DAYS)])
# .where(['scheduled_start >= ?', Time.now() + MIN_HOURS_START.hours])
# .find_each do |ss|
# block_given? ? yield(ss) : objs << ss
# end
# objs
# end
# inserts eligible sessions to temp table
def prep_tmp_table
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS #{TMP_SNAP}")
sql =<<SQL
@ -48,8 +49,11 @@ SQL
def fetch_recipients
objs = []
# load eligible sessions into tmp table
self.prep_tmp_table
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS #{TMP_USER}")
# load eligible recipients into tmp table
sql =<<SQL
SELECT
users.id AS user_id,
@ -69,28 +73,34 @@ GROUP BY users.id, tmp.session_id, tmp.creator_id, tmp.creator_score_idx
SQL
ActiveRecord::Base.connection.execute(sql)
# select recipients whose score is below minimum threshold
sql =<<SQL
SELECT DISTINCT user_id, users.email AS email, users.first_name AS first_name
SELECT DISTINCT user_id, scores.score AS latency
FROM #{TMP_USER}
LEFT JOIN users ON users.id = user_id
INNER JOIN scores ON scores.alocidispid = #{TMP_USER}.creator_score_idx AND scores.blocidispid = #{TMP_USER}.user_score_idx
WHERE
users.id IS NOT NULL AND
scores.score < #{Score::MAX_YELLOW_LATENCY}
SQL
results = ActiveRecord::Base.connection.execute(sql)
# now just get the sessions/latency for each distinct mail recipient
results.each do |result|
sql =<<SQL
SELECT session_id, creator_id, user_id
SELECT session_id
FROM #{TMP_USER}
WHERE
user_id = '#{result['user_id']}'
SQL
sessions = ActiveRecord::Base.connection.execute(sql).collect { |rr| rr['session_id'] }
vals = result.clone
sched_sessions = MusicSession.where(["id IN ('#{sessions.join("','")}')"])
receiver = User.find_by_id(result['user_id'])
block_given? ? yield(receiver, sched_sessions) : objs << vals
user = User.find_by_id(result['user_id'])
sessions = ActiveRecord::Base.connection.execute(sql).collect do |rr|
msess = MusicSession.where(['id = ?',rr['session_id']])
.limit(1)
.includes([:genre, :creator])
.first
msess.latency_store = result['latency']
msess
end
block_given? ? yield(user, sessions) : objs << [user, sessions]
end
objs
end
@ -98,11 +108,11 @@ SQL
def deliver_batch_sets!
self.opt_in_count = 0
sent = 0
self.fetch_recipients do |receiver, sessions|
self.fetch_recipients do |receiver, sessions_and_latency|
self.opt_in_count += 1
sent += 1
bset = EmailBatchSet.scheduled_session_set(self, receiver, sessions)
UserMailer.scheduled_session_daily(receiver, sessions).deliver
bset = EmailBatchSet.scheduled_session_set(self, receiver, sessions_and_latency)
UserMailer.scheduled_session_daily(receiver, sessions_and_latency).deliver
end
self.sent_count = sent
self.save

View File

@ -10,6 +10,8 @@ module JamRuby
attr_accessor :legal_terms, :recurring_mode, :language_description, :scheduled_start_time, :access_description
attr_accessor :latency_store
self.table_name = "music_sessions"
self.primary_key = 'id'