<commit_before># Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do

  factory :task_definition do
    unit
    name                      { Populator.words(1..3) }
    description               { Populator.words(1..3) }
    upload_requirements       { [{'key' => 'file0','name' => 'Imported Code','type' => 'code'}] }
    sequence(:abbreviation)   { |n| "P1.#{n}" }
    weighting                 { rand(1..5) }
    start_date                { unit.start_date + rand(1..12).weeks }
    target_date               { start_date + rand(1..2).weeks }
    target_grade              { rand(0..3) }
    group_set                 nil
    tutorial_stream           { unit.tutorial_streams.sample }
  end

  factory :learning_outcome do
    unit
    name                      { Populator.words(1..3) }
    sequence(:abbreviation)   { |n| "ULO-#{n}" }
    sequence(:ilo_number)     { |n| n }
    description               { "description" }
  end

  factory :unit do
    transient do
      student_count 0
      task_count 2
      tutorials 1  #per campus
      tutorial_config [] #[ {stream: 0, campus: 0} ]
      group_sets 0
      groups [ ] #[ { gs: 0, students:0 } ]
      group_tasks [ ] #[ {idx: 0, gs: 0 }] - index of task, and index of group set
      outcome_count 2
      stream_count 0
      campus_count 1
      set_one_of_each_task false  # In addition to the standard tasks, also add one of each different think of task - group, quality, graded, etc.
    end

    name            { Populator.words(1..2) }
    description     "Description"
    start_date      Time.zone.now
    end_date        Time.zone.now + 14.weeks
    teaching_period nil
    code            "COS10001"
    active          true

    after(:create) do | unit, eval |
      group_sets = eval.group_sets
      task_count = eval.task_count
      group_tasks = eval.group_tasks
      groups = eval.groups

      if eval.set_one_of_each_task
        group_sets = 1 unless group_sets > 0
        task_count = 3 if task_count < 3
        group_tasks << {idx: 0, gs: group_sets - 1}
        group_sets.times do |gs|
          (eval.student_count / 4).times do
            groups << { gs: gs, students: 4}
          end
        end
      end

      campuses = create_list(:campus, eval.campus_count)

      create_list(:group_set, group_sets, unit: unit)
      create_list(:learning_outcome, eval.outcome_count, unit: unit)
      tutorial_streams = create_list(:tutorial_stream, eval.stream_count, unit: unit)
      create_list(:task_definition, task_count, unit: unit)

      if eval.set_one_of_each_task
        unit.task_definitions[1].update(max_quality_pts: 5)
        unit.task_definitions[2].update(is_graded: true)
      end

      campuses.each do |c|
        # loop to 2nd last, unless there are no streams... then loop for all
        break if (c == campuses.last) && tutorial_streams.count > 0<commit_msg>FIX: Ensure lists are cloned in unit factory<commit_after># Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do

  factory :task_definition do
    unit
    name                      { Populator.words(1..3) }
    description               { Populator.words(1..3) }
    upload_requirements       { [{'key' => 'file0','name' => 'Imported Code','type' => 'code'}] }
    sequence(:abbreviation)   { |n| "P1.#{n}" }
    weighting                 { rand(1..5) }
    start_date                { unit.start_date + rand(1..12).weeks }
    target_date               { start_date + rand(1..2).weeks }
    target_grade              { rand(0..3) }
    group_set                 nil
    tutorial_stream           { unit.tutorial_streams.sample }
  end

  factory :learning_outcome do
    unit
    name                      { Populator.words(1..3) }
    sequence(:abbreviation)   { |n| "ULO-#{n}" }
    sequence(:ilo_number)     { |n| n }
    description               { "description" }
  end

  factory :unit do
    transient do
      student_count 0
      task_count 2
      tutorials 1  #per campus
      tutorial_config [] #[ {stream: 0, campus: 0} ]
      group_sets 0
      groups [ ] #[ { gs: 0, students:0 } ]
      group_tasks [ ] #[ {idx: 0, gs: 0 }] - index of task, and index of group set
      outcome_count 2
      stream_count 0
      campus_count 1
      set_one_of_each_task false  # In addition to the standard tasks, also add one of each different think of task - group, quality, graded, etc.
    end

    name            { Populator.words(1..2) }
    description     "Description"
    start_date      Time.zone.now
    end_date        Time.zone.now + 14.weeks
    teaching_period nil
    code            "COS10001"
    active          true

    after(:create) do | unit, eval |
      group_sets = eval.group_sets
      task_count = eval.task_count
      group_tasks = eval.group_tasks.clone
      groups = eval.groups.clone

      if eval.set_one_of_each_task
        group_sets = 1 unless group_sets > 0
        task_count = 3 if task_count < 3
        group_tasks << {idx: 0, gs: group_sets - 1}
        group_sets.times do |gs|
          (eval.student_count / 4).times do
            groups << { gs: gs, students: 4}
          end
        end
      end

      campuses = create_list(:campus, eval.campus_count)

      create_list(:group_set, group_sets, unit: unit)
      create_list(:learning_outcome, eval.outcome_count, unit: unit)
      tutorial_streams = create_list(:tutorial_stream, eval.stream_count, unit: unit)
      create_list(:task_definition, task_count, unit: unit)

      if eval.set_one_of_each_task
        unit.task_definitions[1].update(max_quality_pts: 5)
        unit.task_definitions[2].update(is_graded: true)
      end

      campuses.each do |c|
        # loop to 2nd last, unless there are no streams... then loop for all
        break if (c == campuses.last) && tutorial_streams.count > 0
{'fraction_non_alphanumeric': 0.10086749447184895, 'fraction_numerical': 0.01769008334750808, 'mean_word_length': 2.0497925311203318, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '6321919', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1827, 'n_words': 462}