<commit_before>class EvidenceController < ApplicationController

  before_filter :authenticate_user!, except: [:index, :combined_index]

  respond_to :json

  def combined_index
    @evidence = interactor :"evidence/for_fact_id", params[:fact_id], relation

    render 'evidence/index', formats: [:json]
  end

  class EvidenceNotFoundException < StandardError
  end

  def create_new_evidence(displaystring, opinion)
    evidence = Fact.build_with_data(nil, displaystring.to_s, nil, current_graph_user)

    (evidence.data.save and evidence.save) or raise EvidenceNotFoundException
    if opinion
      evidence.add_opinion(opinion, current_graph_user)
      Activity::Subject.activity(current_graph_user, OpinionType.real_for(opinion),evidence)
    end

    evidence
  end

  def retrieve_evidence(evidence_id)
    Fact[evidence_id] or raise EvidenceNotFoundException
  end

  # TODO move to a fact_relation resource
  def create
    fact = Fact[params[:fact_id]]

    authorize! :add_evidence, fact

    if params[:displaystring] != nil
      evidence = create_new_evidence params[:displaystring], params[:from_fact].andand[:opinion]
    else
      evidence = retrieve_evidence params[:evidence_id]
    end

    @fact_relation = create_believed_factrelation(evidence, relation, fact)

    @fact_relation.calculate_opinion

    render 'fact_relations/show', formats: [:json]
  rescue EvidenceNotFoundException
    render json: [], status: :unprocessable_entity
  end

  def set_opinion
    type = params[:type].to_sym

    @fact_relation = FactRelation[params[:id]]

    authorize! :opinionate, @fact_relation

    @fact_relation.add_opinion(type, current_user.graph_user)
    Activity::Subject.activity(current_user.graph_user, OpinionType.real_for(type),@fact_relation)

    @fact_relation.calculate_opinion

    render 'fact_relations/show', formats: [:json]
  end

  def remove_opinions
    @fact_relation = Basefact[params[:id]]

    authorize! :opinionate, @fact_relation

    @fact_relation.remove_opinions(current_user.graph_user)
    Activity::Subject.activity(current_user.graph_user,:removed_opinions,@fact_relation)

    @fact_relation.calculate_opinion

    render 'fact_relations/show', formats: [:json]
  end

  # TODO move to a fact_relation resource
  def destroy
    fact_relation = FactRelation[params[:id]]

    authorize! :destroy, fact_relation
<commit_msg>Removed unnecessary opinion calculations<commit_after>class EvidenceController < ApplicationController

  before_filter :authenticate_user!, except: [:index, :combined_index]

  respond_to :json

  def combined_index
    @evidence = interactor :"evidence/for_fact_id", params[:fact_id], relation

    render 'evidence/index', formats: [:json]
  end

  class EvidenceNotFoundException < StandardError
  end

  def create_new_evidence(displaystring, opinion)
    evidence = Fact.build_with_data(nil, displaystring.to_s, nil, current_graph_user)

    (evidence.data.save and evidence.save) or raise EvidenceNotFoundException
    if opinion
      evidence.add_opinion(opinion, current_graph_user)
      Activity::Subject.activity(current_graph_user, OpinionType.real_for(opinion),evidence)
    end

    evidence
  end

  def retrieve_evidence(evidence_id)
    Fact[evidence_id] or raise EvidenceNotFoundException
  end

  # TODO move to a fact_relation resource
  def create
    fact = Fact[params[:fact_id]]

    authorize! :add_evidence, fact

    if params[:displaystring] != nil
      evidence = create_new_evidence params[:displaystring], params[:from_fact].andand[:opinion]
    else
      evidence = retrieve_evidence params[:evidence_id]
    end

    @fact_relation = create_believed_factrelation(evidence, relation, fact)

    render 'fact_relations/show', formats: [:json]
  rescue EvidenceNotFoundException
    render json: [], status: :unprocessable_entity
  end

  def set_opinion
    type = params[:type].to_sym

    @fact_relation = FactRelation[params[:id]]

    authorize! :opinionate, @fact_relation

    @fact_relation.add_opinion(type, current_user.graph_user)
    Activity::Subject.activity(current_user.graph_user, OpinionType.real_for(type),@fact_relation)

    render 'fact_relations/show', formats: [:json]
  end

  def remove_opinions
    @fact_relation = Basefact[params[:id]]

    authorize! :opinionate, @fact_relation

    @fact_relation.remove_opinions(current_user.graph_user)
    Activity::Subject.activity(current_user.graph_user,:removed_opinions,@fact_relation)

    render 'fact_relations/show', formats: [:json]
  end

  # TODO move to a fact_relation resource
  def destroy
    fact_relation = FactRelation[params[:id]]

    authorize! :destroy, fact_relation

{'fraction_non_alphanumeric': 0.08898395721925134, 'fraction_numerical': 0.0, 'mean_word_length': 4.867001254705144, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1358445', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1347, 'n_words': 288}