Skip to content

Commit

Permalink
feat: skip the first 4 epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Dec 9, 2019
1 parent 8d86dc3 commit 3ccffaf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/block_statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class BlockStatisticsController < ApplicationController
before_action :validate_query_params

def show
block_statistics = BlockStatistic.order(id: :desc).reverse
block_statistics = BlockStatistic.where("epoch_number > 2").order(id: :desc).reverse
render json: BlockStatisticSerializer.new(block_statistics, { params: { indicator: params[:id] } })
end

Expand Down
1 change: 1 addition & 0 deletions app/models/block_statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BlockStatistic < ApplicationRecord
# block_number :decimal(30, )
# created_at :datetime not null
# updated_at :datetime not null
# epoch_number :decimal(30, )
#
# Indexes
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEpochNumberToBlockStatistics < ActiveRecord::Migration[6.0]
def change
add_column :block_statistics, :epoch_number, :decimal, precision: 30, scale: 0
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_12_08_071607) do
ActiveRecord::Schema.define(version: 2019_12_09_054145) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -48,6 +48,7 @@
t.decimal "block_number", precision: 30
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.decimal "epoch_number", precision: 30
t.index ["block_number"], name: "index_block_statistics_on_block_number", unique: true
end

Expand Down
5 changes: 3 additions & 2 deletions lib/tasks/migration/generate_block_statistic_data.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace :migration do
task generate_block_statistic_data: :environment do
max_block_number = Block.maximum(:number)
range = (0..max_block_number).step(100)
start_block_number = [BlockStatistic.maximum(:block_number).to_i + 100, 100].max
range = (start_block_number..max_block_number).step(100)
progress_bar = ProgressBar.create({
total: range.count,
format: "%e %B %p%% %c/%C"
Expand All @@ -15,7 +16,7 @@ namespace :migration do
dead_cells_count = total_cells.where(consumed_by_id: ckb_transaction_ids).count
live_cells_count = total_cells.count - dead_cells_count

BlockStatistic.create(block_number: block.number, difficulty: block.difficulty, hash_rate: hash_rate, live_cells_count: live_cells_count, dead_cells_count: live_cells_count)
BlockStatistic.create(block_number: block.number, epoch_number: block.epoch, difficulty: block.difficulty, hash_rate: hash_rate, live_cells_count: live_cells_count, dead_cells_count: live_cells_count)
progress_bar.increment
end

Expand Down

0 comments on commit 3ccffaf

Please sign in to comment.