From ef820b584e0a71c39f104660c3eab4b051c55b50 Mon Sep 17 00:00:00 2001 From: "Riley L." Date: Sun, 3 Nov 2024 22:23:21 +0100 Subject: [PATCH] sort users based on most recent action rather than lua table randomness --- abrechenbarkeit.lua | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/abrechenbarkeit.lua b/abrechenbarkeit.lua index e702935..00b4f11 100755 --- a/abrechenbarkeit.lua +++ b/abrechenbarkeit.lua @@ -166,6 +166,34 @@ local function last_txns() return users end +local function get_active_users() + local user_balances = {} + for time, username, amount, _, _, _ in read_log() do + user_balances[username] = { + time = time, + username = username, + balance = (user_balances[username] or {balance = 0}).balance + amount + } + end + + local users = {} + for _, user in pairs(user_balances) do + table.insert(users, user) + end + + table.sort(users, function(a,b) return a.time > b.time end) + for k, user in pairs(users) do + io.stderr:write(string.format("%s %s %s %s\n", + k, + os.date("!%Y-%m-%dT%H:%M:%SZ", user.time), + user.username, + user.balance + )) + end + + return users +end + local function error_box(message) return string.format([[

Error: %s

]], message) end @@ -339,17 +367,18 @@ local function r_index()

User Creation

- + ]]) print("")