「モジュール:SMWメンバー情報」の版間の差分

提供:エケペディア
ナビゲーションに移動 検索に移動
編集の要約なし
(setPropertyはこの場所にも置くべきだったのか?)
タグ: 手動差し戻し
 
(同じ利用者による、間の7版が非表示)
26行目: 26行目:
   local dataStore = {}
   local dataStore = {}
   dataStore["主チーム"] = args["チーム"] or ""
   dataStore["主チーム"] = args["チーム"] or ""
   dataStore["主な元グループ"] = args["チーム"] or ""
   dataStore["主な元グループ"] = args["元グループ"] or ""
  dataStore["主チーム"] = args["チーム"] or ""
   dataStore["出身地"] = args["出身地"] or ""
   dataStore["出身地"] = args["出身地"] or ""
   dataStore["生年月日"] = args["生年月日"] or ""
   dataStore["生年月日"] = args["生年月日"] or ""
62行目: 61行目:
   dataStore["選抜回数"] = {}
   dataStore["選抜回数"] = {}


   local lines = mw.text.split(args["選抜回数"]or "", '<br>')
   local lines_s = mw.text.split(args["選抜回数"] or "", '<br>')
   mw.logObject(lines)
   mw.logObject(lines_s)
   local total = 0
   local total_s = 0
   -- Iterate over the lines
   -- Iterate over the lines_s
   for _, line in ipairs(lines) do
   for _, line in ipairs(lines_s) do
       local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
       local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
       mw.logObject(mw.ustring.match(line, "(.+) (%d+)回"))
       mw.logObject(mw.ustring.match(line, "(.+) (%d+)回"))
       -- If the group is not extracted, use the provided group
       -- If the group is not extracted, use the provided group
       if not extractedGroup or extractedGroup == "" then
       if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["グループ"] or ""
         extractedGroup = args["元グループ"] or args["グループ"] or ""
       end
       end
       -- If the num is nil, return an error
       -- If the num is nil, return an error
78行目: 77行目:
       end
       end
       -- Store the group and selection times
       -- Store the group and selection times
       total = total + tonumber(num)
       if tonumber(num) > 0 then
      table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
        total_s = total_s + tonumber(num)
        table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
      end
  end
  -- Add the total selection times to the dataStore
  dataStore["選抜回数合計"] = total_s
 
  -- センター回数
  dataStore["選抜回数"] = {}
 
  local lines_c = mw.text.split(args["センター回数"] or "", '<br>')
  mw.logObject(lines_c)
  local total_c = 0
  -- Iterate over the lines_c
  for _, line in ipairs(lines_c) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      mw.logObject(mw.ustring.match(line, "(.+) (%d+)回"))
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
        extractedGroup = args["元グループ"] or args["グループ"] or ""
      end
      -- If the num is nil, return an error
      if not num then
        return nil, "Unable to extract number from line: " .. line
      end
      -- Store the group and selection times
      if  tonumber(num) > 0 then
        total_c = total_c + tonumber(num)
        table.insert(dataStore["センター回数"], extractedGroup .. ';' .. num)
      end
   end
   end
   -- Add the total selection times to the dataStore
   -- Add the total selection times to the dataStore
   dataStore["選抜回数合計"] = total
   if total_c > 0 then
    dataStore["センター回数合計"] = total_c
  end


   local generation = ''
   local generation = ''
