HiveJS: How to get current Voting Power ? - Wie erhält man die aktuelle Voting Power? #17

DE (EN below)

In meinem letzten Beitrag, der schon ein paar Tage her ist, habe ich gezeigt, wie man Informationen zu Witnesse abrufen kann und wie man für diese votet.

Heute gibt es ein wirklich kurzen Beispielcode, wie man die Hive Power von einem User erhält. Dafür benötigen wir wieder einmal die Funktion hive.api.getAccounts, denn in den Accountdaten finden wir die Votingpower und das Datum des letzten Votes. Dabei gibt die Votingpower an, wie viel man nach dem letzten Post hatte.

Somit müssen wir berechnen, wie viel VotePower der User inzwischen hat.
Pro Tag werden 20% VotePower aufgefüllt, pro 100% Vote werden 2% Vote Power abgezogen.

Ihr könnt am Tag also 10 Votes mit 100% geben, die dann aufgefüllt werden, oder 20 Votes mit 50%.

  function getVotingPower(t) {
  console.log(t.voting_power);
          var e = t.voting_power,
              s = new Date(t.last_vote_time + "Z"),
              a = (new Date() - s) / 1e3,
              r = Math.round((1e4 * a) / 432e3)
              
          return  Math.min(Math.min(e + r, 1e4)/100,100);
        }

Damit man also die korrekte VotingPower bekommt, muss man errechnen wie viel Power seit dem letzten Vote wieder dazugekommen ist "r" und dies zur VotingPower nach dem letzten Vote "e" hinzuaddieren.

Die Funktion habe ich irgendwo übrigens gefunden, da wäre ich nicht ganz so schnell selber drauf gekommen.

Den ganzen Code findet ihr in dem Beispiel hier.

Wer Fragen hat, kann gern ein Kommentar da lassen. Am besten @mein-senf-dazu erwähnen, damit ich es mitbekomme.

EN

In my last post, which was a few days ago, I showed how to retrieve information about Witnesse and how to vote for it.

Today there is a really short example code how to get the hive power from a user. For this we need once again the function hive.api.getAccounts, because in the account data we find the votingpower and the date of the last vote. Thereby the votingpower indicates how much one had after the last post.

So we have to calculate how much VotePower the user has in the meantime.
Per day 20% VotePower will be added, per 100% Vote 2% VotePower will be subtracted.

So you can give 10 votes with 100%, which will be filled up, or 20 votes with 50%.

  function getVotingPower(t) {
  console.log(t.voting_power);
          var e = t.voting_power,
              s = new Date(t.last_vote_time + "Z"),
              a = (new Date() - s) / 1e3,
              r = Math.round((1e4 * a) / 432e3)
              
          return Math.min(Math.min(e + r, 1e4)/100,100);
        }

So to get the correct VotingPower, you have to calculate how much power has been added since the last vote "r" and add this to the VotingPower after the last vote "e".

By the way, I found this function somewhere, I wouldn't have figured it out so fast by myself.

You can find the whole code in the example here.

If you have any questions, feel free to leave a comment. It's best to mention @mein-senf-dazu, so I get it.

Translated with www.DeepL.com/Translator (free version)



0
0
0.000
3 comments
avatar

Congratulations @hive-coding! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 1500 upvotes.
Your next target is to reach 1750 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

Update For Regular Content Creators - New Yearly Author Badge
PUD - PUH - PUM - It's all about Power Up!
The Hive Gamification Proposal Renewal
Support the HiveBuzz project. Vote for our proposal!
0
0
0.000