mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-11 01:15:49 +08:00
87b89e0d57
* Add weekly seasons * Fix test * Add week timestamp tests * Add unit tests * Fix weeks before calculation * Update user.spec.ts * Remove minXp maxXp reward config * Record total time typed + last activity timestamp * Season -> Weekly XP Leaderboard * prettier * Add config hints * Update leaderboard.ts * monkeytype Co-authored-by: Miodec <jack@monkeytype.com>
24 lines
710 B
Lua
24 lines
710 B
Lua
local redis_call = redis.call
|
|
local leaderboard_scores_key, leaderboard_results_key = KEYS[1], KEYS[2]
|
|
|
|
local min_rank = tonumber(ARGV[1])
|
|
local max_rank = tonumber(ARGV[2])
|
|
local include_scores = ARGV[3]
|
|
|
|
local results = {}
|
|
local scores = {}
|
|
local scores_in_range = redis_call('ZRANGE', leaderboard_scores_key, min_rank, max_rank, 'REV')
|
|
|
|
for _, user_id in ipairs(scores_in_range) do
|
|
local result_data = redis_call('HGET', leaderboard_results_key, user_id)
|
|
|
|
if (include_scores == "true") then
|
|
scores[#scores + 1] = redis_call('ZSCORE', leaderboard_scores_key, user_id)
|
|
end
|
|
|
|
if (result_data ~= nil) then
|
|
results[#results + 1] = result_data
|
|
end
|
|
end
|
|
|
|
return {results, scores}
|