Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shown Voting Power is not the current value #2

Closed
crokkon opened this issue Feb 17, 2018 · 2 comments
Closed

Shown Voting Power is not the current value #2

crokkon opened this issue Feb 17, 2018 · 2 comments

Comments

@crokkon
Copy link

crokkon commented Feb 17, 2018

Expected behavior

The utopian-moderator extension should show the current utopian-io voting power

Actual behavior

screenshot.png

The extension shows the utopian-io voting power at the time of the last utopian vote. The voting_power field in the steem account information only stores the VP at the time of the last vote, not the current value:

>>> from steem.account import Account
>>> a = Account("utopian-io")
>>> a['voting_power']
6680

In order to get the current VP, one has to calculate the voting power regeneration since the last vote. Here's the python-equivalent to get the current voting power:


def get_voting_power(account):
    """get current voting power. The 'last_vote_time' value in the account
    data only contains the VP at the time of the last vote.

    """
    last_vote_time = parse(account['last_vote_time'])
    diff = (dt.datetime.utcnow() - last_vote_time).total_seconds()
    regenerated_vp = diff * 10000 / 86400 / 5
    total_vp = (account['voting_power'] + regenerated_vp) / 100.0
    if total_vp > 100:
        total_vp = 100.0
    return total_vp

How to reproduce

Compare the value in the extension with those on steemd/steemworld/...

Here is the corresponding part in the code:

let result = (response[0].voting_power) / 100;

@justyy, steemtools seems to be affected as well:
https://github.com/DoctorLai/SteemTools/blob/24283592c488f23b0df4218982ecb801343d2496/js/steemtools.js#L36



Posted on Utopian.io - Rewarding Open Source Contributors

@DoctorLai
Copy link
Owner

// get voting power
function getVP(id, dom, server) {
    server = server || default_node;
    steem.api.setOptions({ url: server });

    steem.api.getAccounts([id], function(err, response) {
        if (!err) {
            let result = response[0].voting_power;
            let last_vote_time = response[0].last_vote_time;
            let diff = (Date.now() - Date.parse(last_vote_time)) / 1000;
            let regenerated_vp = diff * 10000 / 86400 / 5;
            let total_vp = (result + regenerated_vp) / 100;
            total_vp = Math.min(100, total_vp);
            dom.html("<i>@" + id + "'s Voting Power is</i> <B>" + total_vp.toFixed(2) + "%</B>");
            if (result < 30) {
                dom.css("background-color", "red");
            } else if (result < 60) {
                dom.css("background-color", "orange");
            } else {
                dom.css("background-color", "green");
            }
            dom.css("color", "white");
            dom.css("width", total_vp + "%");
            logit("API Finished: VP - " + server + ": " + id);
        } else {
            logit("API error: " + server + ": " + err);
        }
    });   
}

@DoctorLai
Copy link
Owner

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants