<commit_before>module ChelshiaRocks
  class User
    include NoBrainer::Document

    # Steam ID for this user
    field :steam_id, type: String

    # Name of this user
    field :name, type: String

    # URL to this user's avatar
    field :avatar_url, type: String

    # Time this user was created
    field :created_at, type: Time

    # This user's game-wide score
    field :score, type: Integer, default: 0

    has_many :entrys
    has_many :leaderboards, through: :entrys

    # URL to this user's steam profile
    def profile_url
      "#{Steam::API::BASE_URL}/profiles/#{steam_id}"
    end

    # Fetches a user object from the database. If it isn't found,
    # a request will be made to cache it from Steam unless
    # `request` is `false`.
    # @param steam_id [String, #to_s] steam ID
    # @param request [true, false] whether to fetch this user from the API if it doesn't exist
    def self.user(steam_id, request: true)
      user = where(steam_id: steam_id.to_s).first
      return user if user
      return unless request

      from_hash Steam::API.user(steam_id)
    end

    # Creates a new User from a Steam API user hash
    def self.from_hash(data)
      create(
        steam_id: data[:steamid64],
        name: data[:steamid],
        avatar_url: data[:avatarfull],
        created_at: Time.now
      )
    end
  end
end
<commit_msg>add a method to calculate a users total score<commit_after>require_relative './score'

module ChelshiaRocks
  class User
    include NoBrainer::Document

    # Steam ID for this user
    field :steam_id, type: String

    # Name of this user
    field :name, type: String

    # URL to this user's avatar
    field :avatar_url, type: String

    # Time this user was created
    field :created_at, type: Time

    # This user's game-wide score
    field :score, type: Integer, default: 0

    has_many :entrys
    has_many :leaderboards, through: :entrys

    # URL to this user's steam profile
    def profile_url
      "#{Steam::API::BASE_URL}/profiles/#{steam_id}"
    end

    # Update this user's score
    def update_score!
      value = leaderboards.map do |l|
        Score.value l.user(self.steam_id)&.rank || 0
      end.reduce(:+)

      update(score: value)

      value
    end

    # Fetches a user object from the database. If it isn't found,
    # a request will be made to cache it from Steam unless
    # `request` is `false`.
    # @param steam_id [String, #to_s] steam ID
    # @param request [true, false] whether to fetch this user from the API if it doesn't exist
    def self.user(steam_id, request: true)
      user = where(steam_id: steam_id.to_s).first
      return user if user
      return unless request

      from_hash Steam::API.user(steam_id)
    end

    # Creates a new User from a Steam API user hash
    def self.from_hash(data)
      create(
        steam_id: data[:steamid64],
        name: data[:steamid],
        avatar_url: data[:avatarfull],
        created_at: Time.now
      )
    end
  end
end

{'fraction_non_alphanumeric': 0.08446957100099767, 'fraction_numerical': 0.002327901563019621, 'mean_word_length': 2.6153846153846154, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5070459', 'n_tokens_mistral': 977, 'n_tokens_neox': 934, 'n_words': 338}