app/lib/profile_insights.rb
# Unroll each question from the survey into a separate insight
Unroll each question from the survey into a separate insight
Unroll each question from the survey into a separate insight
def profile_insights_from_survey(most_recent_survey)
    survey_insights = []
    prompt_keys_to_include = [
      :proud,
      :best_qualities,
      :activities_and_interests,
      :nervous_or_stressed,
      :learn_best
    ]
    prompt_keys_to_include.each do |prompt_key|
      survey_response_text = most_recent_survey[prompt_key].strip
      next if survey_response_text.nil? || survey_response_text == ''
      survey_text = render_survey_as_text(most_recent_survey, prompt_keys_to_include)
      student_voice_completed_survey_json = most_recent_survey.as_json({
        only: [:id, :form_timestamp, :created_at]
      }).merge(survey_text: survey_text)
      survey_insights << ProfileInsight.new('student_voice_survey_response', {
        prompt_key: prompt_key,
        prompt_text: StudentVoiceCompletedSurvey.columns_for_form_v2[prompt_key],
        survey_response_text: survey_response_text,
        student_voice_completed_survey: student_voice_completed_survey_json
      })
    end
    survey_insights
  end
def profile_insights_from_survey ( most_recent_survey ) survey_insights = [ ] prompt_keys_to_include = [ :proud , :best_qualities , :activities_and_interests , :nervous_or_stressed , :learn_best ] prompt_keys_to_include . each do | prompt_key | survey_response_text = most_recent_survey [ prompt_key ] . strip next if survey_response_text . nil? || survey_response_text == '' survey_text = render_survey_as_text ( most_recent_survey , prompt_keys_to_include ) student_voice_completed_survey_json = most_recent_survey . as_json ( { only : [ :id , :form_timestamp , :created_at ] } ) . merge ( survey_text : survey_text ) survey_insights << ProfileInsight . new ( 'student_voice_survey_response' , { prompt_key : prompt_key , prompt_text : StudentVoiceCompletedSurvey . columns_for_form_v2 [ prompt_key ] , survey_response_text : survey_response_text , student_voice_completed_survey : student_voice_completed_survey_json } ) end survey_insights end
Unroll each question from the survey into a separate insight
Unroll each question from the survey into a separate insight
most_recent_survey
<not_specific>