<commit_before>require 'elo'

class PongController < ActionController::Base
  layout 'application'

  def feed
  end

  def leaderboard
    if params[:club] == nil
      redirect_to '/clubs'
    end
  end

  def about
  end

  def clubs
    @clubs = Club.all.map do |club|
      {
        name: club.name,
        country: club.country.downcase,
        resource_name: club.name.downcase.gsub(/ /, '-'),
        player_count: Club.members_in_club(club.id)
      }
    end

    @clubs.sort_by! do |item| item[:player_count] end
    @clubs.reverse!
  end

  def feeddata
    if params[:club] == nil
      redirect_to '/clubs'
    else
      render json: Match.all.to_json
    end
  end

  def leaderboarddata
    players = {}

    if params[:club] == nil
      redirect_to '/clubs'
    else
      formatted_club_name = format_club_name params[:club]
      matches = Match.joins(:club).where('lower(clubs.name) = ?', 'pivotal denver').order(created_at: 'desc')

      matches.each do |match|
          winner = match['winner']
          loser = match['loser']

        if (!players.has_key? winner)
          players[winner] = Elo::Player.new
        end

        if (!players.has_key? loser)
          players[loser] = Elo::Player.new
        end

        players[winner].wins_from(players[loser])
      end
    end

    sorted_players = players.sort_by { |name, player| player.rating}.reverse!

    render json: sorted_players.map { |arr| {name: arr[0], rating: arr[1].rating}}
  end

  def format_club_name(club_name)
    formatted_club_name = club_name.gsub(/[ \.\/]/, '-').gsub(/[-]+/, '-').downcase
    formatted_club_name[0...-1] if formatted_club_name[-1, 1] == '-' # Remove last character if -
  end
end<commit_msg>Fixes issue #21 - leaderboard and feed relevant to correct club<commit_after>require 'elo'

class PongController < ActionController::Base
  layout 'application'

  def feed
  end

  def leaderboard
    if params[:club] == nil
      redirect_to '/clubs'
    end
  end

  def about
  end

  def clubs
    @clubs = Club.all.map do |club|
      {
        name: club.name,
        country: club.country.downcase,
        resource_name: club.name.downcase.gsub(/ /, '-'),
        player_count: Club.members_in_club(club.id)
      }
    end

    @clubs.sort_by! do |item| item[:player_count] end
    @clubs.reverse!
  end

  def feeddata
    if params[:club] == nil
      redirect_to '/clubs'
    else
      formatted_club_name = params[:club].gsub(/-/, ' ')
      render json: Match.joins(:club).where('lower(clubs.name) = ?', formatted_club_name).to_json
    end
  end

  def leaderboarddata
    players = {}

    if params[:club] == nil
      redirect_to '/clubs'
    else
      formatted_club_name = params[:club].gsub(/-/, ' ')
      matches = Match.joins(:club).where('lower(clubs.name) = ?', formatted_club_name).order(created_at: 'desc')

      matches.each do |match|
          winner = match['winner']
          loser = match['loser']

        if (!players.has_key? winner)
          players[winner] = Elo::Player.new
        end

        if (!players.has_key? loser)
          players[loser] = Elo::Player.new
        end

        players[winner].wins_from(players[loser])
      end
    end

    sorted_players = players.sort_by { |name, player| player.rating}.reverse!

    render json: sorted_players.map { |arr| {name: arr[0], rating: arr[1].rating}}
  end
end
{'fraction_non_alphanumeric': 0.13134592680047225, 'fraction_numerical': 0.0029515938606847697, 'mean_word_length': 2.490216271884655, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7639641', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1137, 'n_words': 246}