Skip to content
Permalink
Browse files

* Add curation performance calculation for paid out posts

* Robustify comment parsing
* Some bug fixes
* Limit the number of shown failed votes at the homepage
  • Loading branch information...
holgern committed May 21, 2019
1 parent 1ff8331 commit 6a9f10930207c14d3b18e505078cd157fac1eee1
@@ -98,7 +98,11 @@
if len(rules) == 0:
continue
fitting_rules = []
post = Comment(authorperm, steem_instance=stm)
try:
post = Comment(authorperm, steem_instance=stm)
except:
print("Could not parse %s" % authorperm)
continue
for rule in rules:
# print(rule)
if not string_included(rule["include_authors"], post["author"]):
@@ -120,7 +120,10 @@

if len(fitting_rules) == 0:
continue
c = Comment(authorperm, steem_instance=stm)
try:
c = Comment(authorperm, steem_instance=stm)
except:
continue
voters = []
for v in c["active_votes"]:
voters.append(v["voter"])
@@ -6,6 +6,7 @@
from datetime import datetime, timedelta
from beem.instance import set_shared_steem_instance
from beem.blockchain import Blockchain
from beem.vote import AccountVotes, ActiveVotes
import time
import json
import os
@@ -24,7 +25,7 @@
from steemrewarding.vote_log_storage import VoteLogTrx
from steemrewarding.failed_vote_log_storage import FailedVoteLogTrx
from steemrewarding.account_storage import AccountsDB
from steemrewarding.utils import isfloat, upvote_comment, valid_age
from steemrewarding.utils import isfloat, upvote_comment, valid_age, curation_performance
from steemrewarding.version import version as rewardingversion
import dataset

@@ -72,7 +73,8 @@
b = Blockchain(steem_instance = stm)
updated_vote_log = []
voteLogTrx.delete_old_logs(14)
for n in range(16):

for n in range(32):
if n < 4:
vote_log = voteLogTrx.get_oldest_log(vote_delay_optimized=True)

@@ -86,6 +88,8 @@
if vote_log is not None:
authorperm = vote_log["authorperm"]
# print(vote_log["authorperm"])
if n == 15:
print("performance vote last update %s" % str(vote_log["last_update"]))
try:
c = Comment(authorperm, steem_instance=stm)
except:
@@ -108,19 +112,7 @@
if vote_log["vote_delay_optimized"]:
vote_log["vote_delay_optimized"] = False
voteLogTrx.update(vote_log)
continue

performance = 0
rshares = 0
for vote in c["active_votes"]:
if vote["voter"] != vote_log["voter"]:
continue
rshares = int(vote["rshares"])
vote_SBD = stm.rshares_to_sbd(rshares)
curation_SBD = curation_rewards_SBD["active_votes"][vote["voter"]]
if vote_SBD > 0:
performance = (float(curation_SBD) / vote_SBD * 100)


acc_data = accountsDB.get(vote_log["voter"])
vote_delay_diff = vote_log["voted_after_min"] - vote_log["vote_delay_min"]
if acc_data is not None:
@@ -132,18 +124,62 @@
else:
minimum_vote_delay = 0
maximum_vote_delay = 6.5 * 24 * 60
rshares_divider = 5
rshares_divider = 5

best_performance = 0
best_vote_delay_min = 0
for v in c["active_votes"]:
v_SBD = stm.rshares_to_sbd(int(v["rshares"]))

if v_SBD > 0 and int(v["rshares"]) > rshares / rshares_divider:
best_vote_delay_min = 0
performance = 0
rshares = 0
voter_rshares = 0

if c.is_pending():
for vote in c["active_votes"]:
if vote["voter"] == vote_log["voter"]:
rshares = int(vote["rshares"])
for vote in c["active_votes"]:

voter_rshares = int(vote["rshares"])

p = float(curation_rewards_SBD["active_votes"][v["voter"]]) / v_SBD * 100
if p > best_performance:
best_performance = p
best_vote_delay_min = ((v["time"]) - c["created"]).total_seconds() / 60
curation_SBD = curation_rewards_SBD["active_votes"][vote["voter"]]
if voter_rshares > 0 and vote["voter"] == vote_log["voter"]:
vote_SBD = stm.rshares_to_sbd(voter_rshares)
performance = (float(curation_SBD) / vote_SBD * 100)
if voter_rshares > 0 and voter_rshares > rshares / rshares_divider:
vote_SBD = stm.rshares_to_sbd(voter_rshares)
p = float(curation_rewards_SBD["active_votes"][vote["voter"]]) / vote_SBD * 100
if p > best_performance:
best_performance = p
best_vote_delay_min = ((vote["time"]) - c["created"]).total_seconds() / 60
else:
rshares_sum = 0
rshares_before = 0
rshares_after = 0
activeVotes = ActiveVotes(authorperm, steem_instance=stm).get_sorted_list()
total_rshares_sum = 0
for v in activeVotes:
if v["rshares"] > 0:
rshares_sum += int(v["rshares"])
total_rshares_sum += int(v["rshares"])
if v["voter"] == vote_log["voter"]:
rshares = int(vote["rshares"])
curation_rshares = 0.25 * total_rshares_sum
for vote in activeVotes:
voter_rshares = int(vote["rshares"])
rshares_after = rshares_sum - rshares_before - voter_rshares
if voter_rshares > 0:
y = curation_performance(rshares_before, voter_rshares, rshares_after)
if voter_rshares > 0 and vote["voter"] == vote_log["voter"]:
performance = (1 - c.get_curation_penalty(vote_time=vote["time"])) * (curation_rshares * y) / voter_rshares * 100
if voter_rshares > 0 and voter_rshares > rshares / rshares_divider:
vote_SBD = stm.rshares_to_sbd(voter_rshares)
p = float(curation_rewards_SBD["active_votes"][vote["voter"]]) / vote_SBD * 100
if p > best_performance:
best_performance = p
best_vote_delay_min = ((vote["time"]) - c["created"]).total_seconds() / 60
if voter_rshares > 0:
rshares_before += voter_rshares
vote_log["is_pending"] = False


