コンテンツにスキップ

現在、全3219曲を聴きながらリンク集を作成中のサグラダ・ファミリア サイトです。
情報の誤りやお問い合わせは、管理人 X までお寄せください。
✨ オススメのプレイリストやセトリを教えて下さい ✨

「Module:MemberStats」の版間の差分

今日も推しが尊いですね。― ハロプロ・サブスク非公式リンク集
編集の要約なし
編集の要約なし
 
1行目: 1行目:
local p = {}
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)
function p.getStats(frame)
     local mode = frame.args[1] -- "count" か "average"
     local mode = frame.args[1] -- "count" か "average"
    local totalAge = 0
    local count = #birthDates
      
      
    -- 現在のページのソースコードを取得
    local title = mw.title.getCurrentTitle()
    local content = title:getContent()
    if not content then return "ページ内容が取得できません" end
    -- 今日の日付
     local todayStr = frame:preprocess("{{CURRENTYEAR}}{{CURRENTMONTH}}{{CURRENTDAY}}")
     local todayStr = frame:preprocess("{{CURRENTYEAR}}{{CURRENTMONTH}}{{CURRENTDAY}}")
     local today = tonumber(todayStr)
     local today = tonumber(todayStr)


     if count == 0 then return "0" end
     local totalAge = 0
    local count = 0


     for _, birth in ipairs(birthDates) do
    -- ページ内から「生年月日順=8桁数字」をすべて抽出して計算
         local age = math.floor((today - birth) / 10000)
     for birthStr in content:gmatch("生年月日順%s*=%s*(%d%d%d%d%d%d%d%d)") do
        totalAge = totalAge + age
         local birth = tonumber(birthStr)
        if birth then
            local age = math.floor((today - birth) / 10000)
            totalAge = totalAge + age
            count = count + 1
        end
     end
     end


    if count == 0 then return "0" end
     if mode == "count" then
     if mode == "count" then
         return count
         return count
     elseif mode == "average" then
     else
         return string.format("%.2f", totalAge / count)
         return string.format("%.2f", totalAge / count)
     end
     end

2026年2月20日 (金) 11:13時点における最新版

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