Class: Searchjoy::SearchesController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Searchjoy::SearchesController
- Defined in:
- app/controllers/searchjoy/searches_controller.rb
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
15 16 17 18 19 |
# File 'app/controllers/searchjoy/searches_controller.rb', line 15 def index if params[:sort] == "conversion_rate" @searches.sort_by! { |s| [s["conversion_rate"].to_f, s["query"]] } end end |
#overview ⇒ Object
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 # determine period duration = @time_range.last - @time_range.first period = if duration < 3.days # shows 48-72 data points (ends at current time) :hour elsif duration < 60.days :day elsif duration < 60.weeks # to make it easy to compare to same time last year :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 @converted_by_week = relation.where.not(converted_at: nil).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 * @converted_by_week[week] / searches_count).round : 0 end end |
#recent ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/searchjoy/searches_controller.rb', line 49 def recent @searches = Searchjoy::Search.order(created_at: :desc).limit(50) if Searchjoy.multiple_conversions @searches.includes!(conversions: :convertable) else @searches.includes!(:convertable) end render layout: false end |
#stream ⇒ Object
46 47 |
# File 'app/controllers/searchjoy/searches_controller.rb', line 46 def stream end |