if acc_data is not None and acc_data["optimize_vote_delay"] and abs(vote_delay_diff) < 1.0 and not vote_log["trail_vote"]:

@@ -646,11 +646,11 @@ def show_failed_vote_log():
failedVoteLogTrx = FailedVoteLogTrx(db)

try:
logs = failedVoteLogTrx.get_votes(name)
logs = failedVoteLogTrx.get_votes(name, limit=100)
except:
db = dataset.connect(databaseConnector, engine_kwargs={'pool_recycle': 3600})
failedVoteLogTrx = FailedVoteLogTrx(db)
logs = failedVoteLogTrx.get_votes(name)
logs = failedVoteLogTrx.get_votes(name, limit=100)
accountsTrx = AccountsDB(db)
setting = accountsTrx.get(name)
if setting is None:
@@ -935,6 +935,12 @@ def edit_rule():
form = RuleForm(formdata=request.form)
if request.method == 'POST': # and form.validate():
rule_dict = rule_dict_from_form(name, form)
if rule_dict["author"] == "":
return redirect('/show_rules')
if rule_dict["author"][0] == '@':
rule_dict["author"] = rule_dict["author"][1:]
if len(rule_dict["author"]) > 16:
return redirect('/show_rules')
if rule_dict["author"] != author or rule_dict["main_post"] != main_post:
if copy_rule is None or not copy_rule:
voteRulesTrx.delete(name, author, main_post)
@@ -16,7 +16,7 @@
ascii = codecs.lookup('ascii')
codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs'))

VERSION = '0.1.4'
VERSION = '0.1.5'

tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized']

@@ -90,13 +90,18 @@ def get(self, authorperm, voter):
table = self.db[self.__tablename__]
return table.find_one(authorperm=authorperm, voter=voter)

def get_votes(self, voter, hours=168):
def get_votes(self, voter, hours=168, limit=-1):
table = self.db[self.__tablename__]
# today = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
date_before = datetime.utcnow() - timedelta(hours=hours)
votes = []
for v in table.find(table.table.columns.timestamp > date_before, voter=voter, order_by='-timestamp'):
votes.append(v)
if limit > 0:

for v in table.find(table.table.columns.timestamp > date_before, voter=voter, order_by='-timestamp', _limit=limit):
votes.append(v)
else:
for v in table.find(table.table.columns.timestamp > date_before, voter=voter, order_by='-timestamp'):
votes.append(v)
return votes

def get_votes_per_day(self, voter):
@@ -7,6 +7,7 @@
from future.utils import python_2_unicode_compatible
from datetime import date, datetime, timedelta
import time
import math


def isfloat(value):
@@ -44,6 +45,11 @@ def upvote_comment(c_comment, acc_vote_name, acc_vote_weight):
print("retry to vote %s from %s" % (c_comment["authorperm"], acc_vote_name))
print(type(inst))
print(inst)
time.sleep(3)
c_comment.refresh()
for v in c_comment["active_votes"]:
if acc_vote_name == v["voter"]:
vote_sucessfull = True

cnt += 1
return vote_sucessfull
@@ -114,3 +120,26 @@ def string_included(include_rule, string):
include = True
return include
return True

def approx_sqrt_v1(x):
if x <= 1:
return x
# mantissa_bits, leading_1, mantissa_mask are independent of x
msb_x = x.bit_length() - 1
msb_z = msb_x >> 1
msb_x_bit = 1 << msb_x
msb_z_bit = 1 << msb_z
mantissa_mask = msb_x_bit-1

mantissa_x = x & mantissa_mask
if (msb_x & 1) != 0:
mantissa_z_hi = msb_z_bit
else:
mantissa_z_hi = 0
mantissa_z_lo = mantissa_x >> (msb_x - msb_z)
mantissa_z = (mantissa_z_hi | mantissa_z_lo) >> 1
result = msb_z_bit | mantissa_z
return result

def curation_performance(rshares_before, rshares_vote, rshares_after):
return (approx_sqrt_v1(rshares_before + rshares_vote) - approx_sqrt_v1(rshares_before)) / (approx_sqrt_v1(rshares_before + rshares_vote + rshares_after))
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.1.4'
version = '0.1.5'
@@ -116,7 +116,7 @@ def get_log_list(self):
def get_oldest_log(self, vote_delay_optimized=False, min_age=15):
table = self.db[self.__tablename__]
date_before = datetime.utcnow() - timedelta(minutes=min_age)
return table.find_one(table.table.columns.timestamp < date_before, vote_delay_optimized=vote_delay_optimized, order_by='last_update')
return table.find_one(table.table.columns.timestamp < date_before, is_pending=True, vote_delay_optimized=vote_delay_optimized, order_by='last_update')

def get_votes_per_day(self, voter, author, sliding_window=True):
table = self.db[self.__tablename__]

0 comments on commit 6a9f109

Please sign in to comment.
You can’t perform that action at this time.