<commit_before>unless ENV['RACK_ENV'] == 'production'
  namespace :db do
    desc 'Load seed data into the database'
    task :seed => :environment do
      buildDataFromFolder("seeds")
    end

    desc 'Load account data into the database'
    task :fixtures => :environment do
      buildDataFromFolder("fixtures")

      # Harrison Heights has too much void.
      Rake::Task["kill_them_all"].invoke if Instance.plane == 3
    end

    desc 'Build seed files from database'
    task :build_seed => :environment do
      write_seed(Entity::StatusType, 'status_type', 1)
      write_seed(Entity::Plane, 'plane', 2)
      write_seed(Entity::TileType, 'tile_type', 3)
      write_seed(Entity::Tile, 'tile', 4)
      write_seed(Entity::ItemType, 'item_type', 5)
    end
  end
end

def buildDataFromFolder(folder)
	belongAccount = nil
	Dir[Dir.pwd+"/" + folder + "/*.json"].sort.each do |seed_file|
		next unless File.file? seed_file
		trimmedFileName = File.basename(seed_file, '.json').split("-")
    klass = trimmedFileName[1].classify
		puts "Seeding #{klass}... "
		(seeds = JSON.parse(File.read(seed_file))).each do |seed|
			entity = Entity.class_eval(klass).new

      keys = seed.keys
      id_keys = keys.select { |key| key.end_with? 'id' }
      other_keys = keys - id_keys

      keys = id_keys + other_keys

			keys.each do |property|
        entity.send "#{property}=", seed[property]
			end

      entity.plane = Instance.plane if entity.respond_to? 'plane=' unless klass == 'Plane'
			entity.save
		end
		puts " Done. (seeded #{seeds.count} records)"
	end
	puts
end

def write_seed(collection, filename, filenumber)
  items = build_json_array(collection)
  write_json_file(items, filename, filenumber)

  puts "Build #{filename} file with #{items.count} records"
end

def write_json_file(items, filename, filenumber)
  path = Dir.pwd + '/seeds/' + filenumber.to_s + '-' + filename + '.json'

  FileUtils.rm(path) if File.exist?(path)

  File.open(path, 'w+') do |file|
    file.puts('[')

    if items.any?
      items.take(items.count - 1).each {|item| file.puts(item + ',')}
      file.puts(items.last)
    end

    file.puts(']')
  end<commit_msg>Only reset the plane of the character table when seeding<commit_after>unless ENV['RACK_ENV'] == 'production'
  namespace :db do
    desc 'Load seed data into the database'
    task :seed => :environment do
      buildDataFromFolder("seeds")
    end

    desc 'Load account data into the database'
    task :fixtures => :environment do
      buildDataFromFolder("fixtures")

      # Harrison Heights has too much void.
      Rake::Task["kill_them_all"].invoke if Instance.plane == 3
    end

    desc 'Build seed files from database'
    task :build_seed => :environment do
      write_seed(Entity::StatusType, 'status_type', 1)
      write_seed(Entity::Plane, 'plane', 2)
      write_seed(Entity::TileType, 'tile_type', 3)
      write_seed(Entity::Tile, 'tile', 4)
      write_seed(Entity::ItemType, 'item_type', 5)
    end
  end
end

def buildDataFromFolder(folder)
	belongAccount = nil
	Dir[Dir.pwd+"/" + folder + "/*.json"].sort.each do |seed_file|
		next unless File.file? seed_file
		trimmedFileName = File.basename(seed_file, '.json').split("-")
    klass = trimmedFileName[1].classify
		puts "Seeding #{klass}... "
		(seeds = JSON.parse(File.read(seed_file))).each do |seed|
			entity = Entity.class_eval(klass).new

      keys = seed.keys
      id_keys = keys.select { |key| key.end_with? 'id' }
      other_keys = keys - id_keys

      keys = id_keys + other_keys

			keys.each do |property|
        entity.send "#{property}=", seed[property]
			end

      entity.plane = Instance.plane if entity.respond_to? 'plane=' and klass == 'Character'
			entity.save
		end
		puts " Done. (seeded #{seeds.count} records)"
	end
	puts
end

def write_seed(collection, filename, filenumber)
  items = build_json_array(collection)
  write_json_file(items, filename, filenumber)

  puts "Build #{filename} file with #{items.count} records"
end

def write_json_file(items, filename, filenumber)
  path = Dir.pwd + '/seeds/' + filenumber.to_s + '-' + filename + '.json'

  FileUtils.rm(path) if File.exist?(path)

  File.open(path, 'w+') do |file|
    file.puts('[')

    if items.any?
      items.take(items.count - 1).each {|item| file.puts(item + ',')}
      file.puts(items.last)
    end

    file.puts(']')
  end
{'fraction_non_alphanumeric': 0.1372369624885636, 'fraction_numerical': 0.0036596523330283625, 'mean_word_length': 3.408266129032258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7508960', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1473, 'n_words': 368}