Module:MemberStats
表示
local p = {}
-- メンバーの誕生日を一時的に蓄積するテーブル local birthDates = {}
-- 表の各行(MemberRow)から誕生日を受け取って蓄積する関数 function p.addMember(frame)
local birth = frame.args[1] or frame.args['生年月日順']
if birth and tonumber(birth) then
table.insert(birthDates, tonumber(birth))
end
return "" -- 画面には何も表示しない
end
-- 蓄積されたデータから統計を出すメイン関数 function p.getStats(frame)
local mode = frame.args[1] -- "count" か "average"
local totalAge = 0
local count = #birthDates
local todayStr = frame:preprocess("2026041")
local today = tonumber(todayStr)
if count == 0 then return "0" end
for _, birth in ipairs(birthDates) do
local age = math.floor((today - birth) / 10000)
totalAge = totalAge + age
end
if mode == "count" then
return count
elseif mode == "average" then
return string.format("%.2f", totalAge / count)
end
end
return p