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

prettyNumber #2

Open
Eaven opened this issue Jun 12, 2018 · 3 comments
Open

prettyNumber #2

Eaven opened this issue Jun 12, 2018 · 3 comments

Comments

@Eaven
Copy link

Eaven commented Jun 12, 2018

the votes were way off with 2.8

the closest I could come up with is num = parseInt(parseInt(num) / 1e10 * 2.67708);

@Eaven
Copy link
Author

Eaven commented Jun 13, 2018

<td>{{numberWithCommas((producer.total_votes  / calculateVoteWeight() / 10000).toFixed(0))}}</td>

calculateVoteWeight() {
    //time epoch:
    //https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/time.hpp#L160
    //stake to vote
    //https://github.com/EOSIO/eos/blob/master/contracts/eosio.system/voting.cpp#L105-L109
    let timestamp_epoch:number = 946684800000;
    let dates_:number = (Date.now() / 1000) - (timestamp_epoch / 1000);
    let weight_:number = (dates_ / (86400 * 7)) / 52;  //86400 = seconds per day 24*3600
    return Math.pow(2, weight_);
  }
  numberWithCommas(x: any) {
    x = x.toString();
    var pattern = /(-?\d+)(\d{3})/;
    while (pattern.test(x))
      x = x.replace(pattern, "$1,$2");
    return x;
  }

so this is how eosportal is doing it. going to work on converting it from vue to pure JS

@Eaven
Copy link
Author

Eaven commented Jun 13, 2018

function calculateVoteWeight() {
  //time epoch:
  //https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/time.hpp#L160
  //stake to vote
  //https://github.com/EOSIO/eos/blob/master/contracts/eosio.system/voting.cpp#L105-L109
  var timestamp_epoch = 946684800000;
  var dates_ = (Date.now() / 1000) - (timestamp_epoch / 1000);
  var weight_ = (dates_ / (86400 * 7)) / 52;  //86400 = seconds per day 24*3600
  return Math.pow(2, weight_);
}

function numberWithCommas(x) {
  x = x.toString();
  var pattern = /(-?\d+)(\d{3})/;
  while (pattern.test(x))
    x = x.replace(pattern, "$1,$2");
  return x;
}
<td>${numberWithCommas((prod.total_votes  / calculateVoteWeight() / 10000).toFixed(0))}</td>

its still a little off.. hmm

@Eaven
Copy link
Author

Eaven commented Jun 13, 2018

it could be eosportal thats a little off honestly

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

1 participant