class QuestionsController < ApplicationController include QuizHelperMethods def show not_found unless question @answer = Answer.new(player_id: current_player.id, node_id: question.id) end def answer @answer = Answer.find_by(node_id: question.id, player_id: current_player.id) @question_answer = question.attachments.with_text.each_slice(2).to_a[@answer.value] end def result not_found if result_node.blank? or current_player.answers.count < questions.size planet_score = 0 current_player.answers.ordered.each_with_index do |answer, i| case i when 0, 3 planet_score += 1 if answer.value == 0 else planet_score += 1 if answer.value == 1 end end people_score = questions.count - planet_score score_diff = people_score - planet_score attachment_index = case when score_diff >= 2 0 # People when score_diff <= -2 1 # Planet else 2 # Balanced end # logger.info(">>> score_diff #{score_diff}") # logger.info(">>> people_score #{people_score}") # logger.info(">>> planet_score #{planet_score}") # logger.info(">>> attachment_index #{attachment_index}") @result_attachment = result_node.attachments.offset(attachment_index).first @stats_attachment = result_node.attachments.offset(3).first end end