Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. from steem import Steem
  2. from steem.post import Post
  3. from steem.amount import Amount
  4. from dateutil.parser import parse
  5. from datetime import timedelta
  6.  
  7. steem = Steem()
  8.  
  9. # Everything we need to calculate the reward
  10.  
  11. reward_fund = steem.get_reward_fund()
  12.  
  13. reward_balance = Amount(reward_fund["reward_balance"]).amount
  14.  
  15. recent_claims = float(reward_fund["recent_claims"])
  16.  
  17. reward_share = reward_balance / recent_claims
  18.  
  19. base = Amount(steem.get_current_median_history_price()["base"]).amount
  20.  
  21.  
  22.  
  23. # The post
  24.  
  25. post = Post("@steempytutorials/part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python")
  26.  
  27.  
  28.  
  29. ### Sorting votes by rshares
  30.  
  31. # Create list of all votes, sort them by reward and print the top five
  32.  
  33. votes = [vote for vote in post["active_votes"]]
  34.  
  35. for vote in sorted(votes[:5], key=lambda x: float(x["rshares"]), reverse=True):
  36.  
  37.     print("{0:16} voted for ${1} - {2:>5}%".format(
  38.  
  39.         vote["voter"],
  40.  
  41.         str(float(vote["rshares"]) * reward_share * base)[:5],
  42.  
  43.         vote["percent"] / 100))
  44.  
  45.  
  46.  
  47. ### Curation reward penalty
  48.  
  49. def curation_penalty(post, vote):
  50.  
  51.     post_time = post["created"]
  52.  
  53.     vote_time = parse(vote["time"])
  54.  
  55.     time_elapsed = vote_time - post_time
  56.  
  57.     reward = time_elapsed / timedelta(minutes=30) * 1.0
  58.  
  59.  
  60.  
  61.     if reward > 1.0:
  62.         reward = 1.0
  63.  
  64.     return reward
  65.  
  66.  
  67. ### Calculating curation reward per vote
  68.  
  69. curation_pct = 0.25
  70.  
  71. def curation_reward(post, vote):
  72.  
  73.     rshares = float(vote["rshares"])
  74.  
  75.     base_share = reward_share * base
  76.     reward_pct = curation_penalty(post, vote)
  77.  
  78.     final_reward = (rshares * reward_pct * curation_pct) * base_share
  79.  
  80.     if reward_pct < 1.0:
  81.         print("The curator only got $" + final_reward + " because he voted"
  82.                                                        " during the 30 minutes penalty.")
  83.         print("He could have got $" + ((rshares * 1.0 * curation_pct) * base_share))
  84.         print("So the author made " + (rshares * 0.75 * (1.0 - reward_pct)) + " reward shares profit.")
  85.  
  86.     return final_reward
  87.  
  88.  
  89.  
  90. ### Adding everything together
  91.  
  92. curation_share = sum([curation_reward(post, vote) for vote in votes])
  93.  
  94. print(f"Estimated curation reward for this post is ${curation_share:.2}")
  95.  
  96.  
  97.  
  98. ### Revisiting the votes
  99.  
  100. for vote in sorted(votes[:5], key=lambda x: float(x["rshares"]), reverse=True):
  101.  
  102.     print("{0:16} voted for ${1} - {2:>5}%".format(
  103.  
  104.         vote["voter"],
  105.  
  106.         str(curation_reward(post, vote))[:5],
  107.  
  108.         vote["percent"] / 100))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement