Fixed NaN vote error on the Utopian botsteemCreated with Sketch.

in #utopian-io7 years ago

image.png

While playing around with the new version of the Utopian bot, I noticed that the 'task-requests' where not upvoted, and couldn't seem to find why.

One of the posts I found to be non-upvoted in this category was actually pointing to a permlink that didn't exist but the others should have worked. After digging a bit, I realized what was going on:

  • Because the bot couldn't find that wrong permlink, it thought that this post had no upvote
  • At some point, the nb of upvotes is used in a division, and well. if you remember your maths lesson, dividing by zero is not a thing you want to do :

image.png

  • Dividing by zero cause a NaN result to the calculate (Not a Number) and therefore the post wilth the wrong permlink couldn't be upvoted. The one with the right permlink was already upvoted so @elear fixed this in the database.

Now, to understand what was going on with the other contributions and prevent this I had to dig a little bit more and realize that:

  • When calculating the votes pool for each categories, the votes are added to each other.
  • Only one NaN is sufficient to ruin it all and cause the reward pool for the category to become NaN.

Therefore, I made sure in this commit that if we get a null number of votes for a reason or another, we'll set it to one instead.

It will prevent this situation from happening again.

@stoodkev



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

[utopian-moderator]

something better ...

Hey @stoodkev I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.030
BTC 64768.36
ETH 3436.88
USDT 1.00
SBD 2.51