4bbd93ded1
Adding the .ruby-verison file triggered previously un-run cops, specifically: This cop is designed to help upgrade to Ruby 3.0. It will add the comment `# frozen_string_literal: true` to the top of files to enable frozen string literals. Frozen string literals will be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+. More info on rubocop [Automatic-Corrections](https://github.com/bbatsov/rubocop/wiki/Automatic-Corrections)
57 lines
1.5 KiB
Ruby
57 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
class QuizStatus
|
|
attr_reader :candidate
|
|
|
|
def initialize candidate
|
|
@candidate = Candidate.find(candidate.to_i)
|
|
end
|
|
|
|
def started
|
|
candidate.answers.count > 0
|
|
end
|
|
|
|
def on_summary
|
|
candidate.submitted_answers.count == candidate.questions.count
|
|
end
|
|
|
|
def completed
|
|
candidate.completed
|
|
end
|
|
|
|
def can_submit
|
|
on_summary &&
|
|
no_finish_later &&
|
|
candidate.answered_questions.count == candidate.questions.count
|
|
end
|
|
|
|
def progress
|
|
answs = candidate.answered_questions.count.to_f
|
|
total = candidate.quiz.questions.count.to_f
|
|
|
|
(answs / total * 100).round.to_i
|
|
end
|
|
|
|
def no_finish_later
|
|
sql = %(select count(a.id) todos
|
|
from answers a
|
|
inner join questions q on q.id = a.question_id
|
|
where q.input_type = 'live_code'
|
|
and a.answer like "%later: 'true'%"
|
|
and a.candidate_id = #{candidate.id})
|
|
result = ActiveRecord::Base.connection.exec_query(sql).to_hash.first
|
|
result['todos'].zero?
|
|
end
|
|
|
|
def current_question_id
|
|
sql = "select q.id question_id
|
|
from candidates c
|
|
inner join questions q on q.quiz_id = c.quiz_id
|
|
left join answers a on a.candidate_id = c.id AND a.question_id = q.id
|
|
where q.active = true and c.id = #{candidate.to_i}
|
|
and (a.id is null OR a.submitted is false)
|
|
order by q.sort limit 1;"
|
|
result = ActiveRecord::Base.connection.exec_query(sql).to_hash.first
|
|
result['question_id'] unless result.nil?
|
|
end
|
|
end
|