app/models/questionnaire.rb
# for questionnaire wise stochastics
# return count array of selected choices

for questionnaire wise stochastics
return count array of selected choices
for questionnaire wise stochastics return count array of selected choices
def sum_up_answers
    (no_of_answers = answers.size) <= 0 and return []
    case question_type
    when Free_Form_Type
      []
    when Single_Choice_Type
      count_array = answers.inject([]) do |sum, a|
        unless a.answer.blank?
          index = a.answer.to_i - 1
          sum[index].nil? ? sum[index] = 1 : sum[index] += 1
        end
        sum
      end
      count_array.map do |count|
        count ||= 0
        count * 100.0 / no_of_answers
      end
    when Multiple_Choice_Type
      count_array = answers.inject([]) do |sum, a|
        unless a.answer.blank?
          answer_series = a.multiple_choice_answers
          answer_series.each do |ans_value|
            index = ans_value - 1 
            sum[index].nil? ? sum[index] = 1 :sum[index] += 1
          end
        end
        sum
      end
      count_array.map do |count|
        count ||= 0
        count * 100.0 / no_of_answers
      end
    end    
  end
def sum_up_answers ( no_of_answers = answers . size ) <= 0 and return [ ] case question_type when Free_Form_Type [ ] when Single_Choice_Type count_array = answers . inject ( [ ] ) do | sum , a | unless a . answer . blank? index = a . answer . to_i - 1 sum [ index ] . nil? ? sum [ index ] = 1 : sum [ index ] += 1 end sum end count_array . map do | count | count ||= 0 count * 100.0 / no_of_answers end when Multiple_Choice_Type count_array = answers . inject ( [ ] ) do | sum , a | unless a . answer . blank? answer_series = a . multiple_choice_answers answer_series . each do | ans_value | index = ans_value - 1 sum [ index ] . nil? ? sum [ index ] = 1 : sum [ index ] += 1 end end sum end count_array . map do | count | count ||= 0 count * 100.0 / no_of_answers end end end
for questionnaire wise stochastics
return count array of selected choices
for questionnaire wise stochastics return count array of selected choices