<% data = action_data @survey = data['survey'] @answer_model = data['answer'] answer_model_attrs = @answer_model.attributes weight_relations = @survey.survey_questions.map{|q| [q.id.to_s,(q.weight.nil? ? 1 : q.weight)]}.to_h %> <% if @survey.result_type == QuestionnaireSurvey::ResultCriteria %> <% tmp_msgs = [] types = [] %> <% @survey.result_criteria.each do |criteria| %> <% total_criteria_score = 0 total_weight = 0 ((criteria["questions"][0].to_i - 1)..(criteria["questions"][1].to_i - 1)).each do |x| total_criteria_score = (total_criteria_score + @answer_model.individual_total[x].to_i) rescue 0 k = weight_relations.keys[x] if k && answer_model_attrs.has_key?(k) total_weight += weight_relations[k] end end type = criteria["type"].to_i %> <% if type == 0 %> <% if (criteria["range"][0].to_i..criteria["range"][1].to_i).cover?(total_criteria_score) %> <% tmp_msgs << criteria["msg"] %> <% types << type %> <% end %> <% else %> <% avg = (total_criteria_score.to_f / total_weight).round %> <% if (criteria["range"][0].to_i..criteria["range"][1].to_i).cover?(avg) %> <% tmp_msgs << criteria["msg"] %> <% types << type %> <% end %> <% end %> <% end %> <% if types.include?(0) %>

Your total score is <%= @answer_model.scored_points %>

<% end %> <% if types.include?(1) %>

Your average score is <%= @answer_model.get_avg_points %>

<% end %> <% tmp_msgs.each do |msg| %>
<%=msg.html_safe%>
<% end %> <% else %>

<%= t('survey.answer_success')%>

<% end %> "><%=t("survey.go_back")%>