Skip to content

Commit

Permalink
chore: update date range for rgbpp assets statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Dec 19, 2024
1 parent db4ea0c commit 8def4fd
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions app/workers/generate_rgbpp_assets_statistic_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ class GenerateRgbppAssetsStatisticWorker
include Sidekiq::Job
sidekiq_options queue: "rgbpp"

def perform
attr_accessor :datetime

def perform(datetime = nil)
@datetime = datetime
statistic_attributes = [
ft_count_attributes,
dob_count_attributes,
Expand All @@ -11,9 +14,6 @@ def perform
btc_holders_count_attributes,
ckb_holders_count_attributes,
]

puts "===="
puts statistic_attributes
statistic_attributes.each { _1[:created_at_unixtimestamp] = started_at.to_i }
RgbppAssetsStatistic.upsert_all(statistic_attributes, unique_by: %i[indicator network created_at_unixtimestamp])
rescue StandardError => e
Expand All @@ -23,12 +23,13 @@ def perform
private

def ft_count_attributes
xudts_count = Udt.published_xudt.joins(:xudt_tag).where("xudt_tags.tags && ARRAY[?]::varchar[]", ["rgb++"]).count
xudts_count = Udt.published_xudt.where(created_at: ..ended_at).count
{ indicator: "ft_count", value: xudts_count, network: "global" }
end

def dob_count_attributes
token_collections_count = TokenCollection.where("tags && ARRAY[?]::varchar[]", ["rgb++"]).count
token_collections_count = TokenCollection.where("tags && ARRAY[?]::varchar[]", ["rgb++"]).
where(created_at: ..ended_at).count
{ indicator: "dob_count", value: token_collections_count, network: "global" }
end

Expand All @@ -49,18 +50,24 @@ def btc_holders_count_attributes
udt_types = %i[xudt xudt_compatible spore_cell did_cell]
udt_ids = Udt.where(udt_type: udt_types, published: true).ids
address_ids = UdtAccount.where(udt_id: udt_ids).where("amount > 0").pluck(:address_id).uniq
holders_count = BitcoinAddressMapping.where(ckb_address_id: address_ids).distinct.count(:bitcoin_address_id)
holders_count = BitcoinAddressMapping.where(ckb_address_id: address_ids, created_at: ..ended_at).
distinct.count(:bitcoin_address_id)
{ indicator: "holders_count", value: holders_count, network: "btc" }
end

def ckb_holders_count_attributes
udt_types = %i[xudt xudt_compatible spore_cell did_cell]
udt_ids = Udt.where(udt_type: udt_types, published: true).ids
holders_count = UdtAccount.where(udt_id: udt_ids).where("amount > 0").distinct.count(:address_id)
holders_count = UdtAccount.where(udt_id: udt_ids, created_at: ..ended_at).
where("amount > 0").distinct.count(:address_id)
{ indicator: "holders_count", value: holders_count, network: "ckb" }
end

def to_be_counted_date
if @datetime.present?
return Time.zone.parse(@datetime)
end

last_record = UdtHourlyStatistic.order(created_at_unixtimestamp: :desc).first
if last_record
Time.zone.at(last_record.created_at_unixtimestamp) + 1.day
Expand Down

0 comments on commit 8def4fd

Please sign in to comment.