コンテンツにスキップ

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

「Module:MemberStats」の版間の差分

今日も推しが尊いですね。― ハロプロ・サブスク非公式リンク集
編集の要約なし
編集の要約なし
1行目: 1行目:
local p = {}
local p = {}


-- 今日の日付をMediaWikiマジックワードで取得
-- メンバーの誕生日を一時的に蓄積するテーブル
local function getTodayYmd()
local birthDates = {}
     local frame = mw.getCurrentFrame()
 
     local todayStr = frame:preprocess("{{CURRENTYEAR}}{{CURRENTMONTH}}{{CURRENTDAY}}"-- 例: 20260220
-- 表の各行(MemberRow)から誕生日を受け取って蓄積する関数
    return tonumber(todayStr)
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
end


function p.averageAge(frame)
-- 蓄積されたデータから統計を出すメイン関数
     local args = frame.args
function p.getStats(frame)
     local mode = frame.args[1] -- "count" か "average"
     local totalAge = 0
     local totalAge = 0
     local count = 0
     local count = #birthDates
     local today = getTodayYmd()   -- os.dateの代わり
   
    local todayStr = frame:preprocess("{{CURRENTYEAR}}{{CURRENTMONTH}}{{CURRENTDAY}}")
     local today = tonumber(todayStr)


     if not today then
     if count == 0 then return "0" end
        return "日付取得エラー"
    end


     for _, birthStr in ipairs(args) do
     for _, birth in ipairs(birthDates) do
         local birth = tonumber(birthStr)
         local age = math.floor((today - birth) / 10000)
        if birth and birth >= 19000101 and birth <= today then
        totalAge = totalAge + age
            -- 正確な年齢計算(誕生日が過ぎているかを考慮)
            local birthYear  = math.floor(birth / 10000)
            local birthMonth = math.floor((birth % 10000) / 100)
            local birthDay  = birth % 100
 
            local todayYear  = math.floor(today / 10000)
            local todayMonth = math.floor((today % 10000) / 100)
            local todayDay  = today % 100
 
            local age = todayYear - birthYear
            if todayMonth < birthMonth or (todayMonth == birthMonth and todayDay < birthDay) then
                age = age - 1
            end
 
            totalAge = totalAge + age
            count = count + 1
        end
     end
     end


     if count == 0 then return "0" end
     if mode == "count" then
 
        return count
     local avg = totalAge / count
     elseif mode == "average" then
    return string.format("%.2f", avg)
        return string.format("%.2f", totalAge / count)
end
 
function p.count(frame)
    local count = 0
    for _ in pairs(frame.args) do  -- ipairsではなくpairsで安全
        count = count + 1
     end
     end
    return count
end
end


return p
return p

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

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