daily report for the trending maps

pull/5756/head
Mario de Frutos 9 years ago
parent 09fd243901
commit eeb3be2fe1

@ -0,0 +1,11 @@
class ReporterMailer < ActionMailer::Base
default from: "cartodb.com <support@cartodb.com>"
layout 'mail'
def trending_maps_report(mail_to, trending_visualizations)
@subject = "Daily report for trending maps"
@trending_visualizations = trending_visualizations
mail to: mail_to, subject: @subject
end
end

@ -0,0 +1,48 @@
<% content_for(:subject) { @subject } %>
<% content_for :body do %>
<tr>
<td>
<!-- HEADER -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color: #ffffff; border: 1px solid #dddddd; border-bottom: 0; border-collapse: separate !important; border-top-left-radius: 4px; border-top-right-radius: 4px; width: 100% !important;">
<tr>
<td align="left" style="padding: 40px 50px 40px 50px; font-weight: bold; font-size: 25px; font-family: Helvetica, Arial, sans-serif; color: #333333;">Trending Maps Report</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<!-- CONTENT -->
<table cellspacing="0" cellpadding="0" border="0" width="100%" style="background-color: #ffffff; border: 1px solid #dddddd; border-top: 1px solid #dddddd; border-bottom: 1px solid #cccccc; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; width: 100% !important;">
<tr>
<td valign="top" style="padding: 0;">
<table cellspacing="0" cellpadding="0" border="0" width="100%" style="background-color: #F2FAE8 border-bottom: 1px solid #dddddd; width: 100% !important;">
<% @trending_visualizations.each do |vis_id, map_data| %>
<tr>
<td align="left" style="padding: 10px 50px 10px 50px; font-family: Helvetica, Arial, sans-serif;">
<p style="margin: 0; font-size: 16px; line-height: 25px; color: #666666;">Trending map <a href="<%= "#{map_data['user_public_url']}#{CartoDB.path(self, 'public_visualizations_public_map', { id: vis_id })}" %>" ><%= map_data["visualization_name"] %></a> by <a href="mailto:<%= map_data["user_mail"] %>"><%= map_data["user"] %></a> with <strong><%= map_data["mapviews"] %> mapviews</strong></p>
</td>
</tr>
<% end %>
</table>
</td>
</tr>
</table>
</td>
</tr>
<% end %>
<% content_for :footer do %>
<tr>
<td style="padding: 20px 0px 20px 0px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center" valign="middle" style="font-size: 12px; line-height: 18px; font-family: Helvetica, Arial, sans-serif; color:#999;">
&copy; <%= Time.now.year %> CartoDB
</td>
</tr>
</table>
</td>
</tr>
<% end %>

@ -100,6 +100,8 @@ defaults: &defaults
generate_every: 86400
explore_api:
username: ''
reports:
mail_to: ''
varnish_management:
critical: false
host: '127.0.0.1'

@ -18,7 +18,8 @@ module CartoDB
yesterday_mapviews = stats_manager.get_api_calls_from_redis(username, {from: date, to: date, stat_tag: visualization_id})
total_mapviews = stats_manager.get_total_api_calls_from_redis(username, visualization_id)
if is_trending_map?(yesterday_mapviews[date_key], total_mapviews)
trending_maps[visualization_id] = { user: username, mapviews: total_mapviews }
visualization = Carto::Visualization.find(visualization_id)
trending_maps[visualization_id] = { user: username, user_mail: visualization.user.email, user_public_url: visualization.user.public_url, mapviews: total_mapviews, visualization_name: visualization.name }
end
end
trending_maps
@ -28,6 +29,19 @@ module CartoDB
::Resque.enqueue(::Resque::UserJobs::Mail::TrendingMap, visualization_id, mapviews, preview_image)
end
def send_trending_map_report(trending_visualizations)
reports_mail_to = Cartodb.get_config(:reports, 'mail_to')
if reports_mail_to.blank?
CartoDB.notify_error("Reporter mail_to property missing")
else
::Resque.enqueue(
::Resque::Reporter::Mail::TrendingMapsReport,
reports_mail_to,
trending_visualizations
)
end
end
def is_trending_map?(mapviews_number_before, total_mapviews_today)
return false if total_mapviews_today < GEOMETRIC_SEQUENCE_BASE
total_mapviews_yesterday = total_mapviews_today - mapviews_number_before

@ -0,0 +1,16 @@
# encoding: utf-8
require_relative './base_job'
module Resque
module Reporter
module Mail
module TrendingMapsReport
@queue = :users
def self.perform(mail_to, trending_visualizations)
ReporterMailer.trending_maps_report(mail_to, trending_visualizations).deliver
end
end
end
end
end

@ -17,6 +17,8 @@ namespace :cartodb do
preview_image = Carto::StaticMapsURLHelper.new.url_for_static_map_without_request(data[:user], 'http' , visualization, 600, 300)
trending_maps_lib.notify_trending_map(visualization_id, data[:mapviews], preview_image) unless simulation
end
trending_maps_lib.send_trending_map_report(trending_maps)
end
end

Loading…
Cancel
Save