From f47a70f50e67353f4c3e032867ac2fc3b266cc9f Mon Sep 17 00:00:00 2001 From: k00b Date: Tue, 17 Dec 2024 14:15:47 -0600 Subject: [PATCH] untested rewards/leaderboard changes --- api/resolvers/rewards.js | 2 +- api/resolvers/user.js | 2 +- api/typeDefs/user.js | 2 +- components/user-list.js | 8 ++++---- pages/rewards/index.js | 8 ++++---- worker/earn.js | 13 ++++++------- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/api/resolvers/rewards.js b/api/resolvers/rewards.js index 3dcfd2c25..a65ebc43e 100644 --- a/api/resolvers/rewards.js +++ b/api/resolvers/rewards.js @@ -157,7 +157,7 @@ export default { const [{ to, from }] = await models.$queryRaw` SELECT date_trunc('day', (now() AT TIME ZONE 'America/Chicago')) AT TIME ZONE 'America/Chicago' as from, (date_trunc('day', (now() AT TIME ZONE 'America/Chicago')) AT TIME ZONE 'America/Chicago') + interval '1 day - 1 second' as to` - return await topUsers(parent, { when: 'custom', to: new Date(to).getTime().toString(), from: new Date(from).getTime().toString(), limit: 100 }, { models, ...context }) + return await topUsers(parent, { when: 'custom', to: new Date(to).getTime().toString(), from: new Date(from).getTime().toString(), limit: 500 }, { models, ...context }) }, total: async (parent, args, { models }) => { if (!parent.total) { diff --git a/api/resolvers/user.js b/api/resolvers/user.js index e836b22be..ef53de638 100644 --- a/api/resolvers/user.js +++ b/api/resolvers/user.js @@ -70,7 +70,7 @@ export async function topUsers (parent, { cursor, when, by, from, to, limit = LI } const users = (await models.$queryRawUnsafe(` - SELECT * + SELECT *, ${column === 'proportion' ? 'proportion' : ''} FROM (SELECT users.*, COALESCE(floor(sum(msats_spent)/1000), 0) as spent, diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js index 8b100170f..ed8b17418 100644 --- a/api/typeDefs/user.js +++ b/api/typeDefs/user.js @@ -58,7 +58,7 @@ export default gql` bioId: Int photoId: Int since: Int - + proportion: Float optional: UserOptional! privates: UserPrivates diff --git a/components/user-list.js b/components/user-list.js index 40f77286f..90be34f8e 100644 --- a/components/user-list.js +++ b/components/user-list.js @@ -107,13 +107,13 @@ export function User ({ user, rank, statComps, className = 'mb-2', Embellish, ny
{statComps.map((Comp, i) => )}
} - {Embellish && } + {Embellish && } ) } -function UserHidden ({ rank, Embellish }) { +function UserHidden ({ rank, user, Embellish }) { return ( <> {rank @@ -133,7 +133,7 @@ function UserHidden ({ rank, Embellish }) {
stacker is in hiding
- {Embellish && } + {Embellish && } @@ -148,7 +148,7 @@ export function ListUsers ({ users, rank, statComps = DEFAULT_STAT_COMPONENTS, E {users.map((user, i) => ( user ? - : + : ))} ) diff --git a/pages/rewards/index.js b/pages/rewards/index.js index 164710f4c..3176ada97 100644 --- a/pages/rewards/index.js +++ b/pages/rewards/index.js @@ -16,7 +16,6 @@ import { useToast } from '@/components/toast' import { useLightning } from '@/components/lightning' import { ListUsers } from '@/components/user-list' import { Col, Row } from 'react-bootstrap' -import { proportions } from '@/lib/madness' import { useData } from '@/components/use-data' import { GrowthPieChartSkeleton } from '@/components/charts-skeletons' import { useMemo } from 'react' @@ -50,6 +49,7 @@ ${ITEM_FULL_FIELDS} photoId ncomments nposts + proportion optional { streak @@ -117,9 +117,9 @@ export default function Rewards ({ ssrData }) { if (!dat) return - function EstimatedReward ({ rank }) { - const referrerReward = Math.floor(total * proportions[rank - 1] * 0.2) - const reward = Math.floor(total * proportions[rank - 1]) - referrerReward + function EstimatedReward ({ rank, user }) { + const referrerReward = Math.max(Math.floor(total * user.proportion * 0.2), 0) + const reward = Math.max(Math.floor(total * user.proportion) - referrerReward, 0) return (
diff --git a/worker/earn.js b/worker/earn.js index 630342597..bfb5348f4 100644 --- a/worker/earn.js +++ b/worker/earn.js @@ -1,6 +1,5 @@ import { notifyEarner } from '@/lib/webPush' import createPrisma from '@/lib/create-prisma' -import { proportions } from '@/lib/madness' import { SN_NO_REWARDS_IDS } from '@/lib/constants' const TOTAL_UPPER_BOUND_MSATS = 1_000_000_000 @@ -40,15 +39,15 @@ export async function earn ({ name }) { /* How earnings (used to) work: - 1/3: top 21% posts over last 36 hours, scored on a relative basis - 1/3: top 21% comments over last 36 hours, scored on a relative basis + 1/3: top 50% posts over last 36 hours, scored on a relative basis + 1/3: top 50% comments over last 36 hours, scored on a relative basis 1/3: top upvoters of top posts/comments, scored on: - their trust - how much they tipped - how early they upvoted it - how the post/comment scored - Now: 80% of earnings go to top 100 stackers by value, and 10% each to their forever and one day referrers + Now: 80% of earnings go to top stackers by relative value, and 10% each to their forever and one day referrers */ // get earners { userId, id, type, rank, proportion, foreverReferrerId, oneDayReferrerId } @@ -63,8 +62,8 @@ export async function earn ({ name }) { 'day') uv JOIN users ON users.id = uv.id WHERE NOT (users.id = ANY (${SN_NO_REWARDS_IDS})) + AND uv.proportion > 0.00000001 ORDER BY proportion DESC - LIMIT 100 ) SELECT earners.*, COALESCE( @@ -86,10 +85,10 @@ export async function earn ({ name }) { let total = 0 const notifications = {} - for (const [i, earner] of earners.entries()) { + for (const [earner] of earners.entries()) { const foreverReferrerEarnings = Math.floor(parseFloat(earner.proportion * sum * 0.1)) // 10% of earnings let oneDayReferrerEarnings = Math.floor(parseFloat(earner.proportion * sum * 0.1)) // 10% of earnings - const earnerEarnings = Math.floor(parseFloat(proportions[i] * sum)) - foreverReferrerEarnings - oneDayReferrerEarnings + const earnerEarnings = Math.floor(parseFloat(earner.proportion * sum)) - foreverReferrerEarnings - oneDayReferrerEarnings total += earnerEarnings + foreverReferrerEarnings + oneDayReferrerEarnings if (total > sum) {