查看“模块:Standings”的源代码
←
模块:Standings
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您必须确认您的电子邮件地址才能编辑页面。请通过
系统设置
设置并确认您的电子邮件地址。
您可以查看与复制此页面的源代码。
local p = {} --p stands for package local mode_col = 1 local level_col = 2 local score_col = 3 local name_col = 4 local video_col = 5 local date_col = 6 -- .0 => .4999, .5 => .9999 function expand_from_old_SR_time(score) if score:len() == 6 then if score:sub(-1) == '0' then score = score:sub(1, -2) .. '4999' elseif score:sub(-1) == '5' then score = score:sub(1, -2) .. '9999' end end return score end function score_less_SR(a, b) a = expand_from_old_SR_time(a) b = expand_from_old_SR_time(b) return a > b end function score_less_HS(a, b) return a < b end function remove_asterisk(score) if score:sub(-1) == '*' then score = score:sub(1, -2) end return score end -- compare score, including HS and SR function score_less(a, b) a = remove_asterisk(a) b = remove_asterisk(b) if string.find(a, ':') and string.find(b, ':') then return score_less_SR(a, b) elseif not string.find(a, ':') and not string.find(b, ':') then return score_less_HS(a, b) end end -- sort by mode, level, score and date function standing_less(a, b) if a[mode_col] ~= b[mode_col] then return a[mode_col] < b[mode_col] elseif a[level_col] ~= b[level_col] then return a[level_col] < b[level_col] elseif a[score_col] ~= b[score_col] then return score_less(b[score_col], a[score_col]) else return a[date_col] < b[date_col] end end -- sort by mode, level, name and score function unique_less(a, b) if a[mode_col] ~= b[mode_col] then return a[mode_col] < b[mode_col] elseif a[level_col] ~= b[level_col] then return a[level_col] < b[level_col] elseif a[name_col] ~= b[name_col] then return a[name_col] < b[name_col] else return score_less(b[score_col], a[score_col]) end end function unique(records) local records_new = {} local record_last = nil table.sort(records, unique_less) for key, record in ipairs(records) do if record_last == nil then table.insert(records_new, record) elseif record[mode_col] ~= record_last[mode_col] or record[level_col] ~= record_last[level_col] or record[name_col] ~= record_last[name_col] then table.insert(records_new, record) end record_last = record end return records_new end function select_standing(records, mode, level) local records_new = {} for key, record in ipairs(records) do if record[mode_col] == mode and record[level_col] == level then table.insert(records_new, record) end end records_new = unique(records_new) table.sort(records_new, standing_less) return records_new end function select_WR(records, mode, level) local records_new = {} local highest = nil table.sort(records, standing_less) for i = #records, 1, -1 do local record = records[i] if record[mode_col] == mode and record[level_col] == level then if highest == nil or score_less(highest, record[score_col]) then table.insert(records_new, record) highest = record[score_col] end end end return records_new end function trim(s) return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)' end function get_records() local content = mw.title.new('Ballance个人纪录列表'):getContent() local records = {} for line in content:gmatch('[^\r\n]+') do if string.sub(line, 1, string.len('| ')) == '| ' then line = line:sub(2) record = {} for element in line:gmatch("[^|]+") do if element ~= '' then element = trim(element) table.insert(record, element) end end table.insert(records, record) end end return records end function p.standings(frame) local args = frame.args[1] and frame.args or frame:getParent().args; local records = select_standing(get_records(), args[1], args[2]) local record_last = nil local ranking = 0 local ranking_hold = 0 local highest = nil local wikitable_str = '{| class="wikitable" style="display: inline-block; vertical-align: top"\n' wikitable_str = wikitable_str .. '|+ <h3> 关卡 ' .. args[2] .. '</h3>\n' wikitable_str = wikitable_str .. '! 名次 !! 分数 !! 纪录持有者 !! 视频链接\n' for key, record in ipairs(records) do ranking = ranking + 1 if highest == nil or highest ~= remove_asterisk(record[score_col]) then ranking_hold = ranking end wikitable_str = wikitable_str .. '|-\n' wikitable_str = wikitable_str .. '|' .. ranking_hold wikitable_str = wikitable_str .. '||' .. record[score_col] wikitable_str = wikitable_str .. '||' .. record[name_col] wikitable_str = wikitable_str .. '||' .. record[video_col] wikitable_str = wikitable_str .. '\n' highest = remove_asterisk(record[score_col]) end wikitable_str = wikitable_str .. '|}\n' return wikitable_str end function p.historical_WRs(frame) local args = frame.args[1] and frame.args or frame:getParent().args; local records = select_WR(get_records(), args[1], args[2]) local date_until = 0 local scire_until = 0 local name_until = 0 local wikitable_str = '{| class="wikitable" style="display: inline-block; vertical-align: top"\n' wikitable_str = wikitable_str .. '|+ <h3> 关卡 ' .. args[2] .. '</h3>\n' wikitable_str = wikitable_str .. '! 时间 !! 纪录分数 !! 纪录持有者 !! 视频链接\n' for key, record in ipairs(records) do wikitable_str = wikitable_str .. '|-\n' wikitable_str = wikitable_str .. '|' .. record[date_col] wikitable_str = wikitable_str .. '||' .. record[score_col] wikitable_str = wikitable_str .. '||' .. record[name_col] wikitable_str = wikitable_str .. '||' .. record[video_col] wikitable_str = wikitable_str .. '\n' end wikitable_str = wikitable_str .. '|}\n' mw.log(wikitable_str) return wikitable_str end return p
该页面使用的模板:
模块:Standings/doc
(
查看源代码
)
返回至
模块:Standings
。
导航菜单
个人工具
中文(中国大陆)
创建账户
登录
名字空间
模块
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
主分类
制图
竞速
Q&A
机关大全
相关程序
地图图鉴
相关网站
Ballance吧
Ballance QQ群
Ballance Discord群组
Speedrun.com
Ballance吧专区
导航贴
英雄榜
快捷访问
公共沙盒
贡献指南
赞助我们
工具
链入页面
相关更改
特殊页面
页面信息