Skip to content

Commit

Permalink
feat: add knowledge size to daily statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Dec 2, 2024
1 parent 3b8e37b commit de6f7d4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/models/daily_statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DailyStatistic < ApplicationRecord
transactions_count addresses_count total_dao_deposit live_cells_count dead_cells_count avg_hash_rate avg_difficulty uncle_rate
total_depositors_count address_balance_distribution total_tx_fee occupied_capacity daily_dao_deposit daily_dao_depositors_count
circulation_ratio daily_dao_withdraw nodes_count circulating_supply burnt locked_capacity treasury_amount mining_reward
deposit_compensation liquidity created_at_unixtimestamp ckb_hodl_wave holder_count
deposit_compensation liquidity created_at_unixtimestamp ckb_hodl_wave holder_count knowledge_size
).freeze
MILLISECONDS_IN_DAY = BigDecimal(24 * 60 * 60 * 1000)
GENESIS_TIMESTAMP = 1573852190812
Expand Down Expand Up @@ -239,6 +239,12 @@ def liquidity
tip_parse_dao.c_i - MarketData::BURN_QUOTA - treasury_amount.to_i
end

define_logic :knowledge_size do
tip_dao = current_tip_block.dao
tip_parse_dao = CkbUtils.parse_dao(tip_dao)
tip_parse_dao.u_i - MarketData::BURN_QUOTA * 0.6
end

define_logic :circulating_supply do
MarketData.new(indicator: "circulating_supply", tip_block_number: current_tip_block.number,
unit: "shannon").call
Expand Down Expand Up @@ -568,6 +574,7 @@ def aggron_first_day?
# locked_capacity :decimal(30, )
# ckb_hodl_wave :jsonb
# holder_count :integer
# knowledge_size :decimal(30, )
#
# Indexes
#
Expand Down
4 changes: 4 additions & 0 deletions app/serializers/daily_statistic_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ class DailyStatisticSerializer
} do |object|
object.holder_count.to_s
end

attribute :knowledge_size, if: Proc.new { |_record, params|
params.present? && params[:indicator].include?("knowledge_size")
}
end
2 changes: 1 addition & 1 deletion app/services/charts/daily_statistic_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def updated_attrs
}
others = %i{
block_timestamp transactions_count addresses_count daily_dao_withdraw
average_deposit_time mining_reward
average_deposit_time mining_reward knowledge_size
treasury_amount estimated_apc live_cells_count dead_cells_count avg_hash_rate
avg_difficulty uncle_rate address_balance_distribution
total_tx_fee occupied_capacity daily_dao_deposit total_supply block_time_distribution
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddKnowledgeSizeToDailyStatistics < ActiveRecord::Migration[7.0]
def change
add_column :daily_statistics, :knowledge_size, :decimal, precision: 30
end
end
7 changes: 5 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,8 @@ CREATE TABLE public.daily_statistics (
nodes_count integer,
locked_capacity numeric(30,0),
ckb_hodl_wave jsonb,
holder_count integer
holder_count integer,
knowledge_size numeric(30,0)
);


Expand Down Expand Up @@ -5945,4 +5946,6 @@ INSERT INTO "schema_migrations" (version) VALUES
('20240823071323'),
('20240823071420'),
('20240902025657'),
('20240904043807');
('20240904043807'),
('20241202072604');

8 changes: 8 additions & 0 deletions test/services/charts/daily_statistic_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ class DailyStatisticGeneratorTest < ActiveSupport::TestCase
assert_equal total_supply_temp, total_supply
end

test "it should get knowledge_size" do
tip_dao = @current_tip_block.dao
tip_parse_dao = CkbUtils.parse_dao(tip_dao)
knowledge_size_temp = tip_parse_dao.u_i - MarketData::BURN_QUOTA * 0.6
knowledge_size = Charts::DailyStatisticGenerator.new(@datetime).call.knowledge_size
assert_equal knowledge_size_temp, knowledge_size
end

test "it should get epoch_length_distribution" do
max_n = 1700
ranges = (700..max_n).step(100).map { |n| [n, n + 100] }
Expand Down

0 comments on commit de6f7d4

Please sign in to comment.