<%= @survey.title %>

<% if @is_answer_list %>

<%=t('survey.taken_by')%>: <%=@user.member_name rescue "NA" %>

<% else %> <% end %>
<% type = nil %> <% if @is_answer_list %> <% type = 'result_chart' if params[:type] == 'result_chart' %>
<%=t("survey.table")%> <%=t("survey.result_chart")%>
<% end %> <% if type == "result_chart" %> <% @survey_answers.options = {} %>
<%= javascript_include_tag "survey/jquery.colorhelpers.js" %> <%= javascript_include_tag "survey/jquery.canvaswrapper.js" %> <%= javascript_include_tag "survey/jquery.flot_3.0.js" %> <%= javascript_include_tag "survey/jquery.flot.time.min.js" %> <%= javascript_include_tag "survey/jquery.flot.uiConstants.js" %> <%= javascript_include_tag "survey/jquery.flot.saturated.js" %> <%= javascript_include_tag "survey/jquery.flot.browser.js" %> <%= javascript_include_tag "survey/jquery.flot.drawSeries.js" %> <%= javascript_include_tag "survey/jquery.flot.axislabels.js" %> <%= javascript_include_tag "survey/jquery.flot.hover.js" %> <%= javascript_include_tag "survey/jquery.flot.animator.min.js" %> <%= javascript_include_tag "survey/moment.min.js" %> <% @survey_answers = @survey_answers.order_by(:created_at=>1) %> <% last_year = @survey_answers.last.created_at.year %> <% first_year = @survey_answers.first.created_at.year %> <% all_years = (first_year..last_year).to_a.reverse %> <% all_years.each do |year|%> <% start_d = DateTime.parse("#{year}/1/1 #{Time.zone}") %> <% end_d = start_d.end_of_year %> <% survey_answers_sep = @survey_answers.where(:created_at.gte=>start_d).and(:created_at.lte=>end_d) %> <% next if survey_answers_sep.count == 0 %>

<%= year %>

<% end %> <% else %> <% @table_fields.each do |f| %> <%= thead(f) %> <% end %> <% @is_answer_list = true if !@answer_repeat%> <% answers_nil = @survey_answers.nil? %> <% (@survey_answer_groups || @survey_answers).each do |sa| %> <% link_sa = sa if answers_nil link_sa = sa.survey_answers.last if link_sa.nil? sa.destroy next end end %> <% user = sa.user.nil? ? nil : (User.find(sa.user) rescue nil) %> <% if !user.nil? %> <% else %> <% end %> <% end %>
<%= user.member_name rescue user.name %>NA<%= (answers_nil ? sa.last_modified : sa.created_at).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 = link_sa %> <% 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 %> <% end %> <%= t("survey.view_answers") %> <% end %>
<%= content_tag :div, class: "bottomnav clearfix" do content_tag :div, paginate((@survey_answer_groups || @survey_answers)), class: "pagination pagination-centered" end %> <% end %>