<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).
#

# Create Admin User
user = User.create!({
  :email    => "<EMAIL>",
  :name     => 'admin',
  :admin    => true,
  :password => '<PASSWORD>'
}, :as => :admin)

# Create Team
team = Team.create! \
  :name       => 'Lorem Ipsum',
  :admin_user => user

# Create some other users
%w(<NAME> <NAME>).each_with_index do |name, i|
  user = User.create! \
    :email    => <EMAIL>",
    :name     => name,
    :password => '<PASSWORD>'
  
  # add two users to the first team
  team.users << user if i < 2
end

# Import ontologies
Dir["#{Rails.root}/db/seeds/*.xml"].each do |file|
  basename = File.basename(file)
  
  o = Ontology.new \
    uri:         "file:///db/seeds/#{basename}",
    name:        basename.split(".")[0].capitalize,
    description: Faker::Lorem.paragraph

  o.import_xml_from_file file
end

# Create 5 ontologies
5.times do |n|
  o = Ontology.new \
    uri:         "gopher://host/ontology/#{n}",
    name:        Faker::Lorem.words(2+rand(4)).join(" "),
    description: Faker::Lorem.paragraph

  o.import_xml_from_file 'test/fixtures/ontologies/valid.xml'
  
  # create a version
  v = o.versions.build
  v.created_at = rand(300).minutes.ago
  v.user       = User.first
  v.save(:validate => false)
end


# Add permissions
Ontology.find_each do |o|
  o.permissions.create! \
    subject: Team.first,
    role: 'owner'
end

Ontology.first.permissions.create! \
  subject: User.first,
  role: 'editor'

<commit_msg>better created_at for seeded versions<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).
#

# Create Admin User
user = User.create!({
  :email    => "<EMAIL>",
  :name     => 'admin',
  :admin    => true,
  :password => '<PASSWORD>'
}, :as => :admin)

# Create Team
team = Team.create! \
  :name       => 'Lorem Ipsum',
  :admin_user => user

# Create some other users
%w(<NAME> <NAME>).each_with_index do |name, i|
  user = User.create! \
    :email    => <EMAIL>",
    :name     => name,
    :password => '<PASSWORD>'
  
  # add two users to the first team
  team.users << user if i < 2
end

# Import ontologies
Dir["#{Rails.root}/db/seeds/*.xml"].each do |file|
  basename = File.basename(file)
  
  o = Ontology.new \
    uri:         "file:///db/seeds/#{basename}",
    name:        basename.split(".")[0].capitalize,
    description: Faker::Lorem.paragraph

  o.import_xml_from_file file
end

# Create 5 ontologies
5.times do |n|
  o = Ontology.new \
    uri:         "gopher://host/ontology/#{n}",
    name:        Faker::Lorem.words(2+rand(4)).join(" "),
    description: Faker::Lorem.paragraph

  o.import_xml_from_file 'test/fixtures/ontologies/valid.xml'
  
  # create a version
  v = o.versions.build
  v.created_at = (60 - n*5).minutes.ago
  v.user       = User.first
  v.save(:validate => false)
end


# Add permissions
Ontology.find_each do |o|
  o.permissions.create! \
    subject: Team.first,
    role: 'owner'
end

Ontology.first.permissions.create! \
  subject: User.first,
  role: 'editor'


{'fraction_non_alphanumeric': 0.14796992481203008, 'fraction_numerical': 0.005413533834586466, 'mean_word_length': 2.9314420803782504, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '444324', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1158, 'n_words': 307}