app/models/plan.rb
def percent_answered
    num_questions = question_ids.length
    return 0 unless num_questions.positive?

    pre_fetched_answers = Answer.includes(:question_options,
                                          question: :question_format)
                                .where(id: answer_ids)
    num_answers = pre_fetched_answers.reduce(0) do |m, a|
      m += 1 if a.answered?
      m
    end
    return 0 unless num_answers.positive?

    (num_answers / num_questions.to_f) * 100
  end
# Determines what percentage of the Plan's questions have been num_answered_questions
#
Determines what percentage of the Plan's questions have been num_answered_questions
Determines what percentage of the Plan ' s questions have been num_answered_questions
def percent_answered
    num_questions = question_ids.length
    return 0 unless num_questions.positive?
    pre_fetched_answers = Answer.includes(:question_options,
                                          question: :question_format)
                                .where(id: answer_ids)
    num_answers = pre_fetched_answers.reduce(0) do |m, a|
      m += 1 if a.answered?
      m
    end
    return 0 unless num_answers.positive?
    (num_answers / num_questions.to_f) * 100
  end
def percent_answered num_questions = question_ids . length return 0 unless num_questions . positive? pre_fetched_answers = Answer . includes ( :question_options , question : :question_format ) . where ( id : answer_ids ) num_answers = pre_fetched_answers . reduce ( 0 ) do | m , a | m += 1 if a . answered? m end return 0 unless num_answers . positive? ( num_answers / num_questions . to_f ) * 100 end
Determines what percentage of the Plan's questions have been num_answered_questions
Determines what percentage of the Plan ' s questions have been num_answered_questions