<commit_before>class VotesController < ApplicationController
  before_filter :find_voteable
  before_filter :check_permissions, :except => [:index]


  def index
    redirect_to(root_path)
  end

  # TODO: refactor
  def create
    value = 0
    if params[:vote_up] || params['vote_up.x'] || params['vote_up.y']
      value = 1
    elsif params[:vote_down] || params['vote_down.x'] || params['vote_down.y']
      vote_type = "vote_down"
      value = -1
    end

    state = :error
    if validate_vote(value, current_user)
      state = @voteable.vote(value, current_user)
      flash[:notice] = generate_notice(state)
    end

    if state == :created
      if @voteable.class == Question
        sweep_question(@voteable)
        Jobs::Votes.async.on_vote_question(@voteable.id, value, current_user.id, current_group.id).commit!
      elsif @voteable.class == Answer
        Jobs::Votes.async.on_vote_answer(@voteable.id, value, current_user.id, current_group.id).commit!
      end
    elsif state == :destroyed
      value = value * -1
    end

    respond_to do |format|
      format.html{redirect_to params[:source]||root_path}

      format.js do
        if state != :error
          average = @voteable.votes_average + value
          render(:json => {:success => true,
                           :message => flash[:notice],
                           :vote_type => vote_type,
                           :vote_state => state,
                           :average => I18n.t("votes.create.average", :count => average)}.to_json)
        else
          render(:json => {:success => false, :message => flash[:error] }.to_json)
        end
      end

      format.json do
        if vote_state != :error
          average = @voteable.votes_average + value
          render(:json => {:success => true,
                           :message => flash[:notice],
                           :vote_type => vote_type,<commit_msg>only show number of votes<commit_after>class VotesController < ApplicationController
  before_filter :find_voteable
  before_filter :check_permissions, :except => [:index]


  def index
    redirect_to(root_path)
  end

  # TODO: refactor
  def create
    value = 0
    if params[:vote_up] || params['vote_up.x'] || params['vote_up.y']
      value = 1
    elsif params[:vote_down] || params['vote_down.x'] || params['vote_down.y']
      vote_type = "vote_down"
      value = -1
    end

    state = :error
    if validate_vote(value, current_user)
      state = @voteable.vote(value, current_user)
      flash[:notice] = generate_notice(state)
    end

    if state == :created
      if @voteable.class == Question
        sweep_question(@voteable)
        Jobs::Votes.async.on_vote_question(@voteable.id, value, current_user.id, current_group.id).commit!
      elsif @voteable.class == Answer
        Jobs::Votes.async.on_vote_answer(@voteable.id, value, current_user.id, current_group.id).commit!
      end
    elsif state == :destroyed
      value = value * -1
    end

    respond_to do |format|
      format.html{redirect_to params[:source]||root_path}

      format.js do
        if state != :error
          average = @voteable.votes_average + value
          render(:json => {:success => true,
                           :message => flash[:notice],
                           :vote_type => vote_type,
                           :vote_state => state,
                           :average => average}.to_json)
        else
          render(:json => {:success => false, :message => flash[:error] }.to_json)
        end
      end

      format.json do
        if vote_state != :error
          average = @voteable.votes_average + value
          render(:json => {:success => true,
                           :message => flash[:notice],
                           :vote_type => vote_type,
{'fraction_non_alphanumeric': 0.1178477690288714, 'fraction_numerical': 0.0026246719160104987, 'mean_word_length': 2.152191894127378, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '4133417', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1113, 'n_words': 243}