<commit_before># This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)

SKIP_CONSTRUCTIONS = false
SKIP_FENESTRATION = false
SKIP_DOORS = false
SKIP_SPACES = false
SKIP_ZIP_CODES = false

u = User.find_or_create_by(email: '<EMAIL>')
u.roles = [:admin]
# Remove this if we share the code. This is very dangerous giving the admin a simple password for testing sake!
# only set password if it doesn't already exist
if u.encrypted_password.empty?
  u.password = 'password'
end
u.save!
# moved test project creation to sim.rake

unless SKIP_CONSTRUCTIONS
# CONSTRUCTION LIBRARIES
  file = File.read(File.join(Rails.root, "lib/assets/construction_library.json"))
  data = JSON.parse(file)

  data['constructions'].each_with_index
  do |c, index|
    cons = Construction.find_or_create_by(name: c['name'])
    if cons
      puts "Adding/Updating Construction: #{cons.name}"

      # Note that this is a one-way merge. It will not remove any fields that are in the current record instance that
      # need to be removed
      c = cons.as_json.merge(c)
      cons.update(c)
      cons.save!
    end
  end
end

unless SKIP_FENESTRATION
  file = File.read(File.join(Rails.root, "lib/assets/fenestration_library.json"))
  data = JSON.parse(file)<commit_msg>fix seed import<commit_after># This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)

SKIP_CONSTRUCTIONS = false
SKIP_FENESTRATION = false
SKIP_DOORS = false
SKIP_SPACES = false
SKIP_ZIP_CODES = false

u = User.find_or_create_by(email: '<EMAIL>')
u.roles = [:admin]
# Remove this if we share the code. This is very dangerous giving the admin a simple password for testing sake!
# only set password if it doesn't already exist
if u.encrypted_password.empty?
  u.password = 'password'
end
u.save!
# moved test project creation to sim.rake

unless SKIP_CONSTRUCTIONS
# CONSTRUCTION LIBRARIES
  file = File.read(File.join(Rails.root, "lib/assets/construction_library.json"))
  data = JSON.parse(file)

  data['constructions'].each_with_index do |c, index|
    cons = Construction.find_or_create_by(name: c['name'])
    if cons
      puts "Adding/Updating Construction: #{cons.name}"

      # Note that this is a one-way merge. It will not remove any fields that are in the current record instance that
      # need to be removed
      c = cons.as_json.merge(c)
      cons.update(c)
      cons.save!
    end
  end
end

unless SKIP_FENESTRATION
  file = File.read(File.join(Rails.root, "lib/assets/fenestration_library.json"))
  data = JSON.parse(file)
{'fraction_non_alphanumeric': 0.1004566210045662, 'fraction_numerical': 0.0, 'mean_word_length': 4.0694214876033055, 'pattern_counts': {'":': 0, '<': 5, '<?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': '703115', 'n_tokens_mistral': 1011, 'n_tokens_neox': 989, 'n_words': 325}