Module:ChartConstant:修订间差异

来自Arcaea中文维基
(sb ipairs, sb lasteternity)
(加点说明书()
 
(未显示3个用户的14个中间版本)
第1行: 第1行:
local mad = require 'Module:AnotherData'
local p = {}
local p = {}
local null = require('Module:Nullish')
-- ns待补充(ns也不需要这个)
local chartConstantList = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'ChartConstant.json' })
-- 需要输出详表(如存档旧ptt数据)的话控制台直接print(p.detail()) 就行了
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 function itData(datas, cc)
local list = {}
cc = cc or 13
for i, k in pairs(songlist['songs']) do
local step, format = unpack(cc > 11 and {1, '%d'} or {.1, '%.1f'})
list[k['id']] = {
cc = cc - step
k['title_localized']['en'], k["date"],
local id = format:format(cc)
((k["difficulties"][4] / null)["title_localized"] / null)["en"],
local data = datas[id]
(k["difficulties"][4] / null)["date"]
if not data then return nil end
}
return cc, id, data
end
return list
end
end
function p.main()
function p.main()
local cvList = cv()
local datas = {}
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
for _, song in ipairs(mad.listOf 'songs') do
local id, titleBase, dateBase = song.id, mad.title(song), song.date
local songCc = songCcs[id] or {}
local link = mad.linkName(song) or titleBase
if not song.deleted then
for _, chart in ipairs {}, song.difficulties, 1 do
local rc = chart.ratingClass + 1
local chartCc = songCc[rc]
-- fk lua donot support continue. use single-loop & break for subst
repeat
if not chartCc or chartCc.old ~= false then break end
local nCc = chartCc.constant
if nCc < 8 then break end
local title, date = mad.title(chart) or titleBase, chart.date or dateBase


for i = 1, 3 do chartConstantList['lasteternity'][i] = { constant = 0 } end
local rowId, sCc
local mid_result = {}
if nCc >= 11 then
-- song key/value : str/array(table)
rowId = ('%d'):format(nCc)
for skey, sval in pairs(chartConstantList) do
sCc = ('%.1f'):format(nCc)
local name, timestamp = cvList[skey][1], cvList[skey][2]
else
local link = trans["songNameToDisplayName"][name] or (trans["sameName"][name] / null)[skey] or name
rowId = ('%.1f'):format(nCc)
-- chart index/value : int1~4/{constant=float,old=bool}
end
for cid, cval in ipairs(sval) do
local rowData = datas[rowId]
if tonumber(cval.constant) >= 8 and not cval.old then
if not rowData then
if cid == 4 then
rowData = {}
if cvList[skey][3] then name = cvList[skey][3] end
datas[rowId] = rowData
if cvList[skey][4] then timestamp = cvList[skey][4] end
end
end
table.insert(rowData, {
-- 每排前面的数字
data = {title, id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = link, CC = sCc},
local rowtag = cval.constant >= 11 and math.floor(cval.constant) or cval.constant
sort = {nCc, rc, date}
mid_result[rowtag] = mid_result[rowtag] or {}
})
table.insert(mid_result[rowtag], {
until (true)
skey, name, cval.constant,
({"PST", "PRS", "FTR", "BYD"})[cid], link, timestamp
})
end
end
end
end
end
end


-- {{组排单元|曲名|id|难度|link= 页面链接|CC= 定数}}
local frame = mw.getCurrentFrame()
local result = {}
local text = mw.html.create 'div':addClass 'notaninfobox dstable'
-- row key/value : float/array({str,str,float,str,str,time})
for _, rowId, rowData in itData, datas do
for rkey, rval in pairs(mid_result) do
text = text
-- 组内:时间升序(<11) 、定数降序(>=11)
:tag 'div':addClass 'ds':wikitext(rowId):done()
table.sort(rval, function(a, b)
:tag 'div':addClass 'number'
if a[3] == b[3] then
:wikitext(frame:expandTemplate {title = '组排列', args = {height = 'auto'}})
return a[6] < b[6]
table.sort(rowData, function(a, b)
else
a, b = a.sort, b.sort
return a[3] > b[3]
if a[1] ~= b[1] then return a[1] > b[1] end
if a[2] ~= b[2] then return a[2] > b[2] end
return a[3] < b[3]
end)
for _, rowItem in ipairs(rowData) do
text:wikitext(frame:expandTemplate {title = ' 组排单元', args = rowItem.data})
end
text = text:wikitext(frame:expandTemplate {title = '组排列-end'}):done()
end
 
return tostring(text)
end
 
function p.detail()
local datas = {}
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
for _, song in ipairs(mad.listOf 'songs') do
if not song.deleted then
local id = song.id
local songCc = songCcs[id] or {}
--
local data = {mad.linkTitle(song)}
local sort = {0, song.date}
table.insert(datas, {data = data, sort = sort})
for _, chart in ipairs(song.difficulties) do
local rc = chart.ratingClass + 1
local chartCc = songCc[rc]
repeat
if not chartCc then break end
local nCc = chartCc.constant
if not chart.date then sort[1] = nCc end
local sCc = ('%.1f'):format(nCc)
data[rc + 1] = chartCc.old ~= false and tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCc)) or sCc
until (true)
end
for i = 2, 6 do
data[i] = data[i] or ' '
end
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
end
table.insert(result, units)
end
end
-- 组间排序
table.sort(result, function(a, b) return a.ds > b.ds end)


-- final text
table.sort(datas, function(a, b)
local finText = "<div class='notaninfobox dstable'>\n"
a, b = a.sort, b.sort
for _, units in ipairs(result) do
if a[1] == b[1] then return a[2] < b[2] end
finText = finText .. table.concat{
return a[1] > b[1]
"<div class='ds'>",
end)
units.ds >= 11 and units.ds or string.format("%.1f", units.ds),
 
"</div>\n",
local texts = {}
"<div class='number'>",
local template = '|-\n|[[%s]]' .. ('||%s'):rep(5)
mw.getCurrentFrame():expandTemplate{ title = ' 组排列', args = units.ds >= 11 and {[' 高度'] = "154px"} or nil },
for _, value in ipairs(datas) do
table.concat(units),
table.insert(texts, template:format(unpack(value.data)))
mw.getCurrentFrame():expandTemplate{ title = '组排列-end' },
"</div>\n"
}
end
end
finText = finText .. "</div>"
 
return finText
return table.concat(texts, '\n')
end
end


return p
return p

2024年11月18日 (一) 12:56的最新版本

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

local mad = require 'Module:AnotherData'
local p = {}
-- ns待补充(ns也不需要这个)
-- 需要输出详表(如存档旧ptt数据)的话控制台直接print(p.detail())就行了

local function itData(datas, cc)
	cc = cc or 13
	local step, format = unpack(cc > 11 and {1, '%d'} or {.1, '%.1f'})
	cc = cc - step
	local id = format:format(cc)
	local data = datas[id]
	if not data then return nil end
	return cc, id, data
end
function p.main()
	local datas = {}
	local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
	for _, song in ipairs(mad.listOf 'songs') do
		local id, titleBase, dateBase = song.id, mad.title(song), song.date
		local songCc = songCcs[id] or {}
		local link = mad.linkName(song) or titleBase
		if not song.deleted then
			for _, chart in ipairs {}, song.difficulties, 1 do
				local rc = chart.ratingClass + 1
				local chartCc = songCc[rc]
				-- fk lua donot support continue. use single-loop & break for subst
				repeat
					if not chartCc or chartCc.old ~= false then break end
					local nCc = chartCc.constant
					if nCc < 8 then break end
					local title, date = mad.title(chart) or titleBase, chart.date or dateBase

					local rowId, sCc
					if nCc >= 11 then
						rowId = ('%d'):format(nCc)
						sCc = ('%.1f'):format(nCc)
					else
						rowId = ('%.1f'):format(nCc)
					end
					local rowData = datas[rowId]
					if not rowData then
						rowData = {}
						datas[rowId] = rowData
					end
					table.insert(rowData, {
						data = {title, id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = link, CC = sCc},
						sort = {nCc, rc, date}
					})
				until (true)
			end
		end
	end

	local frame = mw.getCurrentFrame()
	local text = mw.html.create 'div':addClass 'notaninfobox dstable'
	for _, rowId, rowData in itData, datas do
		text = text
			:tag 'div':addClass 'ds':wikitext(rowId):done()
			:tag 'div':addClass 'number'
			:wikitext(frame:expandTemplate {title = '组排列', args = {height = 'auto'}})
		table.sort(rowData, function(a, b)
			a, b = a.sort, b.sort
			if a[1] ~= b[1] then return a[1] > b[1] end
			if a[2] ~= b[2] then return a[2] > b[2] end
			return a[3] < b[3]
		end)
		for _, rowItem in ipairs(rowData) do
			text:wikitext(frame:expandTemplate {title = '组排单元', args = rowItem.data})
		end
		text = text:wikitext(frame:expandTemplate {title = '组排列-end'}):done()
	end

	return tostring(text)
end

function p.detail()
	local datas = {}
	local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
	for _, song in ipairs(mad.listOf 'songs') do
		if not song.deleted then
			local id = song.id
			local songCc = songCcs[id] or {}
			--
			local data = {mad.linkTitle(song)}
			local sort = {0, song.date}
			table.insert(datas, {data = data, sort = sort})
			for _, chart in ipairs(song.difficulties) do
				local rc = chart.ratingClass + 1
				local chartCc = songCc[rc]
				repeat
					if not chartCc then break end
					local nCc = chartCc.constant
					if not chart.date then sort[1] = nCc end
					local sCc = ('%.1f'):format(nCc)
					data[rc + 1] = chartCc.old ~= false and tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCc)) or sCc
				until (true)
			end
			for i = 2, 6 do
				data[i] = data[i] or ' '
			end
		end
	end

	table.sort(datas, function(a, b)
		a, b = a.sort, b.sort
		if a[1] == b[1] then return a[2] < b[2] end
		return a[1] > b[1]
	end)

	local texts = {}
	local template = '|-\n|[[%s]]' .. ('||%s'):rep(5)
	for _, value in ipairs(datas) do
		table.insert(texts, template:format(unpack(value.data)))
	end

	return table.concat(texts, '\n')
end

return p