Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json, re, requests, collections, time, sys
- from operator import itemgetter
- from piston.steem import Steem
- #https://steem.io/getinvolved/paid-to-curate/
- ###############################
- #######################generali
- ###############################
- def url_posts(user):
- return ['/'.join(x.url[1:].split('/')[1:]) for x in Steem().get_blog(user)]
- def get_votes(link):
- steem = Steem()
- votes = steem.get_content(link).active_votes
- #{'percent': 10000, 'voter': 'balay', 'rshares': 116106839, 'time': '2016-07-16T10:33:57', 'weight': '164997678476'}
- l=[]
- for vote in votes:
- l+=[[int(time.mktime(time.strptime(str(vote['time']), '%Y-%m-%dT%H:%M:%S'))),int(vote['percent']),int(vote['rshares']),int(vote['weight'])]]
- #[epoch,percent,rshares,weight]
- votes=sorted(l, key=itemgetter(0))
- print(votes)
- return votes
- ###############################
- #########################reward
- ###############################
- def current_total_steem_power(votes, n):
- #current_total_steem_power = the combined STEEM power of all past votes
- return sum([votes[x][2] for x in range(n)])
- def new_total_steem_power(votes, n):
- #new_total_steem_power = current_total_steem_power + steem_power;
- return current_total_steem_power(votes, n)+votes[n][2]
- def vote_payout_weight(votes, n):
- #vote_payout_weight = steem_power * (steem_power/new_total_steem_power)^2
- return votes[n][2]*(votes[n][2]/new_total_steem_power(votes, n))**2
- def total_vote_payout_weight(votes, n):
- #total_vote_payout_weight = sum vote_payout_weight for all votes on the post (past votes or 'all' at the payout time?)
- return sum([vote_payout_weight(votes, x) for x in range(n)])
- ###############################
- #########################graphs
- ###############################
- def graph(x,y):
- import matplotlib.pyplot as plt
- import numpy as np
- plt.plot(np.array(x),np.array(y), 'r.')
- plt.show()
- from multiprocessing.dummy import Pool as ThreadPool
- def listflatter(list_to_flat): #[[1,2],[3,4],[5,6]]---->[1,2,3,4,5,6]
- return [item for sublist in list_to_flat for item in sublist]
- def parallelfor(function, lista):
- pool = ThreadPool(3)
- result = listflatter(pool.map(function, lista))
- pool.close()
- pool.join()
- return result
- user='dan'
- tot_votes=[]
- tot_votes=parallelfor(get_votes, url_posts(user))
- # for link in url_posts(user):
- # print(link)
- # tot_votes+=get_votes(link)
- votes=tot_votes
- print('===========')
- print(votes)
- y=[vote_payout_weight(votes, x) for x in range(len(votes))]
- x=[votes[x][3] for x in range(len(votes))]
- graph(x,y)
Advertisement
Add Comment
Please, Sign In to add comment