<commit_before>namespace :db do
  desc 'Populate database with fake data for development'
  task :populate => [ 'db:seed', 'db:populate:create' ]
  
  namespace :populate do
    
    desc "Reload populate data"
    task :reload => [ 'db:reset', :create ]
    
    desc "Create populate data"
    task :create => :environment do
      
      LOGOS_PATH = File.join(Rails.root, 'lib', 'logos')
      
      Mailboxer.setup do |config|
        config.uses_emails = false
      end
      
      def set_logos(klass)
        klass.all.each do |i|
          logo = Dir[File.join(LOGOS_PATH, klass.to_s.tableize, "#{ i.id }.*")].first
          avatar = Dir[File.join(LOGOS_PATH, klass.to_s.tableize, "#{ i.id }.*")].first
        
          if avatar.present? && File.exists?(avatar)
            Avatar.copy_to_temp_file(avatar)
            dimensions = Avatar.get_image_dimensions(avatar)
            l = Avatar.new(:actor => i.actor,:logo => File.open(avatar), :name => File.basename(avatar), :crop_x => 0, :crop_y => 0, :crop_w => dimensions[:width], :crop_h => dimensions[:height] )
            l.active = true
            l.save(false)
          end
        end
      end
      
      def set_tags(klass)
        klass.all.each do |el|
          el.tag_list = Forgery::LoremIpsum.words(1,:random => true)+", "+
                        Forgery::LoremIpsum.words(1,:random => true)+", "+
                        Forgery::LoremIpsum.words(1,:random => true)
          el.save!
        end
      end
      
      puts 'User population'
      users_start = Time.now
      
      # = Users
      
      # Create demo user if not present
      if User.find_by_name('demo').blank?
        User.create! :name => 'Demo',
                     :email => '<EMAIL>',<commit_msg>save(false) does not work in Rails 3.1<commit_after>namespace :db do
  desc 'Populate database with fake data for development'
  task :populate => [ 'db:seed', 'db:populate:create' ]
  
  namespace :populate do
    
    desc "Reload populate data"
    task :reload => [ 'db:reset', :create ]
    
    desc "Create populate data"
    task :create => :environment do
      
      LOGOS_PATH = File.join(Rails.root, 'lib', 'logos')
      
      Mailboxer.setup do |config|
        config.uses_emails = false
      end
      
      def set_logos(klass)
        klass.all.each do |i|
          logo = Dir[File.join(LOGOS_PATH, klass.to_s.tableize, "#{ i.id }.*")].first
          avatar = Dir[File.join(LOGOS_PATH, klass.to_s.tableize, "#{ i.id }.*")].first
        
          if avatar.present? && File.exists?(avatar)
            Avatar.copy_to_temp_file(avatar)
            dimensions = Avatar.get_image_dimensions(avatar)
            l = Avatar.new(:actor => i.actor,:logo => File.open(avatar), :name => File.basename(avatar), :crop_x => 0, :crop_y => 0, :crop_w => dimensions[:width], :crop_h => dimensions[:height] )
            l.active = true
            l.save
          end
        end
      end
      
      def set_tags(klass)
        klass.all.each do |el|
          el.tag_list = Forgery::LoremIpsum.words(1,:random => true)+", "+
                        Forgery::LoremIpsum.words(1,:random => true)+", "+
                        Forgery::LoremIpsum.words(1,:random => true)
          el.save!
        end
      end
      
      puts 'User population'
      users_start = Time.now
      
      # = Users
      
      # Create demo user if not present
      if User.find_by_name('demo').blank?
        User.create! :name => 'Demo',
                     :email => '<EMAIL>',
{'fraction_non_alphanumeric': 0.13515801354401805, 'fraction_numerical': 0.003386004514672686, 'mean_word_length': 1.9541666666666666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '5599448', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1162, 'n_words': 243}