<commit_before>module Demo::AdminReportDemoCreator
  def self.create_demo(name, email_safe_school_name, teacher_email)
    # Create the school
    school = School.create!(name: name)

    # Create admin teacher
    admin_teacher = User.create!(
      name: '<NAME>',
      role: 'teacher',
      email: teacher_email,
      username: '',
      password: <PASSWORD>Random.urlsafe_base64
    )

    # Add admin teacher to school as an admin
    SchoolsAdmins.create!(school_id: school.id, user_id: admin_teacher.id)

    # Find or create a few other teachers
    teachers = ['<NAME>', '<NAME>', '<NAME>']
    teachers = teachers.map do |teacher|
      User.create!(
        name: teacher,
        role: 'teacher',
        email: "hello+admindemo-#{email_safe_school_name}-#{teacher.<EMAIL>(' <EMAIL>",
        username: '',
        password: <PASSWORD>Random.urlsafe_base64
      )
    end

    teachers << admin_teacher

    # Upgrade everyone to premium
    subscription_id = Subscription.create!(purchaser_id: admin_teacher.id, account_type: 'Demo Premium', expiration: Date.today + 100.years).id
    teachers.each do |teacher|
      UserSubscription.create!(user_id: teacher.id, subscription_id: subscription_id)
    end

    # Create a bunch of classrooms and classrooms_teachers associations
    classrooms = [
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'Period 1'), user: admin_teacher).classroom,
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'Period 2'), user: admin_teacher).classroom,
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'English 1'), user: teachers.first).classroom,
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'ELA 1'), user: teachers.second).classroom,
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'Block One'), user: teachers.third).classroom
    ]

    # Choose some unit templates we want to base the units off of
    # NOTE: if you change the unit templates, please see the note above 'exemplar_activity_sessions' below
    unit_template_ids = [20, 3, 4, 46, 44]
    unit_templates = unit_template_ids.map { |id| UnitTemplate.find(id) }

    # Add teachers to the school, units to each teacher, and classroom activities to the units
    teachers.each do |teacher|
      SchoolsUsers.create!(school_id: school.id, user_id: teacher.id)
      units = unit_templates.map { |unit_template| Unit.create!(name: unit_template.name, user_id: teacher.id) }
      teacher.classrooms_i_teach.each do |classroom|
        units.each_with_index do |unit, index|
          unit_templates[index].activities.to_a.uniq.each do |activity|
            ClassroomActivity.create!(classroom_id: classroom.id, activity_id: activity.id, unit_id: unit.id, assign_on_join: true)
          end
        end
      end
    end

    # List of author names to use for student names
    student_names = [
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>"
    ].shuffle

    # How many students per class?
    number_of_students_per_class = 5

    # Add students to the classrooms
    classrooms.each_with_index do |classroom, index|
      number_of_students_per_class.times do |n|
        student_name = student_names[(number_of_students_per_class * index) + n]
        student = User.create!(
          role: 'student',
          name: student_name,
          password: 'password',
          username: "#{student_name.downcase.sub(' ', '-')}@#{classroom.code}"
        )
        StudentsClassrooms.create!(student_id: student.id, classroom_id: classroom.id)
      end
    end

    # Create a map of classroom activity IDs to arrays of exemplar activity sessions to copy
    # NOTE: we manually selected these activity sessions as a representative sample because
    # it would be pretty computationally intensive to select randomly from all of the
    # associated activity sessions. In the event this demo creator for some reason changes,
    # you'll need to update the exemplar activity sessions manually.
    exemplar_activity_sessions = {
      413 => [26132834, 22674997, 23713760, 14651990, 27055198, 18415812, 22221644, 22513965, 27742073, 22158443],
      182 => [22048631, 27667308, 8907523, 3254361, 1598630, 2019699, 28896968, 3848334, 5927654, 25256514],
      165 => [8655355, 10384565, 7728923, 10888514, 19259048, 27499931, 9244672, 29270571, 17727174],
      177 => [3286331, 2598862, 11393817, 21106096, 2304963, 16243410, 8292121, 4243576, 8390959],
      176 => [3533881, 22299270, 28214093, 16169337, 2050344, 12575685, 10083611, 4728267],
       63 => [6162798, 2781282, 7898538, 10039303, 12346263, 27200543, 17472092, 26083226, 7767661],
       69 => [3421136, 14719539, 2306053, 8839785, 18159027, 27889910, 15582813, 123324],
      168 => [27525129, 11107977, 13452776, 4781007, 18059935, 8594742, 22460531, 11026672],
       77 => [22928913, 20999382, 5844732, 21162049, 9756885, 3139148, 22098329, 9906747, 9605560],
      169 => [12499260, 8594352, 27781517, 20855319, 27675646, 23610692, 27357322, 6146957, 3927662],
      107 => [23198318, 8985748, 6874550, 5612963, 28221047, 13513371, 28530677, 19281636],
      113 => [7247763, 7201638, 6971429, 28153116, 15667648, 4759171, 6874847, 13623922, 23351585],
      111 => [4412433, 7641405, 29133289, 28226170, 28738913, 1416021, 10071820, 28921073],
      112 => [3569714, 14067307, 27587029, 17413447, 19843322, 29167975, 2483020, 308392, 2422426],
      110 => [27402978, 3882494, 2972394, 2107590, 22332137, 29308511, 12215419, 14469882],
      108 => [6003924, 2381787, 9059288, 22089450, 9425941, 2289906, 5124950, 10911501],
      109 => [1394227, 13573237, 11777934, 12152451, 6408246, 8968064, 16857416, 21841339],
      273 => [11968758, 10427339, 22435199, 17393608, 13968692, 28949511, 7522721, 9540189],
      571 => [27919823],
      567 => [29001738],
      572 => [28173122]
    }

    # Add activity sessions and concept results for students of all but one teacher
    teachers[1..-1].each do |teacher|
      teacher.students.each do |student|
        teacher.classroom_activities.each do |classroom_activity|
          we_want_to_create_another_activity_session_for_this_student_and_classroom_activity = true
          # We want to ensure that activity 567 shows as in progress for demoing purposes
          the_activity_session_should_be_marked_as_in_progress = classroom_activity.activity.id === 567 ? true : false
          while we_want_to_create_another_activity_session_for_this_student_and_classroom_activity do
            exemplar_activity_session = ActivitySession.unscoped.find(exemplar_activity_sessions[classroom_activity.activity_id].sample)
            activity_session = ActivitySession.create!(
              classroom_activity_id: classroom_activity.id,
              user_id: student.id,
              activity_id: classroom_activity.activity_id,
              state: the_activity_session_should_be_marked_as_in_progress ? 'started' : 'finished',
              percentage: exemplar_activity_session.percentage,
            )
            exemplar_activity_session.concept_results.each do |cr|
              ConceptResult.create!(
                activity_session_id: activity_session.id,
                concept_id: cr.concept_id,
                metadata: cr.metadata,
                question_type: cr.question_type
              )
            end
            we_want_to_create_another_activity_session_for_this_student_and_classroom_activity = false
            # diagnostics and lessons cannot be repeated
            this_activity_can_be_repeated = ![4, 6].include?(classroom_activity.activity.activity_classification_id)
            # we want to show that some of these activities have been attempted more than once
            if this_activity_can_be_repeated && !the_activity_session_should_be_marked_as_in_progress
              we_want_to_create_another_activity_session_for_this_student_and_classroom_activity = true if Random.rand <= 0.25
              the_activity_session_should_be_marked_as_in_progress = true if Random.rand <= 0.25
            end
          end
        end
      end
    end

    admin_teacher
  end
end<commit_msg>update admin report demo creator<commit_after>module Demo::AdminReportDemoCreator
  def self.create_demo(name, email_safe_school_name, teacher_email)
    # Create the school
    school = School.create!(name: name)

    # Create admin teacher
    admin_teacher = User.create!(
      name: '<NAME>',
      role: 'teacher',
      email: teacher_email,
      username: '',
      password: <PASSWORD>Random.urlsafe_base64
    )

    # Add admin teacher to school as an admin
    SchoolsAdmins.create!(school_id: school.id, user_id: admin_teacher.id)

    # Find or create a few other teachers
    teachers = ['<NAME>', '<NAME>', '<NAME>']
    teachers = teachers.map do |teacher|
      User.create!(
        name: teacher,
        role: 'teacher',
        email: "hello+admindemo-#{email_safe_school_name}-#{teacher.<EMAIL>",
        username: '',
        password: <PASSWORD>.urlsafe_base64
      )
    end

    teachers << admin_teacher

    # Upgrade everyone to premium
    subscription_id = Subscription.create!(purchaser_id: admin_teacher.id, account_type: 'Demo Premium', expiration: Date.today + 100.years).id
    teachers.each do |teacher|
      UserSubscription.create!(user_id: teacher.id, subscription_id: subscription_id)
    end

    # Create a bunch of classrooms and classrooms_teachers associations
    classrooms = [
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'Period 1'), user: admin_teacher).classroom,
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'Period 2'), user: admin_teacher).classroom,
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'English 1'), user: teachers.first).classroom,
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'ELA 1'), user: teachers.second).classroom,
      ClassroomsTeacher.create!(role: ClassroomsTeacher::ROLE_TYPES[:owner], classroom: Classroom.create!(name: 'Block One'), user: teachers.third).classroom
    ]

    # Choose some unit templates we want to base the units off of
    # NOTE: if you change the unit templates, please see the note above 'exemplar_activity_sessions' below
    unit_template_ids = [20, 3, 4, 46, 44]
    unit_templates = unit_template_ids.map { |id| UnitTemplate.find(id) }

    # Add teachers to the school, units to each teacher, and classroom units and unit activities to the units
    teachers.each do |teacher|
      SchoolsUsers.create!(school_id: school.id, user_id: teacher.id)
      units = unit_templates.map { |unit_template| Unit.create!(name: unit_template.name, user_id: teacher.id) }
      teacher.classrooms_i_teach.each do |classroom|
        units.each_with_index do |unit, index|
          ClassroomUnit.find_or_create_by(classroom_id: classroom.id, unit_id: unit.id, assign_on_join: true)
          unit_templates[index].activities.to_a.uniq.each do |activity|
            UnitActivity.find_or_create_by(activity_id: activity.id, unit_id: unit.id)
          end
        end
      end
    end

    # List of author names to use for student names
    student_names = [
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>", "<NAME>",
      "<NAME>", "<NAME>", "<NAME>", "<NAME>"
    ].shuffle

    # How many students per class?
    number_of_students_per_class = 5

    # Add students to the classrooms
    classrooms.each_with_index do |classroom, index|
      number_of_students_per_class.times do |n|
        student_name = student_names[(number_of_students_per_class * index) + n]
        student = User.create!(
          role: 'student',
          name: student_name,
          password: 'password',
          username: "#{student_name.downcase.sub(' ', '-')}@#{classroom.code}"
        )
        StudentsClassrooms.create!(student_id: student.id, classroom_id: classroom.id)
      end
    end

    # Create a map of classroom activity IDs to arrays of exemplar activity sessions to copy
    # NOTE: we manually selected these activity sessions as a representative sample because
    # it would be pretty computationally intensive to select randomly from all of the
    # associated activity sessions. In the event this demo creator for some reason changes,
    # you'll need to update the exemplar activity sessions manually.
    exemplar_activity_sessions = {
      413 => [26132834, 22674997, 23713760, 14651990, 27055198, 18415812, 22221644, 22513965, 27742073, 22158443],
      182 => [22048631, 27667308, 8907523, 3254361, 1598630, 2019699, 28896968, 3848334, 5927654, 25256514],
      165 => [8655355, 10384565, 7728923, 10888514, 19259048, 27499931, 9244672, 29270571, 17727174],
      177 => [3286331, 2598862, 11393817, 21106096, 2304963, 16243410, 8292121, 4243576, 8390959],
      176 => [3533881, 22299270, 28214093, 16169337, 2050344, 12575685, 10083611, 4728267],
       63 => [6162798, 2781282, 7898538, 10039303, 12346263, 27200543, 17472092, 26083226, 7767661],
       69 => [3421136, 14719539, 2306053, 8839785, 18159027, 27889910, 15582813, 123324],
      168 => [27525129, 11107977, 13452776, 4781007, 18059935, 8594742, 22460531, 11026672],
       77 => [22928913, 20999382, 5844732, 21162049, 9756885, 3139148, 22098329, 9906747, 9605560],
      169 => [12499260, 8594352, 27781517, 20855319, 27675646, 23610692, 27357322, 6146957, 3927662],
      107 => [23198318, 8985748, 6874550, 5612963, 28221047, 13513371, 28530677, 19281636],
      113 => [7247763, 7201638, 6971429, 28153116, 15667648, 4759171, 6874847, 13623922, 23351585],
      111 => [4412433, 7641405, 29133289, 28226170, 28738913, 1416021, 10071820, 28921073],
      112 => [3569714, 14067307, 27587029, 17413447, 19843322, 29167975, 2483020, 308392, 2422426],
      110 => [27402978, 3882494, 2972394, 2107590, 22332137, 29308511, 12215419, 14469882],
      108 => [6003924, 2381787, 9059288, 22089450, 9425941, 2289906, 5124950, 10911501],
      109 => [1394227, 13573237, 11777934, 12152451, 6408246, 8968064, 16857416, 21841339],
      273 => [11968758, 10427339, 22435199, 17393608, 13968692, 28949511, 7522721, 9540189],
      571 => [27919823],
      567 => [29001738],
      572 => [28173122]
    }

    # Add activity sessions and concept results for students of all but one teacher
    teachers[1..-1].each do |teacher|
      teacher.students.each do |student|
        teacher.unit_activities.each do |unit_activity|
          we_want_to_create_another_activity_session_for_this_student_and_unit_activity = true
          # We want to ensure that activity 567 shows as in progress for demoing purposes
          the_activity_session_should_be_marked_as_in_progress = unit_activity.activity.id === 567 ? true : false
          classroom_unit = ClassroomUnit.find_by(unit_id: unit_activity.unit_id, classroom_id: [student.classroom_ids])
          while we_want_to_create_another_activity_session_for_this_student_and_unit_activity do
            exemplar_activity_session = ActivitySession.unscoped.find(exemplar_activity_sessions[unit_activity.activity_id].sample)
            activity_session = ActivitySession.create!(
              classroom_unit: classroom_unit,
              user_id: student.id,
              activity_id: unit_activity.activity_id,
              state: the_activity_session_should_be_marked_as_in_progress ? 'started' : 'finished',
              percentage: exemplar_activity_session.percentage,
            )
            exemplar_activity_session.concept_results.each do |cr|
              ConceptResult.create!(
                activity_session_id: activity_session.id,
                concept_id: cr.concept_id,
                metadata: cr.metadata,
                question_type: cr.question_type
              )
            end
            we_want_to_create_another_activity_session_for_this_student_and_unit_activity = false
            # diagnostics and lessons cannot be repeated
            this_activity_can_be_repeated = ![4, 6].include?(unit_activity.activity.activity_classification_id)
            # we want to show that some of these activities have been attempted more than once
            if this_activity_can_be_repeated && !the_activity_session_should_be_marked_as_in_progress
              we_want_to_create_another_activity_session_for_this_student_and_unit_activity = true if Random.rand <= 0.25
              the_activity_session_should_be_marked_as_in_progress = true if Random.rand <= 0.25
            end
          end
        end
      end
    end

    admin_teacher
  end
end
{'fraction_non_alphanumeric': 0.1357154051089171, 'fraction_numerical': 0.13508854411534243, 'mean_word_length': 3.5986067739610856, 'pattern_counts': {'":': 0, '<': 234, '<?xml version=': 0, '>': 268, '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': '2768744', 'n_tokens_mistral': 7818, 'n_tokens_neox': 6030, 'n_words': 1500}