모듈:Team appearances list
이 모듈은 일반적으로 사용될 수 있는 등급이 매겨졌습니다. 이것은 발전된 형태에 도달하였으며 오류가 없고 어떤 상황에서도 적절하게 사용할 수 있다고 생각할 수 있습니다. 이것은 도움말 페이지에 멘션을 남길 준비가 되었고 새로운 사용자가 배우기 위한 다른 위키백과 자원입니다. 서버 로드와 잘못된 출력을 줄이기 위해서는, 반복적으로 시도와 오류발생하는 편집을 하기보다는 시험장 테스트를 통해서 발전시켜야 합니다. |
이 모듈은 {{선수단 참가 목록}}을 뒷받침하기 위한 것입니다. 틀 사용법은 틀 문서에 가셔서 설명란을 확인해주세요.
모듈
[편집]- 모듈:Team appearances list • 모듈:Team appearances list/연습장 • 존재하지 않음
- 모듈:Team appearances list/data • 모듈:Team appearances list/data/연습장 • 존재하지 않음
- 모듈:Team appearances list/show • 모듈:Team appearances list/show/연습장 • 존재하지 않음
모듈:Team appearances list은 특정 국가 선수단의 특정 대회 참가 연도를 일렬로 표시하기 위해 만들어진 {{선수단 참가 목록}}의 작동을 위한 모듈입니다. 각 연도마다 해당 문서로 연결되는 링크가 걸려 있으며, 불참한 대회는 링크가 걸리지 않고 회색으로 표시됩니다.
사용 시 대회 명칭과 국가명을 반드시 밝혀 적어야 합니다. 다만 모듈:Team appearances list/data 문서 적혀있는 대회 정보를 활용할 수 있고, 추가로 해당 국가의 참가여부에 관한 정보를 쓸 수 있습니다.
begin_year
- 최초 참가 연도부터 표시됩니다.end_year
- 마지막 참가 연도까지만 표시됩니다.(연도)
- 대회에 불참했던 연도들을 표시할 수 있습니다.
begin_year
나 end_year
가 쓰일 경우, 틀 내의 기본값에 이들 변수값이 적용되어 연도의 범위가 바뀔 수 있습니다.
If a team is defined for a particular competition, any absent years in the templace call are ignored (instead, the absences defined in the data module are used).
모듈:Team appearances list/show은 모듈 테스트에 쓰입니다. It shows the results for all competition/team pairs defined in the data module. The results are displayed at 모듈토론:Team appearances list/show.
Changes should be performed in the sandbox modules, using the following for testing:
- {{Team appearances list/sandbox}} – Uses the sandbox main and data modules.
- 모듈토론:Team appearances list/show – Results for all competition/team pairs defined in the sandbox data module.
오류
[편집]Parameters provided by the template are validated using the following rules.
Always: competition required : non-empty string team required : non-empty string If competition is defined in data module: begin_year optional : number from 1800 to 2100 inclusive end_year optional : as above (and end_year >= begin_year) else: begin_year required : as above end_year optional : as above interval required : number from 1 to 30 inclusive
유효하지 않은 parameter는 오류를 보이게 하고 문서를 숨은 분류인 분류:스크립트 오류가 포함된 문서에 배치시킵니다.
-- This module implements [[Template:Team appearances list]].
local p = {}
-- i18n support for Korean
local param_ko = {
['국가'] = 'team',
['선수단'] = 'team',
['대회'] = 'competition',
['첫참가'] = 'begin_year',
['마지막참가'] = 'end_year',
['연속'] = 'interval',
}
local data_competitions
local data_old_names
local function load_data(frame)
-- Load data module (or its sandbox) and set variables from its exported data.
if not data_competitions then
frame = frame or mw.getCurrentFrame()
local sandbox = frame:getTitle():find('연습장', 1, true) and '/연습장' or ''
local datamod = mw.loadData('모듈:Team appearances list/data' .. sandbox)
data_competitions = datamod.competitions
data_old_names = datamod.old_names
end
end
local function strip_to_nil(text)
-- If text is a string, return its trimmed content, or nil if empty.
-- Otherwise return text (which may, for example, be nil).
if type(text) == 'string' then
text = text:match('(%S.-)%s*$')
end
return text
end
local function make_options(args)
-- Return table of options from validated args or throw error.
local options = {}
local function valid_integer(name, min, max, is_optional)
local arg = args[name]
if arg == nil or arg == '' then
if is_optional then
return nil
end
error('' .. name .. ' 변수가 빠졌습니다')
end
arg = tonumber(arg)
if type(arg) ~= 'number' then
error('' .. name .. ' 변수에는 숫자가 들어가야 합니다')
end
if math.floor(arg) ~= arg then
error('' .. name .. ' 변수에는 정수가 들어가야 합니다')
end
if not (min <= arg and arg <= max) then
error('' .. name .. ' 변수가 유효하지 않습니다')
end
return arg
end
local function valid_text(name)
local arg = args[name]
if arg == nil or arg == '' then
error(name .. ' 변수가 빠졌습니다')
end
if type(arg) ~= 'string' then
error(name .. ' 변수는 문자열이 아닙니다')
end
return arg
end
-- i18n support for Korean
local function localname(parameter)
return param_ko[parameter] or parameter
end
local parent_args = args
for k, v in pairs(parent_args) do
if v ~= '' then
args[localname(k)] = v
end
end
options.competition = valid_text('competition')
options.team = valid_text('team')
options.competitions = data_competitions[options.competition] or data_competitions[data_old_names[options.competition]]
local begin_optional
if options.competitions then
begin_optional = true
else
options.interval = valid_integer('interval', 1, 30)
end
options.begin_year = valid_integer('begin_year', 1800, 2100, begin_optional)
options.end_year = valid_integer('end_year', 1800, 2100, true)
if options.begin_year and options.end_year then
if options.begin_year > options.end_year then
error('end_year 변수는 begin_year 보다 앞서지 않아야 합니다')
end
end
options.disqualified_year = valid_integer('disqualified_year', 1800, 2100, true)
return options
end
local function extract_range(text)
-- Return first (if text is a single year), or first, last if a range.
-- The returned values are numbers.
-- Return nothing if text is invalid.
local year = text:match('^(%d+)$')
if year then
if #year == 4 then
return tonumber(year)
end
return
end
local first, dash, last = text:match('^(%d+)(%D+)(%d+)$')
if not (first and #first == 4) then
return
end
dash = strip_to_nil(dash)
if not (dash == '-' or dash == '–') then
return
end
if #last ~= 4 then
if #last == 2 then
last = first:sub(1, 2) .. last
else
return
end
end
first = tonumber(first)
last = tonumber(last)
if first < last then
return first, last
elseif first == last then
return first
end
end
local function competition_absences(data)
-- Return two tables with absent years and absent year ranges.
-- Parameter data is an array of strings from template parameters, or
-- numbers or strings from built-in data.
-- Parameters that are blank or not numbers or strings are ignored.
local absent_years, absent_ranges = {}, {}
for _, item in ipairs(data) do
if type(item) == 'number' then
absent_years[item] = true
else
item = strip_to_nil(item)
if type(item) == 'string' then
local first, last = extract_range(item)
if not first then
error('연도 ' .. item .. ' 항목이 유효하지 않습니다')
end
if last then
table.insert(absent_ranges, {first, last})
else
absent_years[first] = true
end
end
end
end
return absent_years, absent_ranges
end
local function competition_information(args)
-- Return four tables with competition and team information:
-- * List of competition years that the team attended or could have attended.
-- * Table of disqualified years (the team was absent, but there is an
-- article regarding the absent year).
-- * Table of absent years (when the team did not attend).
-- * List of pairs of years (absent for each year in range, inclusive).
local options = make_options(args)
local absences
local comp_years = {}
local begin_year = options.begin_year
local end_year = options.end_year
local competitions = options.competitions
if competitions then
absences = competitions[options.team] or competitions[data_old_names[options.team]]
begin_year = begin_year or (absences and absences.begin_year) or 0
end_year = end_year or (absences and absences.end_year) or 9999
for _, y in ipairs(competitions) do
if y > end_year then
break
elseif y >= begin_year then
table.insert(comp_years, y)
end
end
else
end_year = end_year or (os.date('!*t').year + options.interval)
for y = begin_year, end_year, options.interval do
table.insert(comp_years, y)
end
end
local disqualified_years = {}
if options.disqualified_year then
-- Input currently only allows entry of a single disqualified year.
-- However processing works for any number of such years.
disqualified_years[options.disqualified_year] = true
end
return comp_years, disqualified_years, competition_absences(absences or args)
end
local function gameName(year, inputName)
-- Modifies output of display being sent back to the hlist
-- for games that have had a name change but are still considered
-- the same competition.
if inputName=="World Athletics Championships" or inputName=="World Championships in Athletics" then
if year <= 2017 then
return "World Championships in Athletics"
else
return "World Athletics Championships"
end
elseif (inputName=="British Empire Games"
or inputName=="British Empire and Commonwealth Games"
or inputName=="British Commonwealth Games"
or inputName=="Commonwealth Games") then
if year <= 1950 then
return "British Empire Games"
elseif year <= 1966 then
return "British Empire and Commonwealth Games"
elseif year <= 1974 then
return "British Commonwealth Games"
else
return "Commonwealth Games"
end
elseif inputName=="Southeast Asian Peninsular Games" or inputName=="Southeast Asian Games" then
if year <= 1975 then
return "Southeast Asian Peninsular Games"
else
return "Southeast Asian Games"
end
elseif inputName=="Asian Indoor Games" or inputName=="Asian Indoor and Martial Arts Games" then
if year <= 2009 then
return "Asian Indoor Games"
else
return "Asian Indoor and Martial Arts Games"
end
elseif inputName=="Southern Cross Games" or inputName=="South American Games" then
if year <= 1982 then
return "Southern Cross Games"
else
return "South American Games"
end
elseif inputName=="All-Africa Games" or inputName=="African Games" then
if year <= 2011 then
return "All-Africa Games"
else
return "African Games"
end
else
return inputName
end
end
local function teamName(year, inputName, comp)
-- Modifies output of display being sent back to the hlist
-- for games that have had a name change but are still considered
-- the same competition.
if inputName=="Eswatini" or inputName=="Swaziland" then
if year < 2018 or year == 2018 and comp == 'Commonwealth Games' then
return "Swaziland"
else
return "Eswatini"
end
elseif inputName=="Upper Volta" or inputName=="Burkina Faso" then
if year <= 1983 then
return "Upper Volta"
else
return "Burkina Faso"
end
elseif inputName=="Democratic Republic of the Congo" or inputName=="Zaire" then
if year >= 1984 and year <=1996 then
return "Zaire"
else
return "Democratic Republic of the Congo"
end
elseif (inputName=="Individual Olympic Athletes"
or inputName=="Independent Olympic Athletes"
or inputName=="Independent Olympic Participants"
or inputName=="Olympic Athletes from Russia"
or inputName=="ROC") then
if year == 1992 or year==2014 then
return "Independent Olympic Participants"
elseif year == 2000 then
return "Individual Olympic Athletes"
elseif year == 2012 or year==2016 then
return "Independent Olympic Athletes"
elseif year == 2018 then
return "Olympic Athletes from Russia"
elseif year == 2020 or year==2022 then
return "ROC"
else
return inputName
end
elseif (inputName=="Independent Paralympic Participants"
or inputName=="Individual Paralympic Athletes"
or inputName=="Independent Paralympic Athletes"
or inputName=="RPC") then
if year == 1992 then
return "Independent Paralympic Participants"
elseif year == 2000 then
return "Individual Paralympic Athletes"
elseif year==2016 then
return "Independent Paralympic Athletes"
elseif year == 2020 or year==2022 then
return "RPC"
else
return inputName
end
elseif inputName=="North Macedonia" or inputName=="Macedonia" then
if year < 2019 then
return "Macedonia"
else
return "North Macedonia"
end
elseif inputName=="Malaysia" or inputName=="Malaya" then
if year < 1963 then
return "Malaya"
else
return "Malaysia"
end
-- 대한민국 지역
elseif inputName=="강원특별자치도" or inputName=="강원도" then
if year <= 2022 and comp == '전국체육대회' then
return "강원도"
elseif year <= 2023 and comp == '전국동계체육대회' then
return "강원도"
elseif year <= 2023 and comp == '전국소년체육대회' then
return "강원도"
else
return "강원특별자치도"
end
elseif inputName=="광주광역시" or inputName=="광주직할시" then
if year <= 1994 then
return "광주직할시"
else
return "광주광역시"
end
elseif inputName=="대구광역시" or inputName=="대구직할시" then
if year <= 1994 then
return "대구직할시"
else
return "대구광역시"
end
elseif inputName=="대전광역시" or inputName=="대전직할시" then
if year <= 1994 then
return "대전직할시"
else
return "대전광역시"
end
elseif inputName=="부산광역시" or inputName=="부산직할시" or inputName=="부산시" then
if year <= 1980 and comp == '전국체육대회' then
return "부산시"
elseif year <= 1982 and comp == '전국동계체육대회' then
return "부산시"
elseif year <= 1980 and comp == '전국소년체육대회' then
return "부산시"
elseif year <= 1994 then
return "부산직할시"
else
return "부산광역시"
end
elseif inputName=="서울특별시" or inputName=="서울특별자유시" then
if year <= 1948 and comp == '전국체육대회' then
return "서울특별자유시"
elseif year <= 1949 and comp == '전국동계체육대회' then
return "서울특별자유시"
else
return "서울특별시"
end
elseif inputName=="인천광역시" or inputName=="인천직할시" then
if year <= 1994 then
return "인천직할시"
else
return "인천광역시"
end
elseif inputName=="전북특별자치도" or inputName=="전라북도" then
if year <= 2023 then
return "전라북도"
else
return "전북특별자치도"
end
elseif inputName=="제주특별자치도" or inputName=="제주도" then
if year <= 2005 and comp == '전국체육대회' then
return "제주도"
elseif year <= 2006 and comp == '전국동계체육대회' then
return "제주도"
elseif year <= 2006 and comp == '전국소년체육대회' then
return "제주도"
else
return "제주특별자치도"
end
else
return inputName
end
end
function p._main(args)
load_data() -- in case this function is called by another module
local hlist = require('Module:List').horizontal
local competitions, disqualified_years, absent_years, absent_ranges = competition_information(args)
local current_year = os.date('!*t').year
local function is_absent(y)
if absent_years[y] then
return true
end
for _, range in ipairs(absent_ranges) do
if range[1] <= y and y <= range[2] then
return true
end
end
return false
end
local appearances = {}
local absent_first, absent_last
for i = 1, #competitions + 1 do -- +1 to handle any trailing absences
local y = competitions[i]
if y and is_absent(y) then
if absent_first then
absent_last = y
else
absent_first = y
end
else
if absent_first then
table.insert(appearances,
'<span style="color:gray">' ..
(absent_last and (absent_first .. '–' .. absent_last) or absent_first) ..
'</span>')
absent_first, absent_last = nil, nil
end
if y then
local display = tostring(y)
if y > current_year then
display = '<i>' .. display .. '</i>'
end
if disqualified_years[y] then
display = '<del>' .. display .. '</del>'
end
local compName = gameName(y, args.competition)
local teamOut = teamName(y, args.team, args.competition)
if compName == 'FIS Alpine World Ski Championships' then
table.insert(appearances, string.format(
'[[%s at the %s %d|%s]]',
teamOut, compName, y, display
))
else
table.insert(appearances, string.format(
'[[%d년 %s %s 선수단|%s]]',
y, compName, teamOut, display
))
end
end
end
end
return hlist(appearances)
end
function p.main(frame)
load_data(frame)
return p._main(frame:getParent().args)
end
return p