Module:MemberStats
表示
local p = {}
function p.getStats(frame)
local mode = frame.args[1] -- "count" か "average" -- 現在のページのソースコードを取得 local title = mw.title.getCurrentTitle() local content = title:getContent() if not content then return "ページ内容が取得できません" end
-- 今日の日付
local todayStr = frame:preprocess("2026041")
local today = tonumber(todayStr)
local totalAge = 0 local count = 0
-- ページ内から「生年月日順=8桁数字」をすべて抽出して計算
for birthStr in content:gmatch("生年月日順%s*=%s*(%d%d%d%d%d%d%d%d)") do
local birth = tonumber(birthStr)
if birth then
local age = math.floor((today - birth) / 10000)
totalAge = totalAge + age
count = count + 1
end
end
if count == 0 then return "0" end
if mode == "count" then
return count
else
return string.format("%.2f", totalAge / count)
end
end
return p