@@ -5,7 +5,7 @@ class DailyStatistic < ApplicationRecord
55 transactions_count addresses_count total_dao_deposit live_cells_count dead_cells_count avg_hash_rate avg_difficulty uncle_rate
66 total_depositors_count address_balance_distribution total_tx_fee occupied_capacity daily_dao_deposit daily_dao_depositors_count
77 circulation_ratio daily_dao_withdraw nodes_count circulating_supply burnt locked_capacity treasury_amount mining_reward
8- deposit_compensation liquidity created_at_unixtimestamp ckb_hodl_wave holder_count knowledge_size
8+ deposit_compensation liquidity created_at_unixtimestamp ckb_hodl_wave holder_count knowledge_size activity_address_contract_distribution
99 ) . freeze
1010 MILLISECONDS_IN_DAY = BigDecimal ( 24 * 60 * 60 * 1000 )
1111 GENESIS_TIMESTAMP = 1573852190812
@@ -409,8 +409,26 @@ def liquidity
409409 dead_query = CellOutput . dead . generated_before ( to_be_counted_date . to_i * 1000 - 1 ) . consumed_after ( to_be_counted_date . to_i * 1000 ) . select ( :address_id ) . to_sql
410410 combined_query = "#{ live_query } UNION #{ dead_query } "
411411 count_query = "SELECT COUNT(DISTINCT address_id) AS count FROM (#{ combined_query } ) AS combined_results;"
412- count = ActiveRecord ::Base . connection . execute ( count_query ) . first [ "count" ]
413- count
412+ ActiveRecord ::Base . connection . execute ( count_query ) . first [ "count" ]
413+ end
414+
415+ define_logic :activity_address_contract_distribution do
416+ block_ids = blocks_in_current_period . pluck ( :id )
417+ uniq_address_ids = CellOutput . established_status . where ( block_id : block_ids ) . select ( :address_id ) . distinct . map { |cell_output | cell_output . address_id }
418+ results = Address . joins ( :lock_script ) . where ( id : uniq_address_ids ) . group ( :code_hash ) . count
419+ parsed_results =
420+ results . each_with_object ( { } ) do |( key , value ) , hash |
421+ hex_key = "0x#{ key . unpack1 ( 'H*' ) } "
422+ hash [ hex_key ] = value
423+ end . sort_by { |_k , v | -v }
424+ data =
425+ parsed_results . map do |result |
426+ { Contract . where ( is_lock_script : true ) . where . not ( name : nil ) . where ( "type_hash = ? OR data_hash = ?" , result [ 0 ] , result [ 0 ] ) . first &.name => result [ 1 ] }
427+ end
428+ nil_sum = data . select { |item | item . keys . include? ( nil ) } . sum { |item | item [ nil ] }
429+ filtered_data = data . reject { |item | item . keys . include? ( nil ) }
430+ filtered_data << { "Others" => nil_sum } if nil_sum > 0
431+ filtered_data
414432 end
415433
416434 private
@@ -534,47 +552,48 @@ def aggron_first_day?
534552#
535553# Table name: daily_statistics
536554#
537- # id :bigint not null, primary key
538- # transactions_count :string default("0")
539- # addresses_count :string default("0")
540- # total_dao_deposit :string default("0.0")
541- # block_timestamp :decimal(30, )
542- # created_at_unixtimestamp :integer
543- # created_at :datetime not null
544- # updated_at :datetime not null
545- # dao_depositors_count :string default("0")
546- # unclaimed_compensation :string default("0")
547- # claimed_compensation :string default("0")
548- # average_deposit_time :string default("0")
549- # estimated_apc :string default("0")
550- # mining_reward :string default("0")
551- # deposit_compensation :string default("0")
552- # treasury_amount :string default("0")
553- # live_cells_count :string default("0")
554- # dead_cells_count :string default("0")
555- # avg_hash_rate :string default("0")
556- # avg_difficulty :string default("0")
557- # uncle_rate :string default("0")
558- # total_depositors_count :string default("0")
559- # total_tx_fee :decimal(30, )
560- # address_balance_distribution :jsonb
561- # occupied_capacity :decimal(30, )
562- # daily_dao_deposit :decimal(30, )
563- # daily_dao_depositors_count :integer
564- # daily_dao_withdraw :decimal(30, )
565- # circulation_ratio :decimal(, )
566- # total_supply :decimal(30, )
567- # circulating_supply :decimal(, )
568- # block_time_distribution :jsonb
569- # epoch_time_distribution :jsonb
570- # epoch_length_distribution :jsonb
571- # average_block_time :jsonb
572- # nodes_distribution :jsonb
573- # nodes_count :integer
574- # locked_capacity :decimal(30, )
575- # ckb_hodl_wave :jsonb
576- # holder_count :integer
577- # knowledge_size :decimal(30, )
555+ # id :bigint not null, primary key
556+ # transactions_count :string default("0")
557+ # addresses_count :string default("0")
558+ # total_dao_deposit :string default("0.0")
559+ # block_timestamp :decimal(30, )
560+ # created_at_unixtimestamp :integer
561+ # created_at :datetime not null
562+ # updated_at :datetime not null
563+ # dao_depositors_count :string default("0")
564+ # unclaimed_compensation :string default("0")
565+ # claimed_compensation :string default("0")
566+ # average_deposit_time :string default("0")
567+ # estimated_apc :string default("0")
568+ # mining_reward :string default("0")
569+ # deposit_compensation :string default("0")
570+ # treasury_amount :string default("0")
571+ # live_cells_count :string default("0")
572+ # dead_cells_count :string default("0")
573+ # avg_hash_rate :string default("0")
574+ # avg_difficulty :string default("0")
575+ # uncle_rate :string default("0")
576+ # total_depositors_count :string default("0")
577+ # total_tx_fee :decimal(30, )
578+ # address_balance_distribution :jsonb
579+ # occupied_capacity :decimal(30, )
580+ # daily_dao_deposit :decimal(30, )
581+ # daily_dao_depositors_count :integer
582+ # daily_dao_withdraw :decimal(30, )
583+ # circulation_ratio :decimal(, )
584+ # total_supply :decimal(30, )
585+ # circulating_supply :decimal(, )
586+ # block_time_distribution :jsonb
587+ # epoch_time_distribution :jsonb
588+ # epoch_length_distribution :jsonb
589+ # average_block_time :jsonb
590+ # nodes_distribution :jsonb
591+ # nodes_count :integer
592+ # locked_capacity :decimal(30, )
593+ # ckb_hodl_wave :jsonb
594+ # holder_count :integer
595+ # knowledge_size :decimal(30, )
596+ # activity_address_contract_distribution :jsonb
578597#
579598# Indexes
580599#
0 commit comments