<commit_before>module PublicProgressReports
    extend ActiveSupport::Concern

    def first_completed_diagnostic
      classroom_activities = current_user.classroom_activities(:activity_sessions)
      classroom_activities.each do |ca|
        if ca.activity_sessions
              .where.not(activity_sessions: {started_at: nil})
              .where(activity_sessions: {activity_id: Activity.diagnostic.id})
              .limit(1)
              .any?
              classroom_activity = ca
              return ca
        end
      end
      return false
    end

    def default_diagnostic_url
      if first_completed_diagnostic
        ca = first_completed_diagnostic
        custom_url = "#u/#{ca.unit.id}/a/#{Activity.diagnostic.id}/c/#{ca.classroom_id}"
        return "/teachers/progress_reports/diagnostic_reports/#{custom_url}/questions"
      else
        return "/teachers/progress_reports/diagnostic_reports/#not_completed"
      end
    end

    def results_by_question(params)
      classroom_activity = ClassroomActivity.find_by(classroom_id: params[:classroom_id], activity_id: params[:activity_id], unit_id: params[:unit_id])
      questions = Hash.new{|h,k| h[k]={} }
      all_answers = classroom_activity.activity_session_metadata
      all_answers.each do |answer|
        curr_quest = questions[answer["questionNumber"]]
        curr_quest[:correct] ||= 0
        curr_quest[:total] ||= 0
        curr_quest[:correct] += answer["correct"]
        curr_quest[:total] += 1
        curr_quest[:prompt] ||= answer["prompt"]
        curr_quest[:question_number] ||= answer["question_number"]
        if answer["attemptNumber"] == 1 || !!curr_quest[:instructions]
          curr_quest[:instructions] ||= answer["directions"] || answer["instructions"]
        end
      end
      # TODO: change the diagnostic reports so they take in a hash of classrooms -- this is just
      # being converted to an array because that is what the diagnostic reports expect
      questions_arr = questions.map do |k,v|
        {question_id: k,
         score: ((v[:correct].to_f/v[:total].to_f) * 100).round,
         prompt: v[:prompt],
         instructions: v[:instructions]
        }
      end
      questions_arr
    end<commit_msg>fixes bad 'or' statement in results by question<commit_after>module PublicProgressReports
    extend ActiveSupport::Concern

    def first_completed_diagnostic
      classroom_activities = current_user.classroom_activities(:activity_sessions)
      classroom_activities.each do |ca|
        if ca.activity_sessions
              .where.not(activity_sessions: {started_at: nil})
              .where(activity_sessions: {activity_id: Activity.diagnostic.id})
              .limit(1)
              .any?
              classroom_activity = ca
              return ca
        end
      end
      return false
    end

    def default_diagnostic_url
      if first_completed_diagnostic
        ca = first_completed_diagnostic
        custom_url = "#u/#{ca.unit.id}/a/#{Activity.diagnostic.id}/c/#{ca.classroom_id}"
        return "/teachers/progress_reports/diagnostic_reports/#{custom_url}/questions"
      else
        return "/teachers/progress_reports/diagnostic_reports/#not_completed"
      end
    end

    def results_by_question(params)
      classroom_activity = ClassroomActivity.find_by(classroom_id: params[:classroom_id], activity_id: params[:activity_id], unit_id: params[:unit_id])
      questions = Hash.new{|h,k| h[k]={} }
      all_answers = classroom_activity.activity_session_metadata
      all_answers.each do |answer|
        curr_quest = questions[answer["questionNumber"]]
        curr_quest[:correct] ||= 0
        curr_quest[:total] ||= 0
        curr_quest[:correct] += answer["correct"]
        curr_quest[:total] += 1
        curr_quest[:prompt] ||= answer["prompt"]
        curr_quest[:question_number] ||= answer["question_number"]
        if answer["attemptNumber"] == 1 || !curr_quest[:instructions]
          curr_quest[:instructions] ||= answer["directions"] || answer["instructions"]
        end
      end
      # TODO: change the diagnostic reports so they take in a hash of classrooms -- this is just
      # being converted to an array because that is what the diagnostic reports expect
      questions_arr = questions.map do |k,v|
        {question_id: k,
         score: ((v[:correct].to_f/v[:total].to_f) * 100).round,
         prompt: v[:prompt],
         instructions: v[:instructions]
        }
      end
      questions_arr
    end
{'fraction_non_alphanumeric': 0.10529816005320328, 'fraction_numerical': 0.0035468853912657946, 'mean_word_length': 2.836734693877551, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '925625', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1272, 'n_words': 266}