Incorrect Voting Power Returned Steempy (and possibly other libraries) [Workaround]

in #steemit8 years ago

If you have been using Steempy (and possibly others) you probably realize that the Voting Power returned does not update until the User votes.

For example if I Up Vote a post and have 98% Voting Power remaining, then wait 3 hours, my Voting Power will be back at 100%. However Steempy does not reflect the change. Instead it will return the Voting Power at the time of my last vote (98%).

I calculated that the rate of Voting Power replenishment is 20%/24hrs or approximately 0.000228898%/second. Using this combined with the Last Voting Timestamp I wrote a little python function that works around this issue until this is fixed upstream:

from steem import utils

def get_correct_voting_power(vp, last_vote_time):
    VP_REPLENISH_RATE_PER_SECOND = 0.000228898
    delta = utils.time_elapsed(last_vote_time).total_seconds()
    vpoffset = delta*VP_REPLENISH_RATE_PER_SECOND*100
    realVP = int(float(vp) + float(vpoffset))
    if (realVP > 10000):
        realVP = 10000
    return realVP

Example use:

from steem import Steem

s = Steem()
# grab account information and fix voting power
account = s.steemd.get_account("bigdeej")
vp = get_correct_voting_power(account["voting_power"], account["last_vote_time"])

Hope that helps anyone who ran into this issue as I did! Super quick and easy workaround. This code I have tested for 3 weeks and have found it to be within 0.02% accurate of what steemd reports!

Sort:  

I would suggest using get_config() API function instead that will give you

`"STEEMIT_VOTE_REGENERATION_SECONDS": 432000,

This is a number of seconds (five days currently) required for your voting power to go from 0 to 10000. Your logic is equivalent, but in case this parameter ever changes, you won't need to rewrite your code.

Thanks for the input, I wish they would just fix this "up stream" so the API returned the correct VP. I will 100% endorse and use this constant since it will update along with new changes that as you point out are possible in the future (though are not currently as you also pointed out)! This is a great way to take this function and make it work until they fix the return to be the real VP vs the VP at the last voting time!

This issue is still on-going. I am using piston-lib.

Steemd and Busy show correct voting power.
SteemDB has not figured this out yet.

Agreed! We STILL have to use this work around to get the correct value!