<commit_before># frozen_string_literal: true

module Admin::DashboardHelper
  def relevant_account_ip(account, ip_query)
    ips = account.user.ips.to_a

    matched_ip = begin
      ip_query_addr = IPAddr.new(ip_query)
      ips.find { |ip| ip_query_addr.include?(ip.ip) } || ips.first
    rescue IPAddr::Error
      ips.first
    end

    if matched_ip
      link_to matched_ip.ip, admin_accounts_path(ip: matched_ip.ip)
    else
      '-'
    end
  end

  def relevant_account_timestamp(account)
    timestamp, exact = begin
      if account.user_current_sign_in_at && account.user_current_sign_in_at < 24.hours.ago
        [account.user_current_sign_in_at, true]
      elsif account.user_current_sign_in_at
        [account.user_current_sign_in_at, false]
      elsif account.user_pending?
        [account.user_created_at, true]
      elsif account.last_status_at.present?
        [account.last_status_at, true]
      else
        [nil, false]
      end
    end

    return '-' if timestamp.nil?<commit_msg>Fix admin interface crash when displaying deleted user (#17301)<commit_after># frozen_string_literal: true

module Admin::DashboardHelper
  def relevant_account_ip(account, ip_query)
    ips = account.user.present? ? account.user.ips.to_a : []

    matched_ip = begin
      ip_query_addr = IPAddr.new(ip_query)
      ips.find { |ip| ip_query_addr.include?(ip.ip) } || ips.first
    rescue IPAddr::Error
      ips.first
    end

    if matched_ip
      link_to matched_ip.ip, admin_accounts_path(ip: matched_ip.ip)
    else
      '-'
    end
  end

  def relevant_account_timestamp(account)
    timestamp, exact = begin
      if account.user_current_sign_in_at && account.user_current_sign_in_at < 24.hours.ago
        [account.user_current_sign_in_at, true]
      elsif account.user_current_sign_in_at
        [account.user_current_sign_in_at, false]
      elsif account.user_pending?
        [account.user_created_at, true]
      elsif account.last_status_at.present?
        [account.last_status_at, true]
      else
        [nil, false]
      end
    end

    return '-' if timestamp.nil?
{'fraction_non_alphanumeric': 0.08559201141226819, 'fraction_numerical': 0.0042796005706134095, 'mean_word_length': 3.0076190476190474, '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': '6185260', 'n_tokens_mistral': 716, 'n_tokens_neox': 699, 'n_words': 132}