<commit_before>module Intel
  class SearchesController < ActionController::Base
    layout "intel/application"

    http_basic_authenticate_with name: ENV["INTEL_USERNAME"], password: ENV["<PASSWORD>_PASSWORD"] if ENV["INTEL_PASSWORD"]

    before_filter :set_time_zone
    before_filter :set_search_types
    before_filter :set_search_type, only: [:index, :overview]
    before_filter :set_time_range, only: [:index, :overview]
    before_filter :set_searches, only: [:index, :overview]

    def index
      if params[:sort] == "conversion_rate"
        @searches.sort_by!{|s| [s["conversion_rate"].to_f, s["query"]] }
      end
    end

    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

    def stream
    end

    def recent
      @searches = Intel::Search.order("created_at desc").limit(10)<commit_msg>Show 50 searches<commit_after>module Intel
  class SearchesController < ActionController::Base
    layout "intel/application"

    http_basic_authenticate_with name: ENV["INTEL_USERNAME"], password: ENV["INTEL_PASSWORD"] if ENV["INTEL_PASSWORD"]

    before_filter :set_time_zone
    before_filter :set_search_types
    before_filter :set_search_type, only: [:index, :overview]
    before_filter :set_time_range, only: [:index, :overview]
    before_filter :set_searches, only: [:index, :overview]

    def index
      if params[:sort] == "conversion_rate"
        @searches.sort_by!{|s| [s["conversion_rate"].to_f, s["query"]] }
      end
    end

    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

    def stream
    end

    def recent
      @searches = Intel::Search.order("created_at desc").limit(50)
{'fraction_non_alphanumeric': 0.12811867835468643, 'fraction_numerical': 0.008766014834794335, 'mean_word_length': 4.345945945945946, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2640470', 'n_tokens_mistral': 1062, 'n_tokens_neox': 995, 'n_words': 181}