Module:ChartConstant:修订间差异

来自Arcaea中文维基
无编辑摘要
(ChartConstant美化)
第1行: 第1行:
local p = {}
local p = {}
local null = require('Module:Nullish')
local chartConstantList = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'ChartConstant.json' })
local chartConstantList = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'ChartConstant.json' })
local songlist = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist.json' })
local songlist = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist.json' })
local trans = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Template:Transition.json' })
local trans = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Transition.json' })
 
 


local function cv()
local function cv()
local list = {}
local list = {}
for i,k in pairs(songlist['songs']) do
for i, k in pairs(songlist['songs']) do
list[k['id']] = {
list[k['id']] = {
k['title_localized']['en'],
k['title_localized']['en'], k["date"],
k["date"],
((k["difficulties"][4] / null)["title_localized"] / null)["en"],
nil,
(k["difficulties"][4] / null)["date"]
nil
}
}
local byd = k["difficulties"][4]
if byd then
if byd["title_localized"] then
list[k['id']][3] = byd["title_localized"]["en"]
end
if byd["date"] then
list[k['id']][4] = byd["date"]
end
end
end
end
return list
return list
end
end


function p.main()
function p.main()
local name, link, timestamp, index
local cvList = cv()
local cvList = cv()


   local result = {}
local mid_result = {}
   local mid_result = {}
-- song key/value : str/array(table)
for skey, sval in pairs(chartConstantList) do
local get_table_index = function(i)
local name, timestamp = cvList[skey][1], cvList[skey][2]
if i>=11 then
local link = trans["songNameToDisplayName"][name] or (trans["sameName"][name] / null)[skey] or name
return math.floor(i)
-- chart index/value : int1~4/{constant=float,old=bool}
else return i end
for cid, cval in ipairs(sval) do
end
if tonumber(cval.constant) >= 8 and not cval.old then
 
if cid == 4 then
   for i, k in pairs(chartConstantList) do
if cvList[skey][3] then name = cvList[skey][3] end
 
if cvList[skey][4] then timestamp = cvList[skey][4] end
name = cvList[i][1]
link = name
timestamp = cvList[i][2]
 
     if trans["songNameToDisplayName"][name] then
       link = trans["songNameToDisplayName"][name]
     end
     if trans["sameName"][name] then
   link = trans["sameName"][name][i]
     end
  
for m, q in ipairs({ 2, 3, 4 }) do
if k[q] and tonumber(k[q]["constant"])>=8 and not k[q]["old"] then
 
index = get_table_index(k[q]["constant"])
     if not mid_result[index] then mid_result[index] = {} end
if q == 4 then
if cvList[i][3] then name = cvList[i][3] end
if cvList[i][4] then timestamp = cvList[i][4] end
end
end
table.insert(mid_result[index], { i, name, k[q]["constant"], ({"","PRS","FTR","BYD"})[q], link, timestamp })
-- 每排前面的数字
local rowtag = cval.constant >= 11 and math.floor(cval.constant) or cval.constant
mid_result[rowtag] = mid_result[rowtag] or {}
table.insert(mid_result[rowtag], {
skey, name, cval.constant,
({"PST", "PRS", "FTR", "BYD"})[cid], link, timestamp
})
end
end
end
end
   end
end


-- use template
-- {{ 组排单元| 曲名|id| 难度|link=页 链接|CC=定数}}
--  组排单元 第一个参数是 曲名 ,第二个是id,第三个是 难度 ,link字 意思
local result = {}
   for s, k in pairs(mid_result) do
-- row key/value : float/array({str,str,float,str,str,time})
if not(result[s]) then result[s] = {} end
for rkey, rval in pairs(mid_result) do
index = get_table_index(k[1][3])
-- 组内:时间升序(<11) 、定数降序(>=11)
 
table.sort(rval, function(a, b)
table.sort(k,
if a[3] == b[3] then
function (a, b)
return a[6] < b[6]
if a[3]~=b[3] then
else
return a[3]>b[3]
return a[3] > b[3]
end
end
return a[6]<b[6]
end)
end)
local units = { ds = rkey }
 
-- chart discription
for n, m in ipairs(k) do
for _, cdisc in ipairs(rval) do
local arguments = { m[2], m[1], m[4], link=m[5] }
table.insert(units, mw.getCurrentFrame():expandTemplate{
if index >= 11 then arguments.CC = string.format("%.1f", m[3]) end
title = '组排单元',
table.insert(result[index], mw.getCurrentFrame():expandTemplate { title = '组排单元', args = arguments })
args = {
cdisc[2], cdisc[1], cdisc[4], link = cdisc[5],
CC = rkey >= 11 and string.format("%.1f", cdisc[3]) or nil
}
})
end
end
   end
table.insert(result, units)
 
 
-- sort constants
local sortedTable = {}
for i,k in pairs(result) do
table.insert(sortedTable, {i, k})
end
end
table.sort(sortedTable, function(a,b) return a[1] > b[1] end)
-- 组间排序
table.sort(result, function(a, b) return a.ds > b.ds end)


 
-- final text
-- add head and end
local finText = "<div class='notaninfobox dstable'>\n"
local finText = "<div class='notaninfobox dstable'>\n"
for i,k in ipairs(sortedTable) do
for _, units in ipairs(result) do
if k[1] == 11 or k[1] == 12 then
finText = finText .. table.concat{
finText = finText 
"<div class='ds'>",
.. "<div class='ds'>" .. k[1] .. "</div>\n"
units.ds >= 11 and units.ds or string.format("%.1f", units.ds),
.. "<div class='number'>" .. mw.getCurrentFrame():expandTemplate { title = '组排列', args = { ['高度']="154px" } }
"</div>\n",
.. table.concat(k[2]) .. mw.getCurrentFrame():expandTemplate { title = '组排列-end' } .. "</div>\n"
"<div class='number'>",
else
mw.getCurrentFrame():expandTemplate{ title = '组排列', args = units.ds >= 11 and {['高度'] = "154px"} or nil },
finText = finText
table.concat(units),
.. "<div class='ds'>" .. string.format("%.1f", k[1]).."</div>\n"
mw.getCurrentFrame():expandTemplate{ title = '组排列-end' },
.. "<div class='number'>" .. mw.getCurrentFrame():expandTemplate { title = '组排列' }
"</div>\n"
.. table.concat(k[2]) .. mw.getCurrentFrame():expandTemplate { title = '组排列-end' } .. "</div>\n"
}
end
end
end
finText = finText .. "</div>"
finText = finText .. "</div>"
   return finText
return finText
end
end


return p
return p

2022年9月14日 (三) 12:56的版本

可在Module:ChartConstant/doc创建此模块的帮助文档

local p = {}
local null = require('Module:Nullish')
local chartConstantList = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'ChartConstant.json' })
local songlist = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist.json' })
local trans = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Transition.json' })

local function cv()
	local list = {}
	for i, k in pairs(songlist['songs']) do
		list[k['id']] = {
			k['title_localized']['en'], k["date"],
			((k["difficulties"][4] / null)["title_localized"] / null)["en"],
			(k["difficulties"][4] / null)["date"]
		}
	end
	return list
end

function p.main()
	local cvList = cv()

	local mid_result = {}
	-- song key/value : str/array(table)
	for skey, sval in pairs(chartConstantList) do
		local name, timestamp = cvList[skey][1], cvList[skey][2]
		local link = trans["songNameToDisplayName"][name] or (trans["sameName"][name] / null)[skey] or name
		-- chart index/value : int1~4/{constant=float,old=bool}
		for cid, cval in ipairs(sval) do
			if tonumber(cval.constant) >= 8 and not cval.old then
				if cid == 4 then
					if cvList[skey][3] then name = cvList[skey][3] end
					if cvList[skey][4] then timestamp = cvList[skey][4] end
				end
				-- 每排前面的数字
				local rowtag = cval.constant >= 11 and math.floor(cval.constant) or cval.constant
				mid_result[rowtag] = mid_result[rowtag] or {}
				table.insert(mid_result[rowtag], {
					skey, name, cval.constant,
					({"PST", "PRS", "FTR", "BYD"})[cid], link, timestamp
				})
			end
		end
	end

	-- {{组排单元|曲名|id|难度|link=页面链接|CC=定数}}
	local result = {}
	-- row key/value : float/array({str,str,float,str,str,time})
	for rkey, rval in pairs(mid_result) do
		-- 组内:时间升序(<11)、定数降序(>=11)
		table.sort(rval, function(a, b)
			if a[3] == b[3] then
				return a[6] < b[6]
			else
				return a[3] > b[3]
			end
		end)
		local units = { ds = rkey }
		-- chart discription
		for _, cdisc in ipairs(rval) do
			table.insert(units, mw.getCurrentFrame():expandTemplate{
				title = '组排单元',
				args = {
					cdisc[2], cdisc[1], cdisc[4], link = cdisc[5],
					CC = rkey >= 11 and string.format("%.1f", cdisc[3]) or nil
				}
			})
		end
		table.insert(result, units)
	end
	-- 组间排序
	table.sort(result, function(a, b) return a.ds > b.ds end)

	-- final text
	local finText = "<div class='notaninfobox dstable'>\n"
	for _, units in ipairs(result) do
		finText = finText .. table.concat{
			"<div class='ds'>",
				units.ds >= 11 and units.ds or string.format("%.1f", units.ds),
			"</div>\n",
			"<div class='number'>",
				mw.getCurrentFrame():expandTemplate{ title = '组排列', args = units.ds >= 11 and {['高度'] = "154px"} or nil },
				table.concat(units),
				mw.getCurrentFrame():expandTemplate{ title = '组排列-end' },
			"</div>\n"
		}
	end
	finText = finText .. "</div>"
	return finText
end

return p