Skip to content

Commit

Permalink
feat: add epoch_time_distribution
Browse files Browse the repository at this point in the history
to distribution data
  • Loading branch information
shaojunda committed Apr 30, 2020
1 parent 3a175b9 commit 2c40104
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/distribution_data.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DistributionData
VALID_INDICATORS = %w(address_balance_distribution block_time_distribution)
VALID_INDICATORS = %w(address_balance_distribution block_time_distribution epoch_time_distribution)

def id
Time.current.to_i
Expand All @@ -12,4 +12,8 @@ def address_balance_distribution
def block_time_distribution
EpochStatistic.order(epoch_number: :desc).first&.block_time_distribution || []
end

def epoch_time_distribution
EpochStatistic.order(epoch_number: :desc).first&.epoch_time_distribution || []
end
end
6 changes: 6 additions & 0 deletions app/serializers/distribution_data_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ class DistributionDataSerializer
} do |object|
object.block_time_distribution.map { |distribution| distribution.map(&:to_s) }
end

attribute :epoch_time_distribution, if: Proc.new { |_record, params|
params && params[:indicator].include?("epoch_time_distribution")
} do |object|
object.epoch_time_distribution.map { |distribution| distribution.map(&:to_s) }
end
end

0 comments on commit 2c40104

Please sign in to comment.