Module:Sandbox/InvalidData/AichanRepeat:修订间差异
InvalidData(讨论 | 贡献) (计算推荐的重复次数(?) |
InvalidData(讨论 | 贡献) 小 (完成(?) |
||
(未显示同一用户的2个中间版本) | |||
第2行: | 第2行: | ||
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.main() | function p.main() | ||
local prefList = getList() | local prefList = p.getList() | ||
local allList = {} | local allList = {} | ||
local repTimes = 0 | local repTimes = 0 | ||
local repSongs = 0 | local repSongs = 0 | ||
for i = 1,#prefList,1 do | for i = 1,#prefList,1 do | ||
local tempPref1 = prefList[i]['prefer'] | local tempPref1 = prefList[i]['prefer'] | ||
for j | for j = 1,#tempPref1,1 do | ||
local tempPref2 = tempPref1[j] | local tempPref2 = tempPref1[j] | ||
for k | for k = 1,#tempPref2,1 do | ||
local curSong = tempPref2[k] | local curSong = tempPref2[k] | ||
if allList[curSong] then -- when repeat | if allList[curSong] then -- when repeat | ||
repTimes = repTimes + 1 | repTimes = repTimes + 1 | ||
if | if allList[curSong] == 1 then -- when not first repeat | ||
repSongs = repSongs + 1 | repSongs = repSongs + 1 | ||
end | end | ||
allList[curSong] = allList[curSong] + 1 | |||
else -- when not repeat | else -- when not repeat | ||
allList[curSong] = 1 | |||
allList[ | |||
end | end | ||
end | end |
2024年9月22日 (日) 23:32的最新版本
可在Module:Sandbox/InvalidData/AichanRepeat/doc创建此模块的帮助文档
local srcFileName = 'InvalidData/preferdata.json'
local p = {}
function p.getList()
return mw.text.jsonDecode(mw.title.new(srcFileName,'User'):getContent())['aichan']
end
function p.main()
local prefList = p.getList()
local allList = {}
local repTimes = 0
local repSongs = 0
for i = 1,#prefList,1 do
local tempPref1 = prefList[i]['prefer']
for j = 1,#tempPref1,1 do
local tempPref2 = tempPref1[j]
for k = 1,#tempPref2,1 do
local curSong = tempPref2[k]
if allList[curSong] then -- when repeat
repTimes = repTimes + 1
if allList[curSong] == 1 then -- when not first repeat
repSongs = repSongs + 1
end
allList[curSong] = allList[curSong] + 1
else -- when not repeat
allList[curSong] = 1
end
end
end
end
local wikiText = "* 出现了'''" .. repTimes .. "'''次/'''" .. repSongs .. "'''首重复曲目"
return wikiText
end
return p