91行目: 121行目:
   local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:メンバー情報', removeBlanks = false, parentFirst = true });
   local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:メンバー情報', removeBlanks = false, parentFirst = true });
   local dataStore = {}
   local dataStore = {}
   -- 選抜回数
   -- 選抜回数
   dataStore["選抜回数"] = {}
   dataStore["選抜回数"] = {}


   local lines = mw.text.split(args["選抜回数"]or "", '<br>')
   local lines_s = mw.text.split(args["選抜回数"] or "", '<br>')
   mw.logObject(lines)
   mw.logObject(lines_s)
   local total = 0
   local total_s = 0
   -- Iterate over the lines
  -- Iterate over the lines_s
   for _, line in ipairs(lines) do
  for _, line in ipairs(lines_s) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
        extractedGroup = args["元グループ"] or args["グループ"] or ""
        num = mw.ustring.match(line, "(%d+)回")
      end
      -- If the num is nil, return an error
      if not num then
        return nil, "Unable to extract number from line: " .. line
      end
      -- Store the group and selection times
      if tonumber(num) > 0 then
        total_s = total_s + tonumber(num)
        table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
      end
  end
  -- Add the total selection times to the dataStore
  dataStore["選抜回数合計"] = total_s
  setProperty(dataStore);
 
  -- センター回数
  dataStore["センター回数"] = {}
 
  local lines_c = mw.text.split(args["センター回数"] or "", '<br>')
  mw.logObject(lines_c)
  local total_c = 0
   -- Iterate over the lines_c
   for _, line in ipairs(lines_c) do
       local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
       local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
       -- If the group is not extracted, use the provided group
       -- If the group is not extracted, use the provided group
       if not extractedGroup or extractedGroup == "" then
       if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["グループ"] or ""
         extractedGroup = args["元グループ"] or args["グループ"] or ""
         num = mw.ustring.match(line, "(%d+)回")
         num = mw.ustring.match(line, "(%d+)回")
       end
       end
110行目: 169行目:
       end
       end
       -- Store the group and selection times
       -- Store the group and selection times
       total = total + tonumber(num)
       if tonumber(num) > 0 then
      table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
        total_c = total_c + tonumber(num)
        table.insert(dataStore["センター回数"], extractedGroup .. ';' .. num)
      end
   end
   end
   -- Add the total selection times to the dataStore
   -- Add the total selection times to the dataStore
   dataStore["選抜回数合計"] = total
 
   if total_c > 0 then
    dataStore["センター回数合計"] = total_c
  end
 
   setProperty(dataStore);
   setProperty(dataStore);
   return nil;
   return nil;
end
end


return p
return p

2023年10月1日 (日) 07:48時点における最新版

このモジュールについての説明文ページを モジュール:SMWメンバー情報/doc に作成できます

local p = {}

local function setProperty(dataStore)
   -- メイン空間のみ
   if not mw.title.getCurrentTitle().namespace == 0 then
      return true;
   end

   if not mw.smw then
      return true;
   end

   local result = mw.smw.set( dataStore )

   if result == true then
      -- everything ok
   else
      -- error message to be found in result.error
   end
end

local function test(frame)
   local args = frame.args
   --local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:メンバー情報', removeBlanks = false, parentFirst = true });

   local dataStore = {}
   dataStore["主チーム"] = args["チーム"] or ""
   dataStore["主な元グループ"] = args["元グループ"] or ""
   dataStore["出身地"] = args["出身地"] or ""
   dataStore["生年月日"] = args["生年月日"] or ""
   dataStore["血液型"] = mw.text.unstrip(args["血液型"] or "")
   dataStore["合格期"] = args["合格期"] or ""
   dataStore["名前"] = args["名前"] or ""
   dataStore["読み"] = args["読み"] or ""
   dataStore["公式ニックネーム"] = args["公式ニックネーム"] or ""
   dataStore["所属事務所"] = args["所属事務所"] or ""
   dataStore["身長"] = mw.text.unstrip(args["身長"] or "")
   dataStore["お披露目日"] = args["お披露目日"] or ""
   dataStore["卒業発表日"] = args["卒業発表日"] or ""
   dataStore["最終活動日"] = args["最終活動日"] or ""
   dataStore["昇格日"] = args["昇格日"] or ""
   -- グループの処理
   local group_keys = {"グループ", "グループ2", "グループ3"}
   dataStore["グループ"] = {}
   for _, key in ipairs(group_keys) do
      local group_value = args[key]
      if group_value and group_value ~= "" then
         table.insert(dataStore["グループ"], group_value)
      end
   end
   -- チームの処理
   local team_keys = {"チーム", "チーム2", "チーム3"}
   dataStore["チーム"] = {}
   for _, key in ipairs(team_keys) do
      local team_value = args[key]
      if team_value and team_value ~= "" then
         table.insert(dataStore["チーム"], team_value)
      end
   end
   -- 選抜回数
   dataStore["選抜回数"] = {}

   local lines_s = mw.text.split(args["選抜回数"] or "", '<br>')
   mw.logObject(lines_s)
   local total_s = 0
   -- Iterate over the lines_s
   for _, line in ipairs(lines_s) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      mw.logObject(mw.ustring.match(line, "(.+) (%d+)回"))
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["元グループ"] or args["グループ"] or ""
      end
      -- If the num is nil, return an error
      if not num then
         return nil, "Unable to extract number from line: " .. line
      end
      -- Store the group and selection times
      if tonumber(num) > 0 then
        total_s = total_s + tonumber(num)
        table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
      end
   end
   -- Add the total selection times to the dataStore
   dataStore["選抜回数合計"] = total_s

   -- センター回数
   dataStore["選抜回数"] = {}

   local lines_c = mw.text.split(args["センター回数"] or "", '<br>')
   mw.logObject(lines_c)
   local total_c = 0
   -- Iterate over the lines_c
   for _, line in ipairs(lines_c) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      mw.logObject(mw.ustring.match(line, "(.+) (%d+)回"))
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["元グループ"] or args["グループ"] or ""
      end
      -- If the num is nil, return an error
      if not num then
         return nil, "Unable to extract number from line: " .. line
      end
      -- Store the group and selection times
      if  tonumber(num) > 0 then
        total_c = total_c + tonumber(num)
        table.insert(dataStore["センター回数"], extractedGroup .. ';' .. num)
      end
   end
   -- Add the total selection times to the dataStore
   if total_c > 0 then
     dataStore["センター回数合計"] = total_c
   end

   local generation = ''
   return dataStore;
end

function p.main(frame)
   local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:メンバー情報', removeBlanks = false, parentFirst = true });
   local dataStore = {}

   -- 選抜回数
   dataStore["選抜回数"] = {}

   local lines_s = mw.text.split(args["選抜回数"] or "", '<br>')
   mw.logObject(lines_s)
   local total_s = 0
   -- Iterate over the lines_s
   for _, line in ipairs(lines_s) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["元グループ"] or args["グループ"] or ""
         num = mw.ustring.match(line, "(%d+)回")
      end
      -- If the num is nil, return an error
      if not num then
         return nil, "Unable to extract number from line: " .. line
      end
      -- Store the group and selection times
      if tonumber(num) > 0 then
        total_s = total_s + tonumber(num)
        table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
      end
   end
   -- Add the total selection times to the dataStore
   dataStore["選抜回数合計"] = total_s
   setProperty(dataStore);

   -- センター回数
   dataStore["センター回数"] = {}

   local lines_c = mw.text.split(args["センター回数"] or "", '<br>')
   mw.logObject(lines_c)
   local total_c = 0
   -- Iterate over the lines_c
   for _, line in ipairs(lines_c) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["元グループ"] or args["グループ"] or ""
         num = mw.ustring.match(line, "(%d+)回")
      end
      -- If the num is nil, return an error
      if not num then
         return nil, "Unable to extract number from line: " .. line
      end
      -- Store the group and selection times
      if tonumber(num) > 0 then
        total_c = total_c + tonumber(num)
        table.insert(dataStore["センター回数"], extractedGroup .. ';' .. num)
      end
   end
   -- Add the total selection times to the dataStore

   if total_c > 0 then
     dataStore["センター回数合計"] = total_c
   end

   setProperty(dataStore);

   return nil;
end

return p