How to Get Account History Stats in Ruby
This ruby script will allow you to inspect an account's history from up to 10,000 operations using one API call. It's useful for getting a sense as to what a particular account is up to lately, but it depends on how active the account has been.
As always, we use Radiator with bundler
. You can get bundler
with this command:
$ gem install bundler
I've tested it on various versions of ruby. The oldest one I got it to work was:
ruby 2.0.0p645 (2015-04-13 revision 50299) [x86_64-darwin14.4.0]
First, make a project folder:
$ mkdir radiator
$ cd radiator
Create a file named Gemfile
containing:
source 'https://rubygems.org'
gem 'radiator'
gem 'awesome_print'
Then run the command:
$ bundle install
Create a file named account_history_stats.rb
containing:
require 'rubygems'
require 'bundler/setup'
Bundler.require
if ARGV.empty?
puts "Usage: ruby #{__FILE__} <account> [limit]"
exit
end
api = Radiator::Api.new(url: 'https://steemd.steemit.com')
account = ARGV[0]
limit = (ARGV[1] || '10000').to_i
stats = {ops: {}}
response = api.get_account_history(account, -limit, limit)
response.result.each do |index, transaction|
block = transaction.block
timestamp = Time.parse(transaction.timestamp + 'Z')
type, op = transaction.op
stats[:first_block] ||= block
stats[:last_block] = block
stats[:span_in_blocks] = block - stats[:first_block]
stats[:first_timestamp] ||= timestamp
stats[:last_timestamp] = timestamp
stats[:span_in_days] = (timestamp - stats[:first_timestamp]) / 60 / 60 / 24
stats[:ops][type] ||= 0
stats[:ops][type] += 1
end
ap stats
Then run it:
$ ruby account_history_stats.rb sneak
The expected output will be something like this:
{
:ops => {
"vote" => 6806,
"comment" => 2284,
"custom_json" => 98,
"author_reward" => 243,
"curation_reward" => 424,
"account_witness_vote" => 16,
"comment_options" => 22,
"interest" => 8,
"account_update" => 3,
"transfer" => 21,
"limit_order_create" => 9,
"fill_order" => 10,
"limit_order_cancel" => 3,
"transfer_to_vesting" => 11,
"convert" => 2,
"fill_convert_request" => 2,
"delete_comment" => 8,
"account_witness_proxy" => 1,
"claim_reward_balance" => 25,
"delegate_vesting_shares" => 1,
"withdraw_vesting" => 4
},
:first_block => 7463964,
:last_block => 15310716,
:span_in_blocks => 7846752,
:first_timestamp => 2016-12-10 12:48:09 UTC,
:last_timestamp => 2017-09-09 08:40:03 UTC,
:span_in_days => 272.82770833333336
}
Interesting. What class do I have to take to understand this language?
Computernese Class ;)
So simple? Thank you @dandesign86
Great post
Upvoted and followed. Kindly do same for me too....
https://steemit.com/news/@mickyscofield/meet-couple-who-bear-same-name-with-hurricane-harvey-and-irma
nice i think i will try it
Thanks for sharing code, I always like seeing that..
Your post is fantastic. You are a Master Steemian! More People Should Follow You And Upvote Your post which has received a 50.00 % upvote from @binkley thanks to: @steemthat for verifying this quality post.
SteemThat.com Is So Awesome Please Upvote This Comment To Help Me Verify More Quality Posts. Is this post original lets check @originalworks
I always love the comments on dev posts. Succinct and awesome script as always. This pulls the rewards in $$ or Steem? Guessing Steem makes more sense
Sorry, I don't understand the question, I guess. Do you mean the rewards for this post? It's set to the defaut of 50/50.
nice post