<commit_before>module BceExplorer
  # Guesstimated Wallet Storage
  #
  # ... uses address db storage
  # _id - address
  # wallet - wallet id
  class Wallet < Base
    def initialize(dbh)
      super dbh, 'address'
    end

    # merge addresses with wallets
    def merge!(addresses)
      return if addresses.empty? # nothing to do here

      update = { '$set' => { wallet: id(addresses) } }
      if addresses.is_a? Array
        addresses.each { |address| upsert({ _id: address }, update) }
      else
        upsert({ _id: addresses }, update)
      end
    end

    # fetches wallet info
    # returns top addresses with non-zero balance
    def fetch(wallet)
      query = { wallet: wallet, balance: { '$gt' => 1e-8 } }
      order = { balance: :desc }
      result = find_order_limit query, order, 50
      addresses = result.map { |doc| Entities::Address.create_from(doc) }
      params = { 'id' => wallet, 'name' => name(wallet),
                 'balance' => balance(wallet), 'size' => count(wallet),
                 'addresses' => addresses }
      Entities::Wallet.create_from params
    end

    # size of the wallet
    def count(wallet)
      super wallet: wallet
    end

    # returns the largest wallets
    def top(count = 20)
      aggregate([
        { '$group' => { _id: '$wallet', total: { '$sum' => '$balance' },
                        count: { '$sum' => 1 } } },
        { '$sort' => { total: -1 } },
        { '$limit' => count }
      ]).map do |doc|
        params = { 'id' => doc['_id'], 'name' => name(doc['_id']),
                   'balance' => doc['total'], 'size' => doc['count'] }
        Entities::Wallet.create_from params
      end
    end

    def id(address)
      query = address.is_a?(Array) ? { '$in' => address } : address
      doc = find query
      return new_id if doc.nil?
      return new_id if doc['wallet'].nil?
      doc['wallet']
    end
<commit_msg>increased limit of wallets on the top page<commit_after>module BceExplorer
  # Guesstimated Wallet Storage
  #
  # ... uses address db storage
  # _id - address
  # wallet - wallet id
  class Wallet < Base
    def initialize(dbh)
      super dbh, 'address'
    end

    # merge addresses with wallets
    def merge!(addresses)
      return if addresses.empty? # nothing to do here

      update = { '$set' => { wallet: id(addresses) } }
      if addresses.is_a? Array
        addresses.each { |address| upsert({ _id: address }, update) }
      else
        upsert({ _id: addresses }, update)
      end
    end

    # fetches wallet info
    # returns top addresses with non-zero balance
    def fetch(wallet)
      query = { wallet: wallet, balance: { '$gt' => 1e-8 } }
      order = { balance: :desc }
      result = find_order_limit query, order, 50
      addresses = result.map { |doc| Entities::Address.create_from(doc) }
      params = { 'id' => wallet, 'name' => name(wallet),
                 'balance' => balance(wallet), 'size' => count(wallet),
                 'addresses' => addresses }
      Entities::Wallet.create_from params
    end

    # size of the wallet
    def count(wallet)
      super wallet: wallet
    end

    # returns the largest wallets
    def top(count = 50)
      aggregate([
        { '$group' => { _id: '$wallet', total: { '$sum' => '$balance' },
                        count: { '$sum' => 1 } } },
        { '$sort' => { total: -1 } },
        { '$limit' => count }
      ]).map do |doc|
        params = { 'id' => doc['_id'], 'name' => name(doc['_id']),
                   'balance' => doc['total'], 'size' => doc['count'] }
        Entities::Wallet.create_from params
      end
    end

    def id(address)
      query = address.is_a?(Array) ? { '$in' => address } : address
      doc = find query
      return new_id if doc.nil?
      return new_id if doc['wallet'].nil?
      doc['wallet']
    end

{'fraction_non_alphanumeric': 0.14192877566935275, 'fraction_numerical': 0.004159085001299714, 'mean_word_length': 2.1284552845528455, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '3700624', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1181, 'n_words': 341}