Difference between revisions of "Module:Check winner by scores"
Jump to navigation
Jump to search
test>MusikBot II m (Protected "Module:Check winner by scores": High-risk template or module (more info) ([Edit=Require autoconfirmed or confirmed access] (indefinite))) |
m (7 revisions imported) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 44: | Line 44: | ||
if type(s1) == 'number' and type(s2) == 'number' then | if type(s1) == 'number' and type(s2) == 'number' then | ||
return (s1 > s2) and 'W' or ((s2 > s1) and 'L' or 'T') | return (s1 > s2) and 'W' or ((s2 > s1) and 'L' or 'T') | ||
| − | elseif s1:match('[WL]') and s2:match('[WL]') then | + | elseif s1:match('[WL]') and s2:match('[WL]') and s1 ~= s2 then |
return s1 | return s1 | ||
else | else | ||
Latest revision as of 16:07, 20 September 2020
| This Lua module is used on approximately 9,800 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages. Consider discussing changes on the talk page before implementing them.
Transclusion count updated automatically (see documentation). |
| This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Contents
Usage
Implements {{check winner by scores}}
require('Module:No globals')
local p = {}
local function format_score(s)
s = mw.ustring.gsub(s or '', '^[%s\']*([%d%.]+)[%s\']*[–−—%-][%s\']*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*([%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[%[[^%[%]]*%|[%d%.]+)%s*%-%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[[^%[%]%s]*%s+[%d%.]+)%s*%-%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[%[[^%[%]]*%|[%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)', '%1–%2')
s = mw.ustring.gsub(s, '^%s*(%[[^%[%]%s]*%s+[%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)', '%1–%2')
return s
end
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, { parentFirst = true })
local n1 = args[1] or 'X'
local n2 = args[2] or 'X'
local s = args['sc'] or (n1..'–'..n2)
s = format_score(s)
-- following codes obtained from Module:Sports results
-- delink if necessary
if s:match('^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]') then
s = s:match('^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]')
end
if s:match('^%s*%[[^%[%]%s]*%s([^%[%]]*)%]') then
s = s:match('^%s*%[[^%[%]%s]*%s([^%[%]]*)%]')
end
-- get the scores
local s1 = tonumber(mw.ustring.gsub( s or '',
'^%s*([%d][%d%.]*)%s*–%s*([%d][%d%.]*).*', '%1' ) or nil)
or mw.ustring.gsub(s or '', '^([WL]*)–([WL]*).*', '%1' )
or ''
local s2 = tonumber(mw.ustring.gsub( s or '',
'^%s*([%d][%d%.]*)%s*–%s*([%d][%d%.]*).*', '%2' ) or nil)
or mw.ustring.gsub(s or '', '^([WL]*)–([WL]*).*', '%2' )
or ''
if type(s1) == 'number' and type(s2) == 'number' then
return (s1 > s2) and 'W' or ((s2 > s1) and 'L' or 'T')
elseif s1:match('[WL]') and s2:match('[WL]') and s1 ~= s2 then
return s1
else
return string.format("''%s''", 'Result unknown')
end
end
return p