survey/app/views/surveys/answer_success.html.erb

51 lines
1.7 KiB
Plaintext

<%
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) %>
<h3>Your total score is <%= @answer_model.scored_points %> </h3>
<% end %>
<% if types.include?(1) %>
<h3>Your average score is <%= @answer_model.get_avg_points %> </h3>
<% end %>
<% tmp_msgs.each do |msg| %>
<div><%=msg.html_safe%></div>
<% end %>
<% else %>
<h3><%= t('survey.answer_success')%></h3>
<% end %>
<a href="<%= data['url'] %>" class="btn btn-primary" title="<%=t("survey.go_back")%>"><%=t("survey.go_back")%></a>