Finding the number of authors/voters/... per day with Python

in #python5 years ago (edited)


Image: Timur Saglambilek

Just used a similar variant for another purpose, maybe it's helpful for somebody else as well. This script uses beem to access the blockchain.

from beem.blockchain import Blockchain
from datetime import datetime, timedelta
import sys

start_time = datetime(2019, 5, 29)
bc = Blockchain()
start_block = bc.get_estimated_block_num(start_time)
stop_block = bc.get_estimated_block_num(start_time +
                                        timedelta(days=1))
root_authors = set()
comment_authors = set()
voters = set()
transactors = set()
for op in bc.stream(start=start_block, stop=stop_block,
                    max_batch_size=50):
    sys.stdout.write("%s\r" % (op['timestamp']))
    if op['type'] == 'comment':
        if op['parent_author']:
            comment_authors |= set([op['author']])
        else:
            root_authors |= set([op['author']])
    if op['type'] == 'vote':
        voters |= set([op['voter']])
    if op['type'] == 'transfer':
        transactors |= set([op['from']])

print("\nNumber of root authors    : %d" % (len(root_authors)))
print("Number of comment authors : %d" % (len(comment_authors)))
print("Number of voters          : %d" % (len(voters)))
print("Number of transfer senders: %d" % (len(transactors)))

A few remarks:

  • blockchain.get_estimated_block_num() is a nice way to get a block number form a time stamp and is used to find the start and stop blocks.
  • The set()s are an elegant way to keep track of a list of unique entries, or'ing with |= adds new values only if they are not yet contained in the set
  • The sys.stdout.write() with line-return gives some status info on how far in time the script has the data processed and only little output clutter to the terminal

Results for May 29th, 2019

Number of root authors6247
Number of comment authors4129
Number of voters41559
Number of transfer senders2929

Wow, the numbers aren't very promising :/ We had ~8k root posters and ~6k comment authors beginning of the year and more than 10k/8k (root/comment) around Sept. 2018. The number of voters per day also seems to be declining, coming from around 47k at the beginning of the year and >50k in Sept '18. number references.

Sort:  

Congratulations @stmdev! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 2000 upvotes. Your next target is to reach 3000 upvotes.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

This is very useful. Thank you for sharing!

Posted using Partiko Android