Module:ChartConstant:修订间差异

来自Arcaea中文维基
(补last的洞 (这洞怎么还在这 我还以为早有人修完了.jpg))
(已还原Star0讨论)的编辑至最后由Economy666修订的版本)
标签回退
 
(未显示6个用户的27个中间版本)
第1行: 第1行:
local mad = require 'Module:AnotherData'
local p = {}
local p = {}
local chartConstantList = require("Module:LoadJson").ChartConstant()
-- ns待补充(ns也不需要这个)
local songlist = require("Module:LoadJson").Songlist()
-- 需要输出详表(如存档旧ptt数据)的话控制台直接print(p.detail()) 就行了


-- 分界参数
local ccmax = 13   --容纳的最大定数,一般为最高定级+1
local divide = 11.0 --分界定数,低于此定数按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 function cv()
local rowId, sCc
local list = {}
if nCc >= divide then
for i,k in pairs(songlist['songs'])
rowId = divide_str
do
sCc = ('%.1f'):format(nCc)
list[k['id']] = {
else
k['title_localized']['en'],
rowId = ('%.1f'):format(nCc)
k["date"],
end
nil,
local rowData = datas[rowId]
nil
if not rowData then
}
rowData = {}
if k["difficulties"][4] then
datas[rowId] = rowData
if k["difficulties"][4]["title_localized"] then
end
list[k['id']][3] = k["difficulties"][4]["title_localized"]["en"]
table.insert(rowData, {
end
data = {title, id, ({'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[rc], link = link, CC = sCc},
if k["difficulties"][4]["date"] then
sort = {nCc, rc, date}
list[k['id']][4] = k["difficulties"][4]["date"]
})
until (true)
end
end
end
end
end
end
return list
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


local specialSongNameConverter = {
return tostring(text)
["#1f1e33"] = "#1f1e33",
end
   ["AI[UE]OON"] = "AI[UE]OON",
   ["Last | Eternity"] = "Last",
   ["Last | Moment"] = "Last"
}
local n = {
   ["Last | Eternity"] = "Last \| Eternity",
   ["Last | Moment"] = "Last \| Moment"
}


function p.main()
function p.detail()
local list = {}
local datas = {}
local name
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
local cvList = cv()
for _, song in ipairs(mad.listOf 'songs') do
   for i, k in pairs(chartConstantList) do
if not song.deleted then
   if k[2] or k[3] or k[4] then
local id = song.id
   name = cvList[i][1]
local songCc = songCcs[id] or {}
end
--
     local link = name
local data = {mad.linkTitle(song)}
     if specialSongNameConverter[name] then
local sort = {0, song.date}
       link = specialSongNameConverter[name]
table.insert(datas, {data = data, sort = sort})
     end
for _, chart in ipairs(song.difficulties) do
if n[name] then
local rc = chart.ratingClass + 1
name = n[name]
local chartCc = songCc[rc]
end
repeat
   if k[2] and tonumber(k[2]['constant'])>=8 and not(k[2]['old']) then
if not chartCc then break end
   table.insert(list, { i, name, k[2]['constant'], "PRS", link, cvList[i][2] })
local nCc = chartCc.constant
   end
if not chart.date then sort[1] = nCc end
   if k[3] and tonumber(k[3]['constant'])>=8 and not(k[3]['old']) then
local sCc = ('%.1f'):format(nCc)
   table.insert(list, { i, name, k[3]['constant'], "FTR", link, cvList[i][2] })
data[rc + 1] = chartCc.old ~= false and tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCc)) or sCc
   end
until (true)
   if k[4] and tonumber(k[4]['constant'])>=8 and not(k[4]['old']) then
   if cvList[i][3] then
name = cvList[i][3]
end
end
if cvList[i][4] then
for i = 2, 6 do
table.insert(list, { i, name, k[4]['constant'], "BYD", link, cvList[i][4] })
data[i] = data[i] or ' '
else
   table.insert(list, { i, name, k[4]['constant'], "BYD", link, cvList[i][2] })
end
end
   end
end
   end
  
 
-- make lists
   local result = {}
   local mid_result = {}
   result[11], result[12] = {}, {}
   mid_result[11], mid_result[12] = {}, {}
 
   for s, k in pairs(list) do
     if not(mid_result[k[3]]) then mid_result[k[3]]={} end
     if k[3]>=11 then
       if k[3]>=12 then
         table.insert(mid_result[12], k)
       else
         table.insert(mid_result[11], k)
       end
     else table.insert(mid_result[k[3]], k) end
   end
 
 
   -- sort songs
   local diffConverter = { PRS=2, FTR=3, BYD=4 }
   for s, k in pairs(mid_result) do
     table.sort(k, function (a, b)
       if not(a[3]==b[3]) then
         return a[3]>b[3]
       end
return a[6]<b[6]
--[=[
       if not(diffConverter[a[4]]==diffConverter[b[4]]) then
         return diffConverter[a[4]]>diffConverter[b[4]]
       else return string.upper(a[2])<string.upper(b[2]) end
]=]
     end)
   end
 
 
-- use template
-- 组排单元 第一个参数是曲名,第二个是id,第三个是难度,link字面意思
   for s, k in pairs(mid_result) do
   if s<11 then
   if not(result[s]) then result[s]={} end
       for n, m in pairs(k) do
         table.insert(result[s],mw.getCurrentFrame():expandTemplate { title = '组排单元', args = { m[2], m[1], m[4], link=m[5] } } )
       end
   else
   if s<12 then
   for n, m in pairs(k) do
           table.insert(result[11],mw.getCurrentFrame():expandTemplate { title = '组排单元', args = { m[2], m[1], m[4], CC = string.format("%.1f", m[3]), link=m[5] } } )
         end
   else
   for n, m in pairs(k) do
           table.insert(result[12],mw.getCurrentFrame():expandTemplate { title = '组排单元', args = { m[2], m[1], m[4], CC = string.format("%.1f", m[3]), link=m[5] } } )
         end
   end
   end
   end
 
 
-- sort constants
local sortTable = {}
for i,k in pairs(result) do
table.insert(sortTable, {i, k})
end
end
table.sort(sortTable, function(a,b) return a[1] > b[1] 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)


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


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


return p
return p

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

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

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

-- 分界参数
local ccmax = 13    --容纳的最大定数,一般为最高定级+1
local divide = 11.0 --分界定数,低于此定数按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