<commit_before>class VariantsDatatable
  delegate :params, to: :@view_context

  def initialize(view_context)
    @view_context = view_context
  end

  def as_json(options = {})
    {
      sEcho: params[:sEcho].to_i,
      iTotalRecords: Variant.count,
      iTotalDisplayRecords: variants.total_entries,
      aaData: data
    }
  end

  private
  def data
    variants.map do |variant|
      [
        variant.location.chromosome,
        variant.location.start,
        variant.location.stop,
        variant.location.reference_read,
        variant.variant,
        variant.gene.name,
        variant.amino_acid.name,
        variant.mutation_type.name,
        variant.diseases.map(&:name).join(','),
        variant.sources.map(&:pmid_id).join(',')
      ]
    end
  end

  def variants
    @variants ||= get_variants
  end

  def get_variants
    variants = Variant.index_view_scope
      .order("#{sort_column}  #{sort_direction}")
      .page(page)
      .per_page(per_page)

      variants = Filter.filter_query(variants, params)

      if params[:sSearch].present?
        search_conditions = @@searchable_columns.map { |col| "#{col} LIKE :search" }.join(' OR ')
        variants = variants.where(search_conditions, search: "%#{params[:sSearch]}%")
      end
      variants
  end

  #still need sources and druggability
  def sort_column
    @@columns[params[:iSortCol_0].to_i]
  end

  def sort_direction
    params[:sSortDir_0] == 'desc' ? 'desc' : 'asc'
  end

  def page
    params[:iDisplayStart].to_i/per_page + 1
  end

  def per_page
    display_length = params[:iDisplayLength].to_i
    display_length > 0 ? display_length : 50
  end

  @@columns = %w[
    locations.chromosome
    locations.start
    locations.stop
    locations.reference_read<commit_msg>make searching case insensitive<commit_after>class VariantsDatatable
  delegate :params, to: :@view_context

  def initialize(view_context)
    @view_context = view_context
  end

  def as_json(options = {})
    {
      sEcho: params[:sEcho].to_i,
      iTotalRecords: Variant.count,
      iTotalDisplayRecords: variants.total_entries,
      aaData: data
    }
  end

  private
  def data
    variants.map do |variant|
      [
        variant.location.chromosome,
        variant.location.start,
        variant.location.stop,
        variant.location.reference_read,
        variant.variant,
        variant.gene.name,
        variant.amino_acid.name,
        variant.mutation_type.name,
        variant.diseases.map(&:name).join(','),
        variant.sources.map(&:pmid_id).join(',')
      ]
    end
  end

  def variants
    @variants ||= get_variants
  end

  def get_variants
    variants = Variant.index_view_scope
      .order("#{sort_column}  #{sort_direction}")
      .page(page)
      .per_page(per_page)

      variants = Filter.filter_query(variants, params)

      if params[:sSearch].present?
        search_conditions = @@searchable_columns.map { |col| "lower(#{col}) LIKE :search" }.join(' OR ')
        variants = variants.where(search_conditions, search: "#{params[:sSearch]}%".downcase)
      end
      variants
  end

  #still need sources and druggability
  def sort_column
    @@columns[params[:iSortCol_0].to_i]
  end

  def sort_direction
    params[:sSortDir_0] == 'desc' ? 'desc' : 'asc'
  end

  def page
    params[:iDisplayStart].to_i/per_page + 1
  end

  def per_page
    display_length = params[:iDisplayLength].to_i
    display_length > 0 ? display_length : 50
  end

  @@columns = %w[
    locations.chromosome
    locations.start
    locations.stop
    locations.reference_read
{'fraction_non_alphanumeric': 0.11089439955419336, 'fraction_numerical': 0.0033435497353023124, 'mean_word_length': 2.8150903294367695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '111578', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1153, 'n_words': 220}