<commit_before>class SnpsController < ApplicationController
  helper_method :sort_column, :sort_direction
  before_filter :find_snp, except: [:index, :json,:json_annotation]

  def index
    @snps = Snp.order(sort_column + " "+ sort_direction)
    @snps_paginate = @snps.paginate(page: params[:page], per_page: 10)
    @title = "Listing all SNPs"
  end

  def show
    @snp = Snp.includes(:snp_comments).
      where(name: params[:id].downcase).first || not_found

    # TODO: Let's remove this here and use Snp.update_papers from a cron job
    # instead. Shall we? - Helge
    Sidekiq::Client.enqueue(PlosSearch, @snp.id)
    Sidekiq::Client.enqueue(MendeleySearch, @snp.id)
    Sidekiq::Client.enqueue(Snpedia, @snp.id)

    if params[:format] == 'json'
      users = @snp.users
      json_results = users.map do |u|
        json_element(user_id: u.id, snp_name: @snp.name)
      end
      render json: json_results
      return
    end

    @title = @snp.name
    @comments = @snp.snp_comments.order('created_at ASC')
    @snp_comment = SnpComment.new

    if current_user
      # Refactor the following - fixes it for now. Problem with several genotypes. - Philipp
      @current_genotypes = current_user.genotypes
      if @current_genotypes != []
        @user_snp = @snp.user_snps.where(genotype_id: @current_genotypes.first.id).first
        @local_genotype = @user_snp.try(:local_genotype) || ''
      else
        @user_snp = ''
        @local_genotype = ''
      end
    end
  end

  def json
    # TODO: Refactor this. - Helge
    if params[:user_id].index(",")
      @user_ids = params[:user_id].split(",")
      @results = []
      @user_ids.each do |id|
        @new_param = {}
        @new_param[:user_id] = id
        @new_param[:snp_name] = params[:snp_name].downcase
        @results << json_element(@new_param)
      end
    elsif params[:user_id].index("-")
      @results = []
      @id_array = params[:user_id].split("-")
      @user_ids = (@id_array[0].to_i..@id_array[1].to_i).to_a
      @user_ids.each do |id|
        @new_param = {}
        @new_param[:user_id] = id
        @new_param[:snp_name] = params[:snp_name].downcase
        @results << json_element(@new_param)
      end
    else 
      @results = json_element(params)
    end

    respond_to do |format|<commit_msg>Broke a view, this fixes it<commit_after>class SnpsController < ApplicationController
  helper_method :sort_column, :sort_direction
  before_filter :find_snp, except: [:index, :json,:json_annotation]

  def index
    @snps = Snp.order(sort_column + " "+ sort_direction)
    @snps_paginate = @snps.paginate(page: params[:page], per_page: 10)
    @title = "Listing all SNPs"
  end

  def show
    @snp = Snp.includes(:snp_comments).
      where(name: params[:id].downcase).first || not_found

    # TODO: Let's remove this here and use Snp.update_papers from a cron job
    # instead. Shall we? - Helge
    Sidekiq::Client.enqueue(PlosSearch, @snp.id)
    Sidekiq::Client.enqueue(MendeleySearch, @snp.id)
    Sidekiq::Client.enqueue(Snpedia, @snp.id)

    if params[:format] == 'json'
      users = @snp.users
      json_results = users.map do |u|
        json_element(user_id: u.id, snp_name: @snp.name)
      end
      render json: json_results
      return
    end

    @title = @snp.name
    @comments = @snp.snp_comments.order('created_at ASC')
    @snp_comment = SnpComment.new

    if current_user
      # Refactor the following - fixes it for now. Problem with several genotypes. - Philipp
      @current_genotypes = current_user.genotypes
      if @current_genotypes != []
        @user_snp = @snp.user_snps.where(genotype_id: @current_genotypes.first.id).first
        @local_genotype = @user_snp.try(:local_genotype) || ''
      else
        @user_snp = nil
        @local_genotype = nil
      end
    end
  end

  def json
    # TODO: Refactor this. - Helge
    if params[:user_id].index(",")
      @user_ids = params[:user_id].split(",")
      @results = []
      @user_ids.each do |id|
        @new_param = {}
        @new_param[:user_id] = id
        @new_param[:snp_name] = params[:snp_name].downcase
        @results << json_element(@new_param)
      end
    elsif params[:user_id].index("-")
      @results = []
      @id_array = params[:user_id].split("-")
      @user_ids = (@id_array[0].to_i..@id_array[1].to_i).to_a
      @user_ids.each do |id|
        @new_param = {}
        @new_param[:user_id] = id
        @new_param[:snp_name] = params[:snp_name].downcase
        @results << json_element(@new_param)
      end
    else 
      @results = json_element(params)
    end

    respond_to do |format|
{'fraction_non_alphanumeric': 0.13040657439446368, 'fraction_numerical': 0.0017301038062283738, 'mean_word_length': 2.8349917081260365, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4312911', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1610, 'n_words': 320}