<commit_before># frozen_string_literal: true

require 'ffaker'
require 'factory_girl_rails'
require 'paper_trail'
require 'timecop'

include FactoryGirl::Syntax::Methods

staff = create :user, :staff, :fake_name

supervisors = 10.times.map { |_| create :user, :supervisor, :fake_name }

drivers = 50.times.map { |_| create :user, :driver, :fake_name }

codes = {
  collision: create(:reason_code, description: 'Collision'),
  passenger_incident: create(:reason_code, description: 'Passenger Incident'),
  nil => create(:reason_code, description: 'Other')
}

dates = (4.months.ago.to_date..Date.yesterday).to_a
dates.shuffle.each.with_index do |day, i|
  driver = drivers.sample
  supervisor = supervisors.sample
  # Every 20th incident shall be incomplete.
  incident_type = [nil, :collision, :passenger_incident].sample
  incident_type = :incomplete if (i % 9).zero?
  Timecop.freeze day + rand(24 * 60).minutes do
    PaperTrail.whodunnit = driver.id
    driver_report = if incident_type.present?
      create :incident_report, incident_type, user: driver
    else create :incident_report, user: driver
    end
    supervisor_report_attrs = driver_report.attributes.symbolize_keys
                                           .except(:id, :user_id)
                                           .merge(user: supervisor)
    supervisor_report = create :incident_report, supervisor_report_attrs
    incident = create :incident, driver_incident_report: driver_report,
                                 supervisor_incident_report: supervisor_report,
                                 supervisor_report: create(:supervisor_report, user: supervisor),
                                 completed: incident_type != :incomplete,
                                 reason_code: codes[incident_type]
    # Every 8th-ish incident shall be unreviewed.
    unless incident_type == :incomplete || (i % 8).zero?
      create :staff_review, incident: incident, user: staff
    end
  end
end<commit_msg>Only have supervisor response to every other incident<commit_after># frozen_string_literal: true

require 'ffaker'
require 'factory_girl_rails'
require 'paper_trail'
require 'timecop'

include FactoryGirl::Syntax::Methods

staff = create :user, :staff, :fake_name

supervisors = 10.times.map { |_| create :user, :supervisor, :fake_name }

drivers = 50.times.map { |_| create :user, :driver, :fake_name }

codes = {
  collision: create(:reason_code, description: 'Collision'),
  passenger_incident: create(:reason_code, description: 'Passenger Incident'),
  nil => create(:reason_code, description: 'Other')
}

dates = (4.months.ago.to_date..Date.yesterday).to_a
dates.shuffle.each.with_index do |day, i|
  driver = drivers.sample
  supervisor = supervisors.sample
  # Every 20th incident shall be incomplete.
  incident_type = [nil, :collision, :passenger_incident].sample
  incident_type = :incomplete if (i % 9).zero?
  Timecop.freeze day + rand(24 * 60).minutes do
    PaperTrail.whodunnit = driver.id
    driver_report = if incident_type.present?
      create :incident_report, incident_type, user: driver
    else create :incident_report, user: driver
    end
    incident_attrs = { driver_incident_report: driver_report,
                       completed: incident_type != :incomplete,
                       reason_code: codes[incident_type] }
    # Only every other incident should require supervisor response.
    if i.even?
      supervisor_report_attrs = driver_report.attributes.symbolize_keys
                                             .except(:id, :user_id)
                                             .merge(user: supervisor)
      supervisor_report = create :incident_report, supervisor_report_attrs
      incident_attrs.merge! supervisor_incident_report: supervisor_report,
                            supervisor_report: create(:supervisor_report, user: supervisor)
    else incident_attrs.merge! supervisor_incident_report: nil, supervisor_report: nil
    end
    incident = create :incident, incident_attrs
    # Every 8th-ish incident shall be unreviewed.
    unless incident_type == :incomplete || (i % 8).zero?
      create :staff_review, incident: incident, user: staff
    end
  end
end
{'fraction_non_alphanumeric': 0.09333969921222249, 'fraction_numerical': 0.0066841728336118405, 'mean_word_length': 3.1816367265469063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1616197', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1189, 'n_words': 298}