<commit_before>module UserDecorator
  IMAGE_PX_BY_SIZE = { small: 64, medium: 192, large: 384 }

  def display_name
    logged_in? ? name_with_handle : handle
  end

  def inst_to_count
    playings.published.count_insts
  end

  def instruments
    inst_to_count.to_h.keys
  end

  def avatar_url(size)
    px = IMAGE_PX_BY_SIZE[size]
    if avatar.attached?
      url_for avatar.variant(resize: "#{px}x#{px}")
    elsif email.present? && activated?
      hash = Digest::MD5.hexdigest(email)
      "https://www.gravatar.com/avatar/#{hash}?s=#{px}&d=mm"
    else
      "https://www.gravatar.com/avatar/?s=#{px}&d=mm&f=t"
    end
  end

  def avatar_image_tag(size = :small, options = {})
    options[:class] = options[:class].nil? ? "rounded-circle #{size}" : options[:class] + " rounded-circle #{size}"
    image_tag avatar_url(size), options
  end

  def related_playings
    Playing.where(song_id: songs.published.pluck('songs.id'))
  end

  def collaborator_to_count
    related_playings.where.not(user_id: id).group(:user_id).order(count: :desc).count
  end

  def collaborators
    User.where(id: collaborator_to_count.to_h.keys.take(10)).with_attached_avatar
  end

  def delete_link(html_options)
    link_to_delete self, html_options.merge(data: { confirm: t('views.application.delete_confirm') })
  end

  def invite_link(html_options)
    link_to icon('fas', 'envelope') + ' ' + t('views.users.invite'), new_user_activation_path(self), html_options<commit_msg>Make center cropping avatar<commit_after>module UserDecorator
  IMAGE_PX_BY_SIZE = { small: 64, medium: 192, large: 384 }

  def display_name
    logged_in? ? name_with_handle : handle
  end

  def inst_to_count
    playings.published.count_insts
  end

  def instruments
    inst_to_count.to_h.keys
  end

  def avatar_url(size)
    px = IMAGE_PX_BY_SIZE[size]
    if avatar.attached?
      url_for avatar.variant(resize: "#{px}x#{px}^", gravity: 'center', crop: "#{px}x#{px}+0+0")
    elsif email.present? && activated?
      hash = Digest::MD5.hexdigest(email)
      "https://www.gravatar.com/avatar/#{hash}?s=#{px}&d=mm"
    else
      "https://www.gravatar.com/avatar/?s=#{px}&d=mm&f=t"
    end
  end

  def avatar_image_tag(size = :small, options = {})
    options[:class] = options[:class].nil? ? "rounded-circle #{size}" : options[:class] + " rounded-circle #{size}"
    image_tag avatar_url(size), options
  end

  def related_playings
    Playing.where(song_id: songs.published.pluck('songs.id'))
  end

  def collaborator_to_count
    related_playings.where.not(user_id: id).group(:user_id).order(count: :desc).count
  end

  def collaborators
    User.where(id: collaborator_to_count.to_h.keys.take(10)).with_attached_avatar
  end

  def delete_link(html_options)
    link_to_delete self, html_options.merge(data: { confirm: t('views.application.delete_confirm') })
  end

  def invite_link(html_options)
    link_to icon('fas', 'envelope') + ' ' + t('views.users.invite'), new_user_activation_path(self), html_options
{'fraction_non_alphanumeric': 0.137620793068977, 'fraction_numerical': 0.007997334221926024, 'mean_word_length': 4.175862068965517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '7535202', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1072, 'n_words': 184}