pietrod21

Untitled

Jul 19th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 0 0
  1. import json, re, requests, collections, time, sys
  2. from operator import itemgetter
  3. from piston.steem import Steem
  4. #https://steem.io/getinvolved/paid-to-curate/
  5.  
  6.  
  7. ###############################
  8. #######################generali
  9. ###############################
  10.  
  11. def url_posts(user):
  12.     return ['/'.join(x.url[1:].split('/')[1:]) for x in Steem().get_blog(user)]
  13.  
  14. def get_votes(link):
  15.     steem = Steem()
  16.     votes = steem.get_content(link).active_votes
  17.     #{'percent': 10000, 'voter': 'balay', 'rshares': 116106839, 'time': '2016-07-16T10:33:57', 'weight': '164997678476'}
  18.     l=[]
  19.     for vote in votes:
  20.         l+=[[int(time.mktime(time.strptime(str(vote['time']), '%Y-%m-%dT%H:%M:%S'))),int(vote['percent']),int(vote['rshares']),int(vote['weight'])]]
  21.         #[epoch,percent,rshares,weight]
  22.     votes=sorted(l, key=itemgetter(0))
  23.     print(votes)
  24.     return votes
  25.  
  26. ###############################
  27. #########################reward
  28. ###############################
  29.  
  30. def current_total_steem_power(votes, n):
  31.     #current_total_steem_power = the combined STEEM power of all past votes
  32.     return sum([votes[x][2] for x in range(n)])
  33.  
  34. def new_total_steem_power(votes, n):
  35.     #new_total_steem_power = current_total_steem_power + steem_power;
  36.     return current_total_steem_power(votes, n)+votes[n][2]
  37.  
  38. def vote_payout_weight(votes, n):
  39.     #vote_payout_weight = steem_power * (steem_power/new_total_steem_power)^2
  40.     return votes[n][2]*(votes[n][2]/new_total_steem_power(votes, n))**2
  41.  
  42. def total_vote_payout_weight(votes, n):
  43.     #total_vote_payout_weight = sum vote_payout_weight for all votes on the post (past votes or 'all' at the payout time?)
  44.     return sum([vote_payout_weight(votes, x) for x in range(n)])
  45.  
  46. ###############################
  47. #########################graphs
  48. ###############################
  49.  
  50. def graph(x,y):
  51.     import matplotlib.pyplot as plt
  52.     import numpy as np  
  53.     plt.plot(np.array(x),np.array(y), 'r.')
  54.     plt.show()
  55.  
  56.  
  57. from multiprocessing.dummy import Pool as ThreadPool
  58.  
  59. def listflatter(list_to_flat): #[[1,2],[3,4],[5,6]]---->[1,2,3,4,5,6]
  60.     return [item for sublist in list_to_flat for item in sublist]
  61.  
  62. def parallelfor(function, lista):
  63.     pool = ThreadPool(3)
  64.     result = listflatter(pool.map(function, lista))
  65.     pool.close()
  66.     pool.join()
  67.     return result
  68.  
  69. user='dan'
  70.  
  71. tot_votes=[]
  72. tot_votes=parallelfor(get_votes, url_posts(user))
  73.  
  74. # for link in url_posts(user):
  75. #   print(link)
  76. #   tot_votes+=get_votes(link)
  77.  
  78.  
  79. votes=tot_votes
  80. print('===========')
  81. print(votes)
  82. y=[vote_payout_weight(votes, x) for x in range(len(votes))]
  83. x=[votes[x][3] for x in range(len(votes))]
  84. graph(x,y)
Advertisement
Add Comment
Please, Sign In to add comment