Module:Sandbox/InvalidData/AichanTable:修订间差异
InvalidData(讨论 | 贡献) (生成单月推荐表格(?) |
InvalidData(讨论 | 贡献) 小 (完成(?) |
||
(未显示同一用户的3个中间版本) | |||
第1行: | 第1行: | ||
local getArgs = require | local getArgs = require 'Module:Arguments'.getArgs | ||
local data = require 'Module:Arcaea Data' | local data = require 'Module:Arcaea Data' | ||
local query = data.allSongInformation("id", "mobile") | local query = data.allSongInformation("id", "mobile") | ||
第5行: | 第5行: | ||
local p = {} | local p = {} | ||
function p.getList() | |||
return mw.text.jsonDecode(mw.title.new(srcFileName,'User'):getContent())['aichan'] | return mw.text.jsonDecode(mw.title.new(srcFileName,'User'):getContent())['aichan'] | ||
end | end | ||
function p.linkName(id,name) -- 重写Module:AnotherData的linkName | |||
local trans = mw.loadJsonData 'Template:Transition.json' | local trans = mw.loadJsonData 'Template:Transition.json' | ||
local res = trans.songNameToDisplayName[name] | local res = trans.songNameToDisplayName[name] | ||
if res then return res end | if res then return res end | ||
res = trans.sameName[name] | res = trans.sameName[name] | ||
if res then return res[ | if res then return res[id] end | ||
end | end | ||
第31行: | 第31行: | ||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
local index = args['index'] or (args['year']-2024)*12+args['month']-3 | local index = args['index'] or (args['year']-2024)*12+args['month']-3 | ||
local prefList = getList()[index]['prefer'] | local prefList = p.getList()[index]['prefer'] | ||
local year = args['year'] or getList[index]['year'] | local year = args['year'] or getList[index]['year'] | ||
local month = args['month'] or getList[index]['month'] | local month = args['month'] or getList[index]['month'] | ||
第44行: | 第44行: | ||
text = text .. '| ' .. day .. '日\n' | text = text .. '| ' .. day .. '日\n' | ||
text = text .. '| ' .. frame:expandTemplate{title = '组排列', args = {height = 'auto'}} | text = text .. '| ' .. frame:expandTemplate{title = '组排列', args = {height = 'auto'}} | ||
for i | for i = 1,#songs,1 do | ||
local id = songs[i] | local id = songs[i] | ||
local title = query(id,"title") | local title = query(id,"title") | ||
local link = linkName(title) or title | local link = p.linkName(id,title) or title | ||
text = text .. frame:expandTemplate{title = '组排单元', args = {title, id, link = link}} | text = text .. frame:expandTemplate{title = '组排单元', args = {title, id, link = link}} | ||
end | end | ||
第54行: | 第54行: | ||
end | end | ||
for i | for i = 1,#prefList,1 do | ||
local | local d = i + delta | ||
local dayPref = prefList[i] | local dayPref = prefList[i] | ||
wikiText = wikiText .. tableUnit( | wikiText = wikiText .. tableUnit(d, dayPref) | ||
end | end | ||
return wikiText | return wikiText .. '|}\n' | ||
end | end | ||
return p | return p |
2024年9月22日 (日) 22:29的最新版本
可在Module:Sandbox/InvalidData/AichanTable/doc创建此模块的帮助文档
local getArgs = require 'Module:Arguments'.getArgs
local data = require 'Module:Arcaea Data'
local query = data.allSongInformation("id", "mobile")
local srcFileName = 'InvalidData/preferdata.json'
local p = {}
function p.getList()
return mw.text.jsonDecode(mw.title.new(srcFileName,'User'):getContent())['aichan']
end
function p.linkName(id,name) -- 重写Module:AnotherData的linkName
local trans = mw.loadJsonData 'Template:Transition.json'
local res = trans.songNameToDisplayName[name]
if res then return res end
res = trans.sameName[name]
if res then return res[id] end
end
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
-- args:
-- index: 序号
-- 序号以2024年4月为1, 一个月加1
-- 例如2024年11月为8, 2025年3月为12
-- year: 年份, 不填index时使用
-- month: 月份, 不填index时使用
local frame = mw.getCurrentFrame()
local index = args['index'] or (args['year']-2024)*12+args['month']-3
local prefList = p.getList()[index]['prefer']
local year = args['year'] or getList[index]['year']
local month = args['month'] or getList[index]['month']
local wikiText = "== " .. year .. "年" .. month .. "月 ==\n"
local delta = 0
if index == 1 then delta = 1 end -- 硬编码处理24年4月
wikiText = wikiText .. '{| class="wikitable mw-collapsible mw-collapsed" border="1" cellspacing="0" cellpadding="5" style="text-align:center"\n|-\n'
wikiText = wikiText .. '! scope="col" style="position:-webkit-sticky;position:sticky;top:0px;"|日期 !! scope="col" style="position:-webkit-sticky;position:sticky;top:0px;"|曲目\n'
local function tableUnit(day,songs)
local text = '|-\n'
text = text .. '| ' .. day .. '日\n'
text = text .. '| ' .. frame:expandTemplate{title = '组排列', args = {height = 'auto'}}
for i = 1,#songs,1 do
local id = songs[i]
local title = query(id,"title")
local link = p.linkName(id,title) or title
text = text .. frame:expandTemplate{title = '组排单元', args = {title, id, link = link}}
end
text = text .. frame:expandTemplate{title = '组排列-end'} .. '\n'
return text
end
for i = 1,#prefList,1 do
local d = i + delta
local dayPref = prefList[i]
wikiText = wikiText .. tableUnit(d, dayPref)
end
return wikiText .. '|}\n'
end
return p