2016-08-18 13:18:02 +00:00
|
|
|
<%
|
|
|
|
data = action_data
|
|
|
|
@survey = data['survey']
|
|
|
|
@answer_model = data['answer']
|
2021-10-13 09:15:47 +00:00
|
|
|
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
|
2016-08-18 13:18:02 +00:00
|
|
|
%>
|
|
|
|
|
2021-10-13 09:15:47 +00:00
|
|
|
<% if @survey.result_type == QuestionnaireSurvey::ResultCriteria %>
|
|
|
|
<% tmp_msgs = []
|
|
|
|
types = [] %>
|
2016-08-18 13:18:02 +00:00
|
|
|
<% @survey.result_criteria.each do |criteria| %>
|
2016-10-29 11:33:54 +00:00
|
|
|
<%
|
|
|
|
total_criteria_score = 0
|
2021-10-13 09:15:47 +00:00
|
|
|
total_weight = 0
|
2016-11-16 10:46:58 +00:00
|
|
|
((criteria["questions"][0].to_i - 1)..(criteria["questions"][1].to_i - 1)).each do |x|
|
2016-10-29 11:33:54 +00:00
|
|
|
total_criteria_score = (total_criteria_score + @answer_model.individual_total[x].to_i) rescue 0
|
2021-10-13 09:15:47 +00:00
|
|
|
k = weight_relations.keys[x]
|
|
|
|
if k && answer_model_attrs.has_key?(k)
|
|
|
|
total_weight += weight_relations[k]
|
|
|
|
end
|
2016-10-29 11:33:54 +00:00
|
|
|
end
|
2021-10-13 09:15:47 +00:00
|
|
|
type = criteria["type"].to_i
|
2016-10-29 11:33:54 +00:00
|
|
|
%>
|
2021-10-13 09:15:47 +00:00
|
|
|
<% 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 %>
|
2016-08-18 13:18:02 +00:00
|
|
|
<% end %>
|
|
|
|
<% end %>
|
2021-10-13 09:15:47 +00:00
|
|
|
<% 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 %>
|
2016-08-18 13:18:02 +00:00
|
|
|
<% else %>
|
|
|
|
<h3><%= t('survey.answer_success')%></h3>
|
|
|
|
<% end %>
|
|
|
|
|
2021-10-13 09:23:06 +00:00
|
|
|
<a href="<%= data['url'] %>" class="btn btn-primary" title="<%=t("survey.go_back")%>"><%=t("survey.go_back")%></a>
|