Skip to content

Commit

Permalink
Extend mana information on account helper
Browse files Browse the repository at this point in the history
  • Loading branch information
emre committed Oct 11, 2018
1 parent 7e4cc72 commit ef033e0
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lightsteem/helpers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ def vp(self, consider_regeneration=True, precision=2):
return round(total_vp, precision)

def rc(self, consider_regeneration=True, precision=2):
rc_info = self.get_resource_credit_info()
if not consider_regeneration:
percent = rc_info["last_mana_percent"]
else:
percent = rc_info["current_mana_percent"]
return round(percent, precision)

def get_resource_credit_info(self):
preffered_api_type = self.client.api_type
try:
rc_info = self.client('rc_api').find_rc_accounts(
Expand All @@ -222,26 +230,29 @@ def rc(self, consider_regeneration=True, precision=2):

last_mana = int(rc_info["rc_manabar"]["current_mana"])
max_mana = int(rc_info["max_rc"])

if not consider_regeneration:
# the voting power user has after the last vote they casted.
return round(last_mana * 100 / max_mana, precision)
updated_at = datetime.datetime.utcfromtimestamp(
rc_info["rc_manabar"]["last_update_time"])
diff_in_seconds = (
datetime.datetime.utcnow() - updated_at).total_seconds()
regenerated_mana = (diff_in_seconds * max_mana
/ VOTING_MANA_REGENERATION_IN_SECONDS)
current_mana = last_mana + regenerated_mana
current_mana_percent = current_mana * 100 / max_mana

return round(current_mana_percent, precision)
last_mana_percent = last_mana * 100 / max_mana
current_mana_percent = current_mana * 100 / max_mana

# @todo: should there be some methods to calculate
# regeneration estimation until %100?
# total_mana_required = 100 - current_mana_percent
# recharge_in_seconds = total_mana_required * \
# VOTING_MANA_REGENERATION_IN_SECONDS / 100
total_mana_required = 100 - current_mana_percent
recharge_in_seconds = total_mana_required * \
VOTING_MANA_REGENERATION_IN_SECONDS / 100
return {
"last_mana": last_mana,
"last_mana_percent": last_mana_percent,
"current_mana": current_mana,
"current_mana_percent": current_mana_percent,
"max_mana": max_mana,
"full_recharge_in_seconds": recharge_in_seconds,
}

finally:
self.client.api_type = preffered_api_type
Expand Down

0 comments on commit ef033e0

Please sign in to comment.