reward errything again, fix reward parameters

This commit is contained in:
keyan 2023-09-18 17:48:05 -05:00
parent d00de65e9b
commit b0737e53d1
2 changed files with 13 additions and 9 deletions

View File

@ -25,8 +25,8 @@ export default {
WITH days_cte (day) AS (
SELECT date_trunc('day', t)
FROM generate_series(
COALESCE(${when?.[0]}::timestamp - interval '1 day', now() AT TIME ZONE 'America/Chicago'),
COALESCE(${when?.[when.length - 1]}::timestamp - interval '1 day', now() AT TIME ZONE 'America/Chicago'),
COALESCE(${when?.[0]}::text::timestamp - interval '1 day', now() AT TIME ZONE 'America/Chicago'),
COALESCE(${when?.[when.length - 1]}::text::timestamp - interval '1 day', now() AT TIME ZONE 'America/Chicago'),
interval '1 day') AS t
)
SELECT coalesce(FLOOR(sum(sats)), 0) as total,
@ -82,8 +82,8 @@ export default {
WITH days_cte (day) AS (
SELECT date_trunc('day', t)
FROM generate_series(
${when[0]}::timestamp,
${when[when.length - 1]}::timestamp,
${when[0]}::text::timestamp,
${when[when.length - 1]}::text::timestamp,
interval '1 day') AS t
)
SELECT coalesce(sum(sats), 0) as total, json_agg("Earn".*) as rewards

View File

@ -1,8 +1,8 @@
const serialize = require('../api/resolvers/serial')
const { ANON_USER_ID } = require('../lib/constants')
// const ITEM_EACH_REWARD = 3.0
// const UPVOTE_EACH_REWARD = 6.0
const ITEM_EACH_REWARD = 4.0
const UPVOTE_EACH_REWARD = 4.0
const TOP_PERCENTILE = 33
const TOTAL_UPPER_BOUND_MSATS = 1000000000
const REDUCE_REWARDS = [616, 6030, 946, 4502]
@ -119,9 +119,13 @@ function earn ({ models }) {
JOIN users on "userId" = users.id
GROUP BY "userId", "parentId" IS NULL
)
SELECT "userId", id, type, rank, ratio/2.0 as proportion
FROM item_ratios
ORDER BY type, rank ASC`
SELECT "userId", NULL as id, type, ROW_NUMBER() OVER (PARTITION BY "isPost" ORDER BY upvoter_ratio DESC) as rank,
upvoter_ratio/(sum(upvoter_ratio) OVER (PARTITION BY "isPost"))/${UPVOTE_EACH_REWARD} as proportion
FROM upvoter_ratios
WHERE upvoter_ratio > 0
UNION ALL
SELECT "userId", id, type, rank, ratio/${ITEM_EACH_REWARD} as proportion
FROM item_ratios`
// in order to group earnings for users we use the same createdAt time for
// all earnings