Class: Intel::SearchesController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Intel::SearchesController
- Defined in:
- app/controllers/intel/searches_controller.rb
Constant Summary collapse
- COLORS =
suspiciously similar to bootstrap 3
%w[5bc0de d9534f 5cb85c f0ad4e]
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
37 38 39 40 41 42 43 44 |
# File 'app/controllers/intel/searches_controller.rb', line 37 def recent @searches = Intel::Search.order("created_at desc").limit(10) @color = {} @search_types.each_with_index do |search_type, i| @color[search_type] = COLORS[i % COLORS.size] end render layout: false end |
#stream ⇒ Object
31 32 |
# File 'app/controllers/intel/searches_controller.rb', line 31 def stream end |