% data = action_data @survey = data["survey"] @user = data["user"] @survey_answers = data["survey_answers"] @table_fields = data["table_fields"] @is_answer_list = data["is_answer_list"] %> <% if @user.nil? %>
<%= user.member_name rescue user.name %> | <% else %>NA | <% end %><%= (@is_answer_list ? sa.created_at : sa.last_modified).strftime((I18n.locale == :zh_tw ? "%Y/%m/%d %H:%M" : "%h %d, %Y - %H:%M")) rescue nil %> |
<% if @answer_repeat && !@is_answer_list %>
"><%= t("survey.view") %>(<%=sa.survey_answer_ids.count%>)
<% else %>
<% sa = sa.survey_answers.last if answers_nil %>
<% if @survey.result_type == QuestionnaireSurvey::ResultCriteria %>
<% tmp_msgs = []
answer_model_attrs = sa.attributes
weight_relations = @survey.survey_questions.map{|q| [q.id.to_s,(q.weight.nil? ? 1 : q.weight)]}.to_h
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 + sa.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 %>
<% if ((criteria["range"][0].to_i..criteria["range"][1].to_i).cover?(total_criteria_score / total_weight) rescue false) %>
<% tmp_msgs << criteria["msg"] %>
<% types << type %>
<% end %>
<% end %>
<% end %>
<% if types.include?(0) %>
Your total score is <%= sa.scored_points %><% end %> <% if types.include?(1) %>Your average score is <%= sa.get_avg_points %><% end %> <% tmp_msgs.each do |msg| %><%=msg.html_safe%>
<% end %>
<% else %>
"><%= t("survey.view_answers") %>
<% end %>
<% end %>
|