monkeytype/backend/redis-scripts/get-results.lua
Bruce Berrios 87b89e0d57
Add weekly xp leaderboards backend (#3511) Bruception
* 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>
2022-11-28 14:10:02 +01:00

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}