<commit_before>
require 'io_lock.rb'

class Dojo

  def self.names
    Dir.entries(Root_folder).select { |name| name != '.' and name != '..' }
  end

  def initialize(name)
    @name = name
  end

  def name
    @name
  end

  def avatars
    alive = []
    Avatar.names.each do |avatar_name|
      alive << Avatar.new(self, avatar_name) if File.exists?(folder + '/' + avatar_name)
    end
    alive
  end

  def folder
    Root_folder + '/' + name
  end

  def rotation(avatar_name)
  	options = {}
  	io_lock(folder) do
  		if File.exists?(rotation_filename)
  			options = eval IO.read(rotation_filename)
  		end

      mins_per_rotate = 5
      secs_per_rotate = mins_per_rotate * 60
      
      now = Time.now
    	due = now + secs_per_rotate
      options[:already_rotated] ||= []
      options[:prev_rotation_at] ||= [1966,11,23,0,0,0]      
      options[:next_rotation_at] ||= [due.year, due.month, due.day, due.hour, due.min, due.sec]

      already_rotated = options[:already_rotated].include?(avatar_name)
      refresh_period = 5 # from view_panel.html.erb :frequency
      very_recent_rotation = (now - Time.mktime(*options[:prev_rotation_at])).abs <= refresh_period
      due = Time.mktime(*options[:next_rotation_at])
      
      if now > due
      	# first avatar over the now-line
      	# but don't rotate if we're re-entering a dojo after a long break
        options[:do_now] = (now - due < (2 * refresh_period))
        options[:prev_rotation_at] = [now.year, now.month, now.day, now.hour, now.min, now.sec]
        due = now + secs_per_rotate
        options[:next_rotation_at] = [due.year, due.month, due.day, due.hour, due.min, due.sec]
        options[:already_rotated] = [avatar_name]
      elsif !already_rotated && very_recent_rotation
     		# another avatar over the line
     		# but don't re-rotate for the first avatar again
     	  options[:do_now] = true
     		options[:already_rotated] << avatar_name	
      else
      	options[:do_now] = false
      end

      File.open(rotation_filename, 'w') do |file|
        file.write(options.inspect) 
      end        		
  	end
  	options
  end
  
  def ladder
    rungs = []
    io_lock(folder) do
      if File.exists?(money_ladder_filename)
        rungs = eval IO.read(money_ladder_filename)
      else
        File.open(money_ladder_filename, 'w') do |file|
          file.write(rungs.inspect)
        end
      end
    end
    ladder_sort(rungs)
  end

  def ladder_update(avatar_name, latest_increment)
    rungs = []
    io_lock(folder) do
      if File.exists?(money_ladder_filename)
        rungs = eval IO.read(money_ladder_filename)
      end
      ladder_rung_update(rungs, avatar_name, latest_increment)
      File.open(money_ladder_filename, 'w') do |file|
        file.write(rungs.inspect) 
      end
    end
    ladder_sort(rungs)
  end
 
private

  def rotation_filename
  	folder + '/' + 'rotation.rb'
  end

  def money_ladder_filename
    folder + '/' + 'ladder.rb'
  end  
  
  Root_folder = RAILS_ROOT + '/' + 'dojos'
    
  def ladder_rung_update(ladder, avatar, inc)
    ladder.delete_if { |rung| rung[:avatar] == avatar } 
    ladder << { :avatar => avatar, :time => inc[:time], :outcome => inc[:outcome] }
  end
  
  def ladder_sort(rungs)
  	rungs.sort! { |lhs,rhs| lhs[:avatar] <=> rhs[:avatar] }
  end
  
end

<commit_msg>dropped money prefix from ladder filename<commit_after>
require 'io_lock.rb'

class Dojo

  def self.names
    Dir.entries(Root_folder).select { |name| name != '.' and name != '..' }
  end

  def initialize(name)
    @name = name
  end

  def name
    @name
  end

  def avatars
    alive = []
    Avatar.names.each do |avatar_name|
      alive << Avatar.new(self, avatar_name) if File.exists?(folder + '/' + avatar_name)
    end
    alive
  end

  def folder
    Root_folder + '/' + name
  end

  def rotation(avatar_name)
  	options = {}
  	io_lock(folder) do
  		if File.exists?(rotation_filename)
  			options = eval IO.read(rotation_filename)
  		end

      mins_per_rotate = 5
      secs_per_rotate = mins_per_rotate * 60
      
      now = Time.now
    	due = now + secs_per_rotate
      options[:already_rotated] ||= []
      options[:prev_rotation_at] ||= [1966,11,23,0,0,0]      
      options[:next_rotation_at] ||= [due.year, due.month, due.day, due.hour, due.min, due.sec]

      already_rotated = options[:already_rotated].include?(avatar_name)
      refresh_period = 5 # from view_panel.html.erb :frequency
      very_recent_rotation = (now - Time.mktime(*options[:prev_rotation_at])).abs <= refresh_period
      due = Time.mktime(*options[:next_rotation_at])
      
      if now > due
      	# first avatar over the now-line
      	# but don't rotate if we're re-entering a dojo after a long break
        options[:do_now] = (now - due < (2 * refresh_period))
        options[:prev_rotation_at] = [now.year, now.month, now.day, now.hour, now.min, now.sec]
        due = now + secs_per_rotate
        options[:next_rotation_at] = [due.year, due.month, due.day, due.hour, due.min, due.sec]
        options[:already_rotated] = [avatar_name]
      elsif !already_rotated && very_recent_rotation
     		# another avatar over the line
     		# but don't re-rotate for the first avatar again
     	  options[:do_now] = true
     		options[:already_rotated] << avatar_name	
      else
      	options[:do_now] = false
      end

      File.open(rotation_filename, 'w') do |file|
        file.write(options.inspect) 
      end        		
  	end
  	options
  end
  
  def ladder
    rungs = []
    io_lock(folder) do
      if File.exists?(ladder_filename)
        rungs = eval IO.read(ladder_filename)
      else
        File.open(ladder_filename, 'w') do |file|
          file.write(rungs.inspect)
        end
      end
    end
    ladder_sort(rungs)
  end

  def ladder_update(avatar_name, latest_increment)
    rungs = []
    io_lock(folder) do
      if File.exists?(ladder_filename)
        rungs = eval IO.read(ladder_filename)
      end
      ladder_rung_update(rungs, avatar_name, latest_increment)
      File.open(ladder_filename, 'w') do |file|
        file.write(rungs.inspect) 
      end
    end
    ladder_sort(rungs)
  end
 
private

  def rotation_filename
  	folder + '/' + 'rotation.rb'
  end

  def ladder_filename
    folder + '/' + 'ladder.rb'
  end  
  
  Root_folder = RAILS_ROOT + '/' + 'dojos'
    
  def ladder_rung_update(ladder, avatar, inc)
    ladder.delete_if { |rung| rung[:avatar] == avatar } 
    ladder << { :avatar => avatar, :time => inc[:time], :outcome => inc[:outcome] }
  end
  
  def ladder_sort(rungs)
  	rungs.sort! { |lhs,rhs| lhs[:avatar] <=> rhs[:avatar] }
  end
  
end


{'fraction_non_alphanumeric': 0.11571986774872257, 'fraction_numerical': 0.004809137360985873, 'mean_word_length': 2.597297297297297, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, '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': '65945', 'n_tokens_mistral': 2424, 'n_tokens_neox': 2346, 'n_words': 497}