random rewards

This commit is contained in:
keyan 2023-10-04 15:56:18 -05:00
parent 502bfee072
commit b3e8280d76
1 changed files with 19 additions and 10 deletions

View File

@ -53,8 +53,13 @@ export function earn ({ models }) {
} }
const sum = Number(sumDecimal) const sum = Number(sumDecimal)
const heads = Math.random() < 0.5
// if this category is selected, double its proportion
// if it isn't select, zero its proportion
const itemRewardMult = heads ? 0 : 2.0
const upvoteRewardMult = heads ? 2.0 : 0
console.log(name, 'giving away', sum, 'msats') console.log(name, 'giving away', sum, 'msats', 'rewarding', heads ? 'items' : 'upvotes')
/* /*
How earnings (used to) work: How earnings (used to) work:
@ -66,7 +71,7 @@ export function earn ({ models }) {
- how early they upvoted it - how early they upvoted it
- how the post/comment scored - how the post/comment scored
Now: 100% of earnings go to top 21% of posts/comments Now: 100% of earnings go to either top 33% of comments/posts or top 33% of upvoters
*/ */
// get earners { userId, id, type, rank, proportion } // get earners { userId, id, type, rank, proportion }
@ -118,14 +123,18 @@ export function earn ({ models }) {
) u ) u
JOIN users on "userId" = users.id JOIN users on "userId" = users.id
GROUP BY "userId", "parentId" IS NULL GROUP BY "userId", "parentId" IS NULL
) ),
SELECT "userId", NULL as id, type, ROW_NUMBER() OVER (PARTITION BY "isPost" ORDER BY upvoter_ratio DESC) as rank, proportions AS (
upvoter_ratio/(sum(upvoter_ratio) OVER (PARTITION BY "isPost"))/${UPVOTE_EACH_REWARD} as proportion SELECT "userId", NULL as id, type, ROW_NUMBER() OVER (PARTITION BY "isPost" ORDER BY upvoter_ratio DESC) as rank,
FROM upvoter_ratios ${itemRewardMult}*upvoter_ratio/(sum(upvoter_ratio) OVER (PARTITION BY "isPost"))/${UPVOTE_EACH_REWARD} as proportion
WHERE upvoter_ratio > 0 FROM upvoter_ratios
UNION ALL WHERE upvoter_ratio > 0
SELECT "userId", id, type, rank, ratio/${ITEM_EACH_REWARD} as proportion UNION ALL
FROM item_ratios` SELECT "userId", id, type, rank, ${upvoteRewardMult}*ratio/${ITEM_EACH_REWARD} as proportion
FROM item_ratios)
SELECT "userId", id, type, rank, proportion
FROM proportions
WHERE proportion > 0.0001`
// in order to group earnings for users we use the same createdAt time for // in order to group earnings for users we use the same createdAt time for
// all earnings // all earnings