Actifit Task: Nodejs Automated Delegation Rewards Calculation

in #utopian-io6 years ago

Repository

https://github.com/mcfarhat/actifit-bot

Details

We had recently created our nodejs script that handles automating the daily Actifit rewards and upvotes, but also the calculation and storing of relevant rewards for actifiters (check out recent task request which was successfully completed).

My next task on the same line requires automating a rather time consuming item that I need to get performed on a weekly basis, being the calculation of delegator rewards for the past week, storing those in the database, as well as calculating the steem-based rewards for those accounts based on actifit posts for the week before.

Part A: Actifit Weekly Reward Calculation

So the process would go as follows:

  • The script would need to run once per week, at the beginning of the new week (Monday 00:01 server time)
  • The script would need to grab all current @actifit account delegators/delegation history for this past week, prior Monday 00:01 up till Sunday 23:59).
  • By saying history, we need to be accurate as delegations are prone to increase and decrease throughout the week. So one delegator might have started from the prior week with 100 SP delegation, and then increased his delegation for example on Wednesday to 200 SP, then a second time increased on Saturday to 300 SP, a different scenario could be a delegator who started a delegation before and cancelled his delegation within the week, or a delegator who started a delegation within the week and cancelled it before the week concludes. Those are just examples of scenarios we need to consider just so as we do not miss rewarding any of our delegators.
  • After grabbing the current delegator list, along with the delegation history for the past week, we need to perform the following:
  1. For every day that has passed for each delegator, we need to assign an amount equal to the delegation in SP as a matching Actifit token reward. I.e., a delegator who delegated 100 SP on Tuesday within the day, will receive 100 Actifit tokens for that day, and for every subsequent day till Sunday EOD, with a max total of reward as 7x100 actifits/SP (for 1 week / 7 days). Please note that account @mcfarhat does not accrue actifit tokens and is to be excluded from this calculation
  2. If at one point in time, the delegation for the account increased, we will start using the new SP count for the new Actifit reward amount and accumulate on a daily basis the new SP amount.
  3. The total amount of tokens post calculation will need to be added as a transaction into the mongodb transaction database we currently have, with the following format:
    {
    "user": "delegator name", // account, without an @
    "reward_activity": "Delegation", //activity as delegation reward
    "token_count": 500, //calculated amount integer value
    "date": "2018-07-10T18:31:39", //date here according to format
    "note": "Delegation Reward Until EOD July 08 2018" //note of the delegation, update the date
    }
  4. A report needs to be generated with all the detailed data that can be sent via email.

Part B: Steem reward calculation

For this part, we need to calculate the STEEM rewards that need to be sent out to delegators:

  • We need to perform the same process as above, yet on one week earlier. Meaning we need to calculate all the SP for each delegator for the week which preceeds the last week. In this case, nothing needs to be stored, yet we just need to calculate the total number of SP per each delegator across the week.
  • After doing that, we need to calculate the total SP across all delegations.
  • Then we will need to calculate the total amount of beneficiary rewards that were accumulated for the @actifit.pay account by today EOD (script also runs once on a weekly basis on Monday 00:00:01).
  • Then we will need to divide this total amount of SP, by the total amount of delegated SP, to get the reward per single SP. Then we will multiply this amount of single SP by the actual weekly accrued SP per reach user to calculate the amount of reward each user should receive for this week.
  • So for example, if we had only 2 delegators, usera with 700 SP total per week (100 SP delegation) and userb with 350 SP total per week (50 SP delegation) two weeks ago, and @actifit.pay got 5 STEEM for the last week, then we will need to divide 5 / (700+350) to get x = the reward per SP, and then multiply 350 * x to get reward for userb and 700* x to get reward for usera
  • There will be no automated sending of Steem rewards for now.
  • A report will need to be generated with this and sent via email.

To confirm the script runs properly for both items above, we will manually perform a comparison for the numbers generated, against my actual excel sheet numbers.

Components

The above task is required to allow completing a part of the cycle for tracking and rewarding delegators for their Actifit support on a weekly basis.

Deadline

I would love for this to be completed the soonest, with deadline being on July 22nd, 2018. Can be a bit flexible on this although I would prefer to get it ready before my next manual work on this.

Bounty

In addition to the potential for a Utopian upvote, we will also reward the developer with 500 Actifit tokens as a bounty for a job well done.

Communication

If you have any questions or would like to contact me for further details on the task or on means of cooperation, feel free to either comment on this post, or reach out:

Github

https://github.com/mcfarhat

Sort:  

Thanks for the task request, @mcfarhat! Very descriptive - good luck finding someone!

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

I didn't go through all the details yet but I will tomorrow. Maybe I can help with this task too but I cannot promise anything.

@mcfarhat You have received a 100% upvote from @nothankyou because this post did not use any bidbots and you have not used bidbots in the last 30 days!

Upvoting this comment will help keep this service running.

Hey @mcfarhat
Thanks for contributing on Utopian.
We’re already looking forward to your next task request!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.15
TRX 0.12
JST 0.026
BTC 56787.81
ETH 2507.96
USDT 1.00
SBD 2.24