From 66aafa6fcb656c7fcfc43989b826b3891fda2562 Mon Sep 17 00:00:00 2001 From: Rabbit Date: Mon, 2 Dec 2024 19:17:58 +0800 Subject: [PATCH] Issue 797 (#2302) * chore: update dalli client TTL conf * feat: add knowledge size to daily statistics --- app/models/daily_statistic.rb | 9 ++++++++- app/serializers/daily_statistic_serializer.rb | 4 ++++ app/services/charts/daily_statistic_generator.rb | 2 +- ...41202072604_add_knowledge_size_to_daily_statistics.rb | 5 +++++ db/structure.sql | 7 +++++-- test/services/charts/daily_statistic_generator_test.rb | 8 ++++++++ 6 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20241202072604_add_knowledge_size_to_daily_statistics.rb diff --git a/app/models/daily_statistic.rb b/app/models/daily_statistic.rb index a94bc644c..ff2d11f17 100644 --- a/app/models/daily_statistic.rb +++ b/app/models/daily_statistic.rb @@ -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 @@ -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 @@ -568,6 +574,7 @@ def aggron_first_day? # locked_capacity :decimal(30, ) # ckb_hodl_wave :jsonb # holder_count :integer +# knowledge_size :decimal(30, ) # # Indexes # diff --git a/app/serializers/daily_statistic_serializer.rb b/app/serializers/daily_statistic_serializer.rb index 7baa598a5..dbd75c091 100644 --- a/app/serializers/daily_statistic_serializer.rb +++ b/app/serializers/daily_statistic_serializer.rb @@ -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 diff --git a/app/services/charts/daily_statistic_generator.rb b/app/services/charts/daily_statistic_generator.rb index 29a9544ef..0d68f26e0 100644 --- a/app/services/charts/daily_statistic_generator.rb +++ b/app/services/charts/daily_statistic_generator.rb @@ -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 diff --git a/db/migrate/20241202072604_add_knowledge_size_to_daily_statistics.rb b/db/migrate/20241202072604_add_knowledge_size_to_daily_statistics.rb new file mode 100644 index 000000000..7ee48261a --- /dev/null +++ b/db/migrate/20241202072604_add_knowledge_size_to_daily_statistics.rb @@ -0,0 +1,5 @@ +class AddKnowledgeSizeToDailyStatistics < ActiveRecord::Migration[7.0] + def change + add_column :daily_statistics, :knowledge_size, :decimal, precision: 30 + end +end diff --git a/db/structure.sql b/db/structure.sql index b0ee52b1a..b37f2e718 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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) ); @@ -5945,4 +5946,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20240823071323'), ('20240823071420'), ('20240902025657'), -('20240904043807'); +('20240904043807'), +('20241202072604'); + diff --git a/test/services/charts/daily_statistic_generator_test.rb b/test/services/charts/daily_statistic_generator_test.rb index b876f8362..13b04281e 100644 --- a/test/services/charts/daily_statistic_generator_test.rb +++ b/test/services/charts/daily_statistic_generator_test.rb @@ -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] }