Module:ChartConstant:修订间差异

来自Arcaea中文维基
(微调)
(暂时以11.4分界,减轻第一组内容过多的问题)
 
(未显示4个用户的15个中间版本)
第1行: 第1行:
local mad = require 'Module:AnotherData'
local mad = require 'Module:AnotherData'
local frame = mw.getCurrentFrame()
local p = {}
local p = {}
-- ns待补充(ns也不需要这个)
-- 需要输出详表(如存档旧ptt数据)的话控制台直接print(p.detail())就行了


local function songMap()
-- 分界参数
local res = {}
local ccmax = 13   --容纳的最大定数,一般为最高定级+1
for _, song in ipairs(mad.listOf 'songs') do res[song.id] = song end
local divide = 11.4 --分界定数,低于此定数按0.1划分(值需≤间断定数,当前为11.8)
-- ns待补充
-- local divide = 11.4
return res
end


local function itData(datas, cc)
local function itData(datas, cc)
cc = cc or 13
cc = cc or ccmax
local step, format = unpack(cc > 11 and {1, '%d'} or {.1, '%.1f'})
local step = cc > divide and ccmax-divide or .1
cc = cc - step
cc = cc - step
local id = format:format(cc)
local id = ('%.1f'):format(cc)
local data = datas[id]
local data = datas[id]
if not data then return nil end
if not data then return nil end
第20行: 第19行:
end
end
function p.main()
function p.main()
local mSong = songMap()
local datas = {}
local datas = {}
-- CD: constant data
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do
local divide_str = ('%.1f'):format(divide)
local song = mSong[id]
for _, song in ipairs(mad.listOf 'songs') do
local query = mad.songQueryWrap(song)
local id, titleBase, dateBase = song.id, mad.title(song), song.date
local title, date = query.title, song.date
local songCc = songCcs[id] or {}
local link = query.linkName or title
local link = mad.linkName(song) or titleBase
for diffIdx = 2, 4 do
if not song.deleted then
-- fk lua donot support continue. use single-loop & break for subst
for _, chart in ipairs {}, song.difficulties, 1 do
repeat
local rc = chart.ratingClass + 1
local diffCD = songCD[diffIdx] or {}
local chartCc = songCc[rc]
if diffCD.old ~= false then break end
-- fk lua donot support continue. use single-loop & break for subst
local cc = diffCD.constant
repeat
if cc < 8 then break end
if not chartCc or chartCc.old ~= false then break end
if diffIdx == 4 then
local nCc = chartCc.constant
title = query.bydTitle or title
if nCc < 8 then break end
date = query.bydDate or date
local title, date = mad.title(chart) or titleBase, chart.date or dateBase
end
 
local rowId, diasplayCC, rowAttr
local rowId, sCc
if cc >= 11 then
if nCc >= divide then
rowId = ('%d'):format(cc)
rowId = divide_str
diasplayCC = ('%.1f'):format(cc)
sCc = ('%.1f'):format(nCc)
rowAttr = {['高度'] = '154px'}
else
else
rowId = ('%.1f'):format(nCc)
rowId = ('%.1f'):format(cc)
end
end
local rowData = datas[rowId]
local rowData = datas[rowId]
if not rowData then
if not rowData then
rowData = {}
rowData = {attr = rowAttr}
datas[rowId] = rowData
datas[rowId] = rowData
end
end
table.insert(rowData, {
table.insert(rowData, {
data = {title, id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = link, CC = sCc},
data = {title, song.id, ({'PST', 'PRS', 'FTR', 'BYD'})[diffIdx], link = link, CC = diasplayCC},
sort = {nCc, rc, date}
sort = {cc, date}
})
})
until (true)
until (true)
end
end
end
end
end


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


local function constantFormat(a)
if not a then return ' ' end
local sCC = ('%.1f'):format(a.constant)
return a.old and tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCC)) or sCC
end
function p.detail()
function p.detail()
local mSong = songMap()
local datas = {}
local datas = {}
for id, songCD in pairs(mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())) do
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
local song = mSong[id]
for _, song in ipairs(mad.listOf 'songs') do
local query = mad.songQueryWrap(song)
if not song.deleted then
local data = {query.linkTitle}
local id = song.id
local rowData = {data = data, sort = {(songCD[query.bydDate and 3 or 4] or songCD[3]).constant, song.date}}
local songCc = songCcs[id] or {}
table.insert(datas, rowData)
--
for i = 1, 4 do
local data = {mad.linkTitle(song)}
table.insert(data, constantFormat(songCD[i]))
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
end
end
第106行: 第116行:


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

2024年11月25日 (一) 20:40的最新版本

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

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

-- 分界参数
local ccmax = 13    --容纳的最大定数,一般为最高定级+1
local divide = 11.4 --分界定数,低于此定数按0.1划分(值需≤间断定数,当前为11.8)
-- local divide = 11.4

local function itData(datas, cc)
	cc = cc or ccmax
	local step = cc > divide and ccmax-divide or .1
	cc = cc - step
	local id = ('%.1f'):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())
	local divide_str = ('%.1f'):format(divide)
	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 >= divide then
						rowId = divide_str
						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
		if rowId==divide_str then rowId=('≥%s'):format(divide_str) end
		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