Module:MemberStats
表示
local p = {}
function p.averageAge(frame)
local args = frame.args
local totalAge = 0
local count = 0
-- 今日の日付を取得 (YYYYMMDD)
local today = tonumber(os.date("%Y%m%d"))
-- 引数から生年月日をスキャン
for _, birthStr in ipairs(args) do
local birth = tonumber(birthStr)
if birth then
-- 年齢計算ロジック: floor((今日 - 誕生日) / 10000)
local age = math.floor((today - birth) / 10000)
totalAge = totalAge + age
count = count + 1
end
end
if count == 0 then return "0" end
-- 平均を出して小数第2位で丸める
local avg = totalAge / count
return string.format("%.2f", avg)
end
function p.count(frame)
local count = 0
for _, _ in ipairs(frame.args) do
count = count + 1
end
return count
end
return p