Skip to content

Commit

Permalink
common steem constants added and used in account, comment and steem
Browse files Browse the repository at this point in the history
  • Loading branch information
holgern committed May 23, 2018
1 parent 0c0fbf2 commit bac8b3c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
5 changes: 3 additions & 2 deletions beem/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from beembase import operations
from beemgraphenebase.account import PrivateKey, PublicKey
from beemgraphenebase.py23 import bytes_types, integer_types, string_types, text_type
from beem.constants import STEEM_VOTE_REGENERATION_SECONDS
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -285,7 +286,7 @@ def get_voting_power(self, with_regeneration=True):
if with_regeneration:
utc = pytz.timezone('UTC')
diff_in_seconds = (utc.localize(datetime.utcnow()) - (self["last_vote_time"])).total_seconds()
regenerated_vp = diff_in_seconds * 10000 / 86400 / 5 / 100
regenerated_vp = diff_in_seconds * 10000 / STEEM_VOTE_REGENERATION_SECONDS / 100
else:
regenerated_vp = 0
total_vp = (self["voting_power"] / 100 + regenerated_vp)
Expand Down Expand Up @@ -334,7 +335,7 @@ def get_recharge_timedelta(self, voting_power_goal=100):
missing_vp = voting_power_goal - self.get_voting_power()
if missing_vp < 0:
return 0
recharge_seconds = missing_vp * 100 * 5 * 86400 / 10000
recharge_seconds = missing_vp * 100 * STEEM_VOTE_REGENERATION_SECONDS / 10000
return timedelta(seconds=recharge_seconds)

def get_recharge_time(self, voting_power_goal=100):
Expand Down
13 changes: 2 additions & 11 deletions beem/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .exceptions import ContentDoesNotExistsException, VotingInvalidOnArchivedPost
from beembase import operations
from beemgraphenebase.py23 import py23_bytes, bytes_types, integer_types, string_types, text_type
from beem.constants import STEEM_REVERSE_AUCTION_WINDOW_SECONDS, STEEM_100_PERCENT, STEEM_1_PERCENT
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -291,7 +292,7 @@ def get_curation_penalty(self, vote_time=None):
elapsed_seconds = (vote_time - self["created"]).total_seconds()
else:
raise ValueError("vote_time must be a string or a datetime")
reward = (elapsed_seconds / 1800)
reward = (elapsed_seconds / STEEM_REVERSE_AUCTION_WINDOW_SECONDS)
if reward > 1:
reward = 1.0
return 1.0 - reward
Expand Down Expand Up @@ -537,16 +538,6 @@ def vote(self, weight, account=None, identifier=None, **kwargs):
else:
[post_author, post_permlink] = resolve_authorperm(identifier)

steem_conf = self.steem.get_config()
if 'STEEMIT_100_PERCENT' in steem_conf:
STEEM_100_PERCENT = steem_conf['STEEMIT_100_PERCENT']
STEEM_1_PERCENT = steem_conf['STEEMIT_1_PERCENT']
elif 'STEEM_100_PERCENT' in steem_conf:
STEEM_100_PERCENT = steem_conf['STEEM_100_PERCENT']
STEEM_1_PERCENT = steem_conf['STEEM_1_PERCENT']
else:
STEEM_100_PERCENT = 10000
STEEM_1_PERCENT = (STEEM_100_PERCENT / 100)
vote_weight = int(weight * STEEM_1_PERCENT)
if vote_weight > STEEM_100_PERCENT:
vote_weight = STEEM_100_PERCENT
Expand Down
13 changes: 13 additions & 0 deletions beem/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This Python file uses the following encoding: utf-8
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals


STEEM_100_PERCENT = 10000
STEEM_1_PERCENT = 100
STEEM_1_TENTH_PERCENT = 10
STEEM_REVERSE_AUCTION_WINDOW_SECONDS = 1800
STEEM_VOTE_REGENERATION_SECONDS = 432000
STEEM_ROOT_POST_PARENT = ''
3 changes: 2 additions & 1 deletion beem/steem.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .wallet import Wallet
from .transactionbuilder import TransactionBuilder
from .utils import formatTime, resolve_authorperm, derive_permlink, remove_from_dict
from beem.constants import STEEM_VOTE_REGENERATION_SECONDS

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -491,7 +492,7 @@ def _max_vote_denom(self):
# get props
global_properties = self.get_dynamic_global_properties()
vote_power_reserve_rate = global_properties['vote_power_reserve_rate']
max_vote_denom = vote_power_reserve_rate * (5 * 60 * 60 * 24)
max_vote_denom = vote_power_reserve_rate * STEEM_VOTE_REGENERATION_SECONDS
return max_vote_denom

def _calc_resulting_vote(self, voting_power=10000, vote_pct=10000):
Expand Down
11 changes: 8 additions & 3 deletions examples/benchmark_nodes2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from beem.utils import parse_time, formatTimedelta, get_node_list, construct_authorperm, resolve_authorperm, resolve_authorpermvoter, construct_authorpermvoter
from beem.comment import Comment
from beem.vote import Vote
from beemgrapheneapi.rpcutils import NumRetriesReached
from beemapi.exceptions import NumRetriesReached
FUTURES_MODULE = None
if not FUTURES_MODULE:
try:
Expand All @@ -33,6 +33,7 @@ def benchmark_node(node, how_many_minutes=10, how_many_seconds=30):
block_count = 0
history_count = 0
access_time = 0
follow_time = 0
blockchain_version = u'0.0.0'
sucessfull = False
error_msg = None
Expand Down Expand Up @@ -92,7 +93,11 @@ def benchmark_node(node, how_many_minutes=10, how_many_seconds=30):
Account(author, steem_instance=stm)
stop = timer()
account_time = stop - start
access_time = (vote_time + comment_time + account_time) / 3.0
start = timer()
account.get_followers()
stop = timer()
follow_time = stop - start
access_time = (vote_time + comment_time + account_time + follow_time) / 4.0
sucessfull = True
except NumRetriesReached:
error_msg = 'NumRetriesReached'
Expand All @@ -103,7 +108,7 @@ def benchmark_node(node, how_many_minutes=10, how_many_seconds=30):
error_msg = str(e)
return {'sucessfull': sucessfull, 'node': node, 'error': error_msg,
'total_duration': timer() - start_total, 'block_count': block_count,
'history_count': history_count, 'access_time': access_time,
'history_count': history_count, 'access_time': access_time, 'follow_time': follow_time,
'version': blockchain_version}


Expand Down

0 comments on commit bac8b3c

Please sign in to comment.