Voting Powerを表示してみます
こんにちは、@yasuです。
今回は、
Voting Power価格を表示してみます。
https://ojagggyo.github.io/steemitapi03.html#yasu
アカウント指定方法、
#アカウント名(@マークを除く)
計算方法は、
前回Votingした時のVotingWeightと日時が、アカウント情報に記録されているので、
現在のVotingWeight = 前回のVotingWeight + 前回のVoting時間からの回復値(1日で20%回復する)で計算している。
なので、放置しておくと100%を超えます。100%を超えてもVotingWeightの最大値は100%です。
周期的に更新するようにしました。
ソース
<!doctype html>
<html lang="en">
<head>
<title>Voting Power</title>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://github.com/steemit/steem-js/releases/download/v0.7.7/steem.min.js"></script>
<script>
let username;
function saveUserName(){
username = window.location.hash;// #username
if (username == null || username.trim().length == 0){
username = "#steemitblog";
}
username = username.substr(1);//#を取る
username = decodeURI(username).trim();//デコード、トリム
}
async function getAccountsAsync(){
let accounts = await steem.api.getAccountsAsync([username]);
console.log(accounts);
if(accounts.length == 0) {return;}
let account = accounts[0];
let vp = account.voting_power + (10000 * ((new Date - new Date(account.last_vote_time + "Z")) / 1000) / 432000);
var text = "Voting Powerは " + (vp/100).toFixed(4) + " %です。";
$("#votingPower").text(text);
}
window.onload = function() {
steem.api.setOptions({url: 'https://api.steemit.com'});
saveUserName();
getAccountsAsync();
setInterval(getAccountsAsync, 5000);
};
</script>
</head>
<body>
<div>
こんにちは、
</div>
<h1 id="votingPower"></h1>
</body>
</html>
Excellent post, as usual, good luck
jcar bp 3/7