<commit_before># This script is used to populate the database with preload data.
# It does not clear the database - mainly because that would mean deleting your
# admin login. All the numbers are pretty arbitrary, and can be changed to suit
# your needs, and how many records you want.
#
# As it stands, you'll need to follow the format and create a new seed
# generation block for each model you want to seed in the database, every time
# you create a model that isn't already here.
#
# Order matters!! The script will fail if certain records (Catgeories,
# EquipmentModels) aren't generated first and in the order listed.

require 'ffaker'
require 'ruby-progressbar'

#-------RESET PUBLIC DIR IF WE'VE RESET THE DATABASE
if EquipmentModel.all.empty?
  location_models = Rails.root.to_s + "/public/attachments/equipment_models"
  if File.directory?(location_models) # if the directory exists
    FileUtils.rm_r location_models # delete it and everything inside
  end
end


#-------METHODS

#Method for prompting the user for the number of records per model they want to seed into the database.
def ask_for_records(model)
  formatted_model = model.camelize

  puts "\nHow many #{formatted_model} records would you like to generate? (please enter a number)"
  STDIN.gets.chomp.to_i
end


def time_rand(from = 0.0, to = Time.now, length = 0, options = {})
  options[:passes_blackout_validations] = true

  range = to.to_f - from.to_f

  range = length.to_f if length > 0

  random_time = Time.at(from.to_f + rand * range)
  blackouts = Blackout.all.map { |blk| blk.start_date..blk.end_date }

  if options[:passes_blackout_validations] && !blackouts.blank?
    while includes?(blackouts, random_time)
      random_time = Time.at(from.to_f + rand * range)
      binding.pry
    end
  end

  random_time
end

def includes?(array_of_ranges, elem)
  array_of_ranges.each do |rng|
    if rng.include?(elem)
      return true
    else
      return false
    end
  end
end
<commit_msg>removed binding.pry from db/seeds.rb<commit_after># This script is used to populate the database with preload data.
# It does not clear the database - mainly because that would mean deleting your
# admin login. All the numbers are pretty arbitrary, and can be changed to suit
# your needs, and how many records you want.
#
# As it stands, you'll need to follow the format and create a new seed
# generation block for each model you want to seed in the database, every time
# you create a model that isn't already here.
#
# Order matters!! The script will fail if certain records (Catgeories,
# EquipmentModels) aren't generated first and in the order listed.

require 'ffaker'
require 'ruby-progressbar'

#-------RESET PUBLIC DIR IF WE'VE RESET THE DATABASE
if EquipmentModel.all.empty?
  location_models = Rails.root.to_s + "/public/attachments/equipment_models"
  if File.directory?(location_models) # if the directory exists
    FileUtils.rm_r location_models # delete it and everything inside
  end
end


#-------METHODS

#Method for prompting the user for the number of records per model they want to seed into the database.
def ask_for_records(model)
  formatted_model = model.camelize

  puts "\nHow many #{formatted_model} records would you like to generate? (please enter a number)"
  STDIN.gets.chomp.to_i
end


def time_rand(from = 0.0, to = Time.now, length = 0, options = {})
  options[:passes_blackout_validations] = true

  range = to.to_f - from.to_f

  range = length.to_f if length > 0

  random_time = Time.at(from.to_f + rand * range)
  blackouts = Blackout.all.map { |blk| blk.start_date..blk.end_date }

  if options[:passes_blackout_validations] && !blackouts.blank?
    while includes?(blackouts, random_time)
      random_time = Time.at(from.to_f + rand * range)
    end
  end

  random_time
end

def includes?(array_of_ranges, elem)
  array_of_ranges.each do |rng|
    if rng.include?(elem)
      return true
    else
      return false
    end
  end
end

{'fraction_non_alphanumeric': 0.08339651250947688, 'fraction_numerical': 0.0020217336365933787, 'mean_word_length': 3.751500600240096, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5139161', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1210, 'n_words': 464}