21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/controllers/searchjoy/searches_controller.rb', line 21
def overview
duration = @time_range.last - @time_range.first
period =
if duration < 3.days "hour"
elsif duration < 60.days
"day"
elsif duration < 60.weeks "week"
else
"month"
end
relation = Searchjoy::Search.where(search_type: params[:search_type])
@searches_by_week = relation.group_by_period(period, :created_at, time_zone: @time_zone, range: @time_range).count
@conversions_by_week = relation.where("converted_at is not null").group_by_period(period, :created_at, time_zone: @time_zone, range: @time_range).count
@top_searches = @searches.first(5)
@bad_conversion_rate = @searches.sort_by { |s| [s["conversion_rate"].to_f, s["query"]] }.first(5).select { |s| s["conversion_rate"] < 50 }
@conversion_rate_by_week = {}
@searches_by_week.each do |week, searches_count|
@conversion_rate_by_week[week] = searches_count > 0 ? (100.0 * @conversions_by_week[week] / searches_count).round : 0
end
end
|