Skip to content

Commit

Permalink
Merge pull request #29 from emre/account_rc_method
Browse files Browse the repository at this point in the history
Add consider_regeneration to rc calculation
  • Loading branch information
emre committed Oct 11, 2018
2 parents 8b80026 + 74d6768 commit b44f8f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
19 changes: 19 additions & 0 deletions docs/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ If you want the VP at the time the last vote casted, you can pass consider_regen
print(account.vp())
print(account.vp(consider_regeneration=False))
Getting resource credits
-----------------------------------
This helper method determines the account's resource credits in percent. In default, It considers
account's regenerated RC. (Actual RC)

If you want the Rc at the time the last vote casted, you can pass consider_regeneration=False.

.. code-block:: python
from lightsteem.client import Client
client = Client()
account = client.account('emrebeyler')
print(account.rc())
print(account.rc(consider_regeneration=False))
Getting account reputation
-----------------------------------

Expand Down
8 changes: 7 additions & 1 deletion lightsteem/helpers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def vp(self, consider_regeneration=True, precision=2):

return round(total_vp, precision)

def rc(self, precision=2):
def rc(self, consider_regeneration=True, precision=2):
preffered_api_type = self.client.api_type
try:
rc_info = self.client('rc_api').find_rc_accounts(
Expand All @@ -222,6 +222,10 @@ def rc(self, 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 = (
Expand All @@ -233,6 +237,8 @@ def rc(self, precision=2):

return round(current_mana_percent, precision)

# @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
Expand Down
3 changes: 3 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ def match_find_rc_accounts(request):
self.assertEqual(float(95), self.client.account(
'emrebeyler').rc())

self.assertEqual(float(75), self.client.account(
'emrebeyler').rc(consider_regeneration=False))

def test_reputation(self):
reputation_sample = '74765490672156' # 68.86
with requests_mock.mock() as m:
Expand Down

0 comments on commit b44f8f5

Please sign in to comment.