<commit_before>def sample_from_distribution(distribution)
    r = Random::rand(1.0)
    distribution.each {|k, v|
        if r < v
            return (if k.is_a?(Range) then k.to_a.sample else k end)
        else
            r -= v
        end
    }
end

class FakeStudent

  def initialize(homeroom)
    @student = Student.create(data)
    add_attendance_events
    add_discipline_incidents
    add_deprecated_interventions
    add_deprecated_notes
    add_event_notes
    add_services
    add_student_assessments_from_x2
    add_student_assessments_from_star
    add_student_assessments_from_access
    homeroom.students << @student
  end

  def student
    @student
  end

  private

  def data
    base_data.merge(plan_504)
             .merge(program_assigned_and_sped_disability)
  end

  DISNEY_FIRST_NAMES = [
    "Aladdin", "Chip", "Daisy", "Mickey", "Minnie",
    "Donald", "Elsa", "Mowgli", "Olaf", "Pluto",
    "Pocahontas", "Rapunzel", "Snow", "Winnie"
  ]

  DISNEY_LAST_NAMES = [
    "Disney", "Duck", "Kenobi", "Mouse", "Pan", "Poppins", "Skywalker", "White"
  ]

  def base_data
    {
      school_id: School.first.id,
      enrollment_status: enrollment_status,
      grade: "5",
      hispanic_latino: [true, false].sample,
      race: ["A", "B", "H", "W"].sample,
      first_name: DISNEY_FIRST_NAMES.sample,
      last_name: DISNEY_LAST_NAMES.sample,
      local_id: unique_local_id,
      limited_english_proficiency: ["Fluent", "FLEP-Transitioning", "FLEP"].sample,
      free_reduced_lunch: ["Free Lunch", "Not Eligible"].sample,
      home_language: ["Spanish", "English", "Portuguese", "Haitian-Creole"].sample
    }
  end

  def unique_local_id
    existing_local_ids = Student.pluck(:local_id)
    local_id = random_local_id
    while existing_local_ids.include?(local_id)
      local_id = random_local_id
    end
    local_id
  end
<commit_msg>Added comments for sample_from_distribution and added randomly distributed grade levels.<commit_after># Given a map of integers or ranges to weights, e.g
# 
#     d = {
#      0 => 0.83,
#      1 => 0.10,
#      (2..3) => 0.07,
#    }
# 
# Randomly chooses an integer in a correctly weighted way.
# Range keys mean that we sample uniformly from the range.
def sample_from_distribution(distribution)
    r = Random::rand(1.0)
    distribution.each {|k, v|
        if r < v
            return (if k.is_a?(Range) then k.to_a.sample else k end)
        else
            r -= v
        end
    }
end

class FakeStudent

  def initialize(homeroom)
    @student = Student.create(data)
    add_attendance_events
    add_discipline_incidents
    add_deprecated_interventions
    add_deprecated_notes
    add_event_notes
    add_services
    add_student_assessments_from_x2
    add_student_assessments_from_star
    add_student_assessments_from_access
    homeroom.students << @student
  end

  def student
    @student
  end

  private

  def data
    base_data.merge(plan_504)
             .merge(program_assigned_and_sped_disability)
  end

  DISNEY_FIRST_NAMES = [
    "Aladdin", "Chip", "Daisy", "Mickey", "Minnie",
    "Donald", "Elsa", "Mowgli", "Olaf", "Pluto",
    "Pocahontas", "Rapunzel", "Snow", "Winnie"
  ]

  DISNEY_LAST_NAMES = [
    "Disney", "Duck", "Kenobi", "Mouse", "Pan", "Poppins", "Skywalker", "White"
  ]

  def base_data
    {
      school_id: School.first.id,
      enrollment_status: enrollment_status,
      # PK = preschool, KF = kindergarten
      grade: ["1", "2", "3", "4", "5", "6", "7", "8", "PK", "KF"].sample,
      hispanic_latino: [true, false].sample,
      race: ["A", "B", "H", "W"].sample,
      first_name: DISNEY_FIRST_NAMES.sample,
      last_name: DISNEY_LAST_NAMES.sample,
      local_id: unique_local_id,
      limited_english_proficiency: ["Fluent", "FLEP-Transitioning", "FLEP"].sample,
      free_reduced_lunch: ["Free Lunch", "Not Eligible"].sample,
      home_language: ["Spanish", "English", "Portuguese", "Haitian-Creole"].sample
    }
  end

  def unique_local_id
    existing_local_ids = Student.pluck(:local_id)
    local_id = random_local_id
    while existing_local_ids.include?(local_id)
      local_id = random_local_id
    end
    local_id
  end

{'fraction_non_alphanumeric': 0.11646297627606039, 'fraction_numerical': 0.008147615624251139, 'mean_word_length': 3.140873015873016, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, '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': '4796809', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1477, 'n_words': 309}