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 74f59fd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/models/daily_statistic.rb
Original file line number Diff line number Diff line change
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
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 74f59fd

Please sign in to comment.