Skip to content

Commit

Permalink
feat(server): add statistic info
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jun 3, 2019
1 parent 54dd71e commit a52459e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ INAUTHENTICSYNC_LOOP_INTERVAL="1"
TRANSACTION_UPDATER_LOOP_INTERVAL="30"
CODE_HASH="0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5"
INITIAL_BLOCK_REWARD="5_000_000_000_000"
STATISTICAL_INTERVAL="500"
3 changes: 2 additions & 1 deletion server/app/controllers/api/v1/statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module Api
module V1
class StatisticsController < ApplicationController
def index

statistic_info = StatisticInfo.new
render json: IndexStatisticSerializer.new(statistic_info)
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions server/app/models/statistic_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class StatisticInfo
def initialize(difficulty_interval: nil, block_time_interval: nil, statistical_interval: nil)
@difficulty_interval = difficulty_interval.presence || ENV["STATISTICAL_INTERVAL"]
@block_time_interval = block_time_interval.presence || ENV["STATISTICAL_INTERVAL"]
@statistical_interval = statistical_interval.presence || ENV["STATISTICAL_INTERVAL"]
end

def id
Time.current.to_i
end

def tip_block_number

end

def average_difficulty

end

def average_block_time

end

def hash_rate

end

private

attr_reader :difficulty_interval, :block_time_interval, :statistical_interval
end
5 changes: 5 additions & 0 deletions server/app/serializers/index_statistic_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class IndexStatisticSerializer
include FastJsonapi::ObjectSerializer

attributes :tip_block_number, :average_block_time, :average_difficulty, :hash_rate
end

0 comments on commit a52459e

Please sign in to comment.