Module:ArtistSong:修订间差异
Economy666(讨论 | 贡献) (for test) |
Economy666(讨论 | 贡献) (暂时生成表格) |
||
第31行: | 第31行: | ||
local function convertPick(pickList, pickListBYD) | local function convertPick(pickList, pickListBYD) | ||
convertList = {} | convertList = {} | ||
for _id,_ in pickList do | for _id,_ in pairs(pickList) do | ||
local artist = pickList[_id] | local artist = pickList[_id] | ||
if not convertList[artist] then convertList[artist] = {} end | if not convertList[artist] then convertList[artist] = {} end | ||
第38行: | 第38行: | ||
end | end | ||
for _id | for _id in pairs(pickListBYD) do | ||
local artist = pickListBYD[_id] | local artist = pickListBYD[_id] | ||
if not convertList[artist] then convertList[artist] = {} end | if not convertList[artist] then convertList[artist] = {} end | ||
第49行: | 第49行: | ||
local function genList(convertList) | local function genList(convertList) | ||
local function cate(cArtist, artist) | local function cate(singleList, cArtist, artist) | ||
local artist = artist or cArtist | local artist = artist or cArtist | ||
if singleList[artist] then singleList[artist] = {} end | if not singleList[artist] then singleList[artist] = {} end | ||
if convertList[cArtist].beyond then | if convertList[cArtist].beyond then | ||
if not singleList[artist].beyond then singleList[artist]['beyond'] = {} end | if not singleList[artist].beyond then singleList[artist]['beyond'] = {} end | ||
第64行: | 第64行: | ||
end | end | ||
end | end | ||
return singleList | |||
end | |||
singleList = {} | local singleList = {} | ||
for cArtist in convertList do | for cArtist in pairs(convertList) do | ||
if CAL[cArtist] then | if CAL[cArtist] then | ||
for text in CAL[cArtist] do | for _,text in pairs(CAL[cArtist]) do | ||
if text.link then | if text.link then | ||
artist = text['link'] | artist = text['link'] | ||
cate(cArtist,artist) | singleList = cate(singleList, cArtist, artist) | ||
end | end | ||
end | end | ||
else | else | ||
cate(cArtist) | singleList = cate(singleList, cArtist) | ||
end | end | ||
end | end | ||
第85行: | 第86行: | ||
function p.main() | function p.main() | ||
local rl, rlb = readList() | local rl, rlb = readList() | ||
local cl = convertPick(rl, rlb) | |||
local gl = genList(cl) | |||
local wikiText = "{| class=\"wikitable\"\n" | |||
wikiText = wikiText .. "! Artist !! Songs\n" | |||
for name, item in pairs(gl) do | |||
if item.beyond and item.normal then | |||
wikiText = wikiText .. "|-\n| rowspan=\"2\" | " .. name .. "\n" | |||
wikiText = wikiText .. "| " .. mw.text.jsonEncode(item.normal) .. "\n" | |||
wikiText = wikiText .. "|-\n|'''BYD''':" .. mw.text.jsonEncode(item.beyond) .. "\n" | |||
else | |||
wikiText = wikiText .. "|-\n| " .. name .. " || " | |||
if item.normal then | |||
wikiText = wikiText .. mw.text.jsonEncode(item.normal) .. "\n" | |||
elseif item.beyond then | |||
wikiText = wikiText .. " '''BYD''' :" .. mw.text.jsonEncode(item.beyond) .. "\n" | |||
end | |||
end | |||
end | |||
wikiText = wikiText .. "|}" | |||
return wikiText | |||
end | end | ||
return p | return p |
2024年7月4日 (四) 22:19的版本
可在Module:ArtistSong/doc创建此模块的帮助文档
p={}
local CAL = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json'
local multiId = mw.loadJsonData 'Template:Transition.json'.multiId
local mad = require 'Module:AnotherData'
local function readList()
local pickList = {}
local pickListBYD = {}
for _, song in ipairs(mad.listOf('songs', 'mobile')) do
local artist = song.artist
pickList[song.id] = song.artist
if song.difficulties[4] and song.difficulties[4].artist and song.difficulties[4].artist~=artist then
local bydArtist = song['difficulties'][4]['artist']
pickListBYD[song['id']] = bydArtist
end
end
for _, song in ipairs(mad.listOf('songs', 'ns')) do
if not pickList[song.id] and not multiId[song.id] then
pickList[song.id] = song.artist
if song.difficulties[4] and song.difficulties[4].artist then
bydArtist = song['difficulties'][4]['artist']
pickListBYD[song['id']] = bydArtist
end
end
end
return pickList, pickListBYD
end
local function convertPick(pickList, pickListBYD)
convertList = {}
for _id,_ in pairs(pickList) do
local artist = pickList[_id]
if not convertList[artist] then convertList[artist] = {} end
if not convertList[artist].normal then convertList[artist]['normal'] = {} end
table.insert(convertList[artist]['normal'], _id)
end
for _id in pairs(pickListBYD) do
local artist = pickListBYD[_id]
if not convertList[artist] then convertList[artist] = {} end
if not convertList[artist].beyond then convertList[artist]['beyond'] = {} end
table.insert(convertList[artist]['beyond'], _id)
end
return convertList
end
local function genList(convertList)
local function cate(singleList, cArtist, artist)
local artist = artist or cArtist
if not singleList[artist] then singleList[artist] = {} end
if convertList[cArtist].beyond then
if not singleList[artist].beyond then singleList[artist]['beyond'] = {} end
for _,i in pairs(convertList[cArtist]['beyond']) do
table.insert(singleList[artist]['beyond'],i)
end
end
if convertList[cArtist].normal then
if not singleList[artist].normal then singleList[artist]['normal'] = {} end
for _,i in pairs(convertList[cArtist]['normal']) do
table.insert(singleList[artist]['normal'],i)
end
end
return singleList
end
local singleList = {}
for cArtist in pairs(convertList) do
if CAL[cArtist] then
for _,text in pairs(CAL[cArtist]) do
if text.link then
artist = text['link']
singleList = cate(singleList, cArtist, artist)
end
end
else
singleList = cate(singleList, cArtist)
end
end
return singleList
end
function p.main()
local rl, rlb = readList()
local cl = convertPick(rl, rlb)
local gl = genList(cl)
local wikiText = "{| class=\"wikitable\"\n"
wikiText = wikiText .. "! Artist !! Songs\n"
for name, item in pairs(gl) do
if item.beyond and item.normal then
wikiText = wikiText .. "|-\n| rowspan=\"2\" | " .. name .. "\n"
wikiText = wikiText .. "| " .. mw.text.jsonEncode(item.normal) .. "\n"
wikiText = wikiText .. "|-\n|'''BYD''':" .. mw.text.jsonEncode(item.beyond) .. "\n"
else
wikiText = wikiText .. "|-\n| " .. name .. " || "
if item.normal then
wikiText = wikiText .. mw.text.jsonEncode(item.normal) .. "\n"
elseif item.beyond then
wikiText = wikiText .. " '''BYD''' :" .. mw.text.jsonEncode(item.beyond) .. "\n"
end
end
end
wikiText = wikiText .. "|}"
return wikiText
end
return p