<commit_before># coding: utf-8

class TypeController < ApplicationController
  def compete
    @page_scripts = ['type/compete', 'type']
  end
  
  respond_to :json
  def find_room
    room_id = REDIS.srandmember 'rooms:open'
    room_copy = nil
    
    if room_id.nil?
      room_id = Time.now.to_i
      REDIS.sadd 'rooms:open', room_id
      
      room_copy = Copy.find :first, :order => 'random()'
      REDIS.set "rooms:id:#{room_id}:copy", room_copy.id
    else
      room_copy = Copy.find REDIS.get("rooms:id:#{room_id}:copy")
    end
    
    # add the user to the retrieved room
    REDIS.hset "rooms:id:#{room_id}", current_user.id, current_user.email + ":0:0"
    
    render :json => {
      'id' => room_id,
      'copy' => [room_copy.content, room_copy.note],
      'players' => get_players(room_id)
    }
  end
  
  respond_to :json
  def room_status
    room_id = params[:id]
    render :json => {'id' => room_id, 'players' => get_players(room_id)}
  end
  
  respond_to :json
  def update_player_status
    data_str = [params[:name], params[:wpm], params[:cpm], params[:done]].join ':'
    REDIS.hset "rooms:id:#{params[:room_id]}", params[:player_id], data_str
    
    render :json => {'id' => room_id, 'players' => get_players(room_id)}
  end
  
  def practice
    @page_scripts = ['type/practice', 'type']
  end
  
  respond_to :json
  def copy
    # TODO: dynamically generate some unique copy
    # scrape old books or something? :P
    copy = Copy.find :first, :order => 'random()'
    respond_with copy
  end
  
  respond_to :json
  def submit
    @record = Record.create :duration => params[:duration], :words => params[:words], :wpm => params[:wpm], :cpm => params[:cpm]
    @record.user = current_user
    @record.profile_id = current_user.default_profile_id
    @record.save
    
    render :json => ( @record ? true : false )
  end
  
  def record_url something
    ""
  end
  
  private
  def get_players room_id
    REDIS.hgetall('rooms:id:' + room_id).map do |player_id, player_data_str|
      player_data = player_data_str.split ':'
      {'name' => player_data[0], 'wpm' => player_data[1], 'cpm' => player_data[2], 'done' => player_data[3]}
    end
  end
end
<commit_msg>include `done` value in user status string<commit_after># coding: utf-8

class TypeController < ApplicationController
  def compete
    @page_scripts = ['type/compete', 'type']
  end
  
  respond_to :json
  def find_room
    room_id = REDIS.srandmember 'rooms:open'
    room_copy = nil
    
    if room_id.nil?
      room_id = Time.now.to_i
      REDIS.sadd 'rooms:open', room_id
      
      room_copy = Copy.find :first, :order => 'random()'
      REDIS.set "rooms:id:#{room_id}:copy", room_copy.id
    else
      room_copy = Copy.find REDIS.get("rooms:id:#{room_id}:copy")
    end
    
    # add the user to the retrieved room
    REDIS.hset "rooms:id:#{room_id}", current_user.id, current_user.email + ":0:0:false"
    
    render :json => {
      'id' => room_id,
      'copy' => [room_copy.content, room_copy.note],
      'players' => get_players(room_id)
    }
  end
  
  respond_to :json
  def room_status
    room_id = params[:id]
    render :json => {'id' => room_id, 'players' => get_players(room_id)}
  end
  
  respond_to :json
  def update_player_status
    data_str = [params[:name], params[:wpm], params[:cpm], params[:done]].join ':'
    REDIS.hset "rooms:id:#{params[:room_id]}", params[:player_id], data_str
    
    render :json => {'id' => room_id, 'players' => get_players(room_id)}
  end
  
  def practice
    @page_scripts = ['type/practice', 'type']
  end
  
  respond_to :json
  def copy
    # TODO: dynamically generate some unique copy
    # scrape old books or something? :P
    copy = Copy.find :first, :order => 'random()'
    respond_with copy
  end
  
  respond_to :json
  def submit
    @record = Record.create :duration => params[:duration], :words => params[:words], :wpm => params[:wpm], :cpm => params[:cpm]
    @record.user = current_user
    @record.profile_id = current_user.default_profile_id
    @record.save
    
    render :json => ( @record ? true : false )
  end
  
  def record_url something
    ""
  end
  
  private
  def get_players room_id
    REDIS.hgetall('rooms:id:' + room_id).map do |player_id, player_data_str|
      player_data = player_data_str.split ':'
      {'name' => player_data[0], 'wpm' => player_data[1], 'cpm' => player_data[2], 'done' => player_data[3]}
    end
  end
end

{'fraction_non_alphanumeric': 0.1409305461901551, 'fraction_numerical': 0.003146774556080018, 'mean_word_length': 3.147250698974837, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 45, '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': '107856', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1584, 'n_words': 360}