Class: Intel::SearchesController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Intel::SearchesController
- Defined in:
- app/controllers/intel/searches_controller.rb
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
13 14 15 16 17 |
# File 'app/controllers/intel/searches_controller.rb', line 13 def index if params[:sort] == "conversion_rate" @searches.sort_by!{|s| [s["conversion_rate"].to_f, s["query"]] } end end |
#overview ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/intel/searches_controller.rb', line 19 def overview relation = Intel::Search.where(search_type: params[:search_type]) @searches_by_week = relation.group_by_week(:created_at, Time.zone, @time_range).count @conversions_by_week = relation.where("converted_at is not null").group_by_week(:created_at, Time.zone, @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 |
#recent ⇒ Object
34 35 36 37 |
# File 'app/controllers/intel/searches_controller.rb', line 34 def recent @searches = Intel::Search.order("created_at desc").limit(10) render layout: false end |
#stream ⇒ Object
31 32 |
# File 'app/controllers/intel/searches_controller.rb', line 31 def stream end |