Module:Leaderboard: Difference between revisions

From Sagan 4 Alpha Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
 
(18 intermediate revisions by the same user not shown)
Line 6: Line 6:
--Generate a leaderboard of sagan 4 submissions under certain parameters
--Generate a leaderboard of sagan 4 submissions under certain parameters
local mainCat = frame.args[1] or "Species" --the submission type category to be used (leaving it open for landmarks)
local mainCat = frame.args[1] or "Species" --the submission type category to be used (leaving it open for landmarks)
local taxon = frame.args["taxon"] or "Eukaryota" --Ever wanted to know who made the most saucebacks? Was it Ovi? Was it Hydro? Was it me? Who knows!
local taxon = frame.args["taxon"] or "+" --Ever wanted to know who made the most saucebacks? Was it Ovi? Was it Hydro? Was it me? Who knows!
local week = frame.args["week"] or "+" --so Species Georg can be overtaken short-term
local week = frame.args["week"] or "+" --so Species Georg can be overtaken short-term
local gen = frame.args["generation"] or frame.args["gen"] or "+" --or even shorter-term ig
local gen = frame.args["generation"] or frame.args["gen"] or "+" --or even shorter-term ig
Line 13: Line 13:
local leaderType = frame.args["property"] or "Creator"
local leaderType = frame.args["property"] or "Creator"
local label = frame.args["label"] or "Leaderboard"
local label = frame.args["label"] or "Leaderboard"
local exstatus = frame.args["status"] or "+"
local biotatype = frame.args["biota type"] or "+"
local exgen = ""
if frame.args["exgen"] then
exgen = "[[exgen::"..frame.args["exgen"].."]]"
end
local PropList = ""
local PropList = ""
Line 19: Line 26:
local debugtext = ""
local debugtext = ""
local count = tonumber(frame:callParserFunction('#ask',{'[[Category:'..mainCat..']][[Taxonomy::'..taxon..']][[Week::'..week..']][[Generation::'..gen..']]'..whateverProperty,format="count"}))
local count = tonumber(frame:callParserFunction('#ask',{'[[Category:'..mainCat..']][[Biota type::'..biotatype..']][[Taxonomy::'..taxon..']][[Week::'..week..']][[Generation::'..gen..']][[Status::'..exstatus..']]'..whateverProperty..exgen,format="count"}))
local smwlimit = 500
local smwlimit = 500
while not endNextLoop do
while not endNextLoop do
if currentOffset > count then
if smwlimit ~= 500 then
smwlimit = currentOffset - count
debugtext = currentOffset..", "..count..", "..smwlimit
endNextLoop = true
endNextLoop = true
end
end
if currentOffset > count then
local smwResult = frame:callParserFunction('#ask',{'[[Category:'..mainCat..']][[Taxonomy::'..taxon..']][[Week::'..week..']][[Generation::'..gen..']]'..whateverProperty,"?"..leaderType,limit=tostring(smwlimit),searchlabel="",offset=tostring(currentOffset),format="plainlist",headers="hide",mainlabel="-"})
debugtext = debugtext..", and yet we see the offset at "..currentOffset
end
local smwResult = frame:callParserFunction('#ask',{'[[Category:'..mainCat..']][[Biota type::'..biotatype..']][[Taxonomy::'..taxon..']][[Week::'..week..']][[Generation::'..gen..']][[Status::'..exstatus..']]'..whateverProperty..exgen,"?"..leaderType,limit=tostring(smwlimit),searchlabel="",offset=tostring(currentOffset),format="plainlist",headers="hide",mainlabel="-"})
if smwResult == "" then break end
if smwResult == "" then break end
PropList = PropList..", "..smwResult
PropList = PropList..", "..smwResult
if currentOffset + 500 > count then
currentOffset = currentOffset + 500
currentOffset = currentOffset + (currentOffset + 500 - count)
else
currentOffset = currentOffset + 500
end
--debugtext = debugtext.."\n\n"..tostring(currentOffset)
--debugtext = debugtext.."\n\n"..tostring(currentOffset)
if currentOffset + 500 > count and endNextLoop == false then
smwlimit = count - currentOffset
debugtext = count..", "..currentOffset + smwlimit
--endNextLoop = true
end
end
end
Line 52: Line 61:
local proxyTable = {}
local proxyTable = {}
for propval, count in pairs(PropTable) do
for propval, count in pairs(PropTable) do
if leaderType == "Creator" or leaderType == "Artist" then
table.insert(proxyTable,{property=propval,total=count})
table.insert(proxyTable,{property='[[User:'..propval..'|'..propval..']]',total=count})
elseif leaderType == "Domain" or leaderType == "Kingdom" or leaderType == "Phylum" or leaderType == "Class" or leaderType == "Order" or leaderType == "Family" then
table.insert(proxyTable,{property="{{#queryformlink:form=ViewTaxon|query string=ViewTaxon[taxon]="..propval.."&_run|link text="..propval.."}}",total=count})
elseif leaderType == "Ancestor" then
table.insert(proxyTable,{property='[['..propval..']]',total=count})
else
table.insert(proxyTable,{property=propval,total=count})
end
end
end
Line 60: Line 78:
--generate leaderboard table
--generate leaderboard table
local leaderboardTable = '{| class="wikitable"\n!colspan="3"|'..label..'!!n/entries\n|-'
local leaderboardTable = '{| class="wikitable" style="width: 250px;"\n!colspan="3"|'..label..'!!n/entries\n|-'
--local currentPlace = 0
--local currentPlace = 0
--local lastValue = 0
--local lastValue = 0
Line 73: Line 91:
end
end
return leaderboardTable.."\n"..debugtext--..PropList
return frame:preprocess(leaderboardTable)--.."\n"..debugtext--..PropList
end
end



Latest revision as of 20:54, 21 June 2024

--Tools for displaying leaderboards
--WIP
local p = {}
local userlist = mw.loadJsonData('Module:Leaderboard/users.json')
function p.main(frame)
	--Generate a leaderboard of sagan 4 submissions under certain parameters
	local mainCat = frame.args[1] or "Species" --the submission type category to be used (leaving it open for landmarks)
	local taxon = frame.args["taxon"] or "+" --Ever wanted to know who made the most saucebacks? Was it Ovi? Was it Hydro? Was it me? Who knows!
	local week = frame.args["week"] or "+" --so Species Georg can be overtaken short-term
	local gen = frame.args["generation"] or frame.args["gen"] or "+" --or even shorter-term ig
	local whateverProperty = frame.args[2] or "" --psuedo-smw goes here so I don't have to be in pain about people wanting to do More leaderboards than I accounted for
	local limit = frame.args["limit"] or "10"
	local leaderType = frame.args["property"] or "Creator"
	local label = frame.args["label"] or "Leaderboard"
	local exstatus = frame.args["status"] or "+"
	local biotatype = frame.args["biota type"] or "+"
	
	local exgen = ""
	if frame.args["exgen"] then
		exgen = "[[exgen::"..frame.args["exgen"].."]]"
	end
	
	local PropList = ""
	local currentOffset = 0
	local endNextLoop = false
	local debugtext = ""
	
	local count = tonumber(frame:callParserFunction('#ask',{'[[Category:'..mainCat..']][[Biota type::'..biotatype..']][[Taxonomy::'..taxon..']][[Week::'..week..']][[Generation::'..gen..']][[Status::'..exstatus..']]'..whateverProperty..exgen,format="count"}))
	local smwlimit = 500
	
	while not endNextLoop do
		if smwlimit ~= 500 then
			endNextLoop = true
		end
		if currentOffset > count then
			debugtext = debugtext..", and yet we see the offset at "..currentOffset
		end
		local smwResult = frame:callParserFunction('#ask',{'[[Category:'..mainCat..']][[Biota type::'..biotatype..']][[Taxonomy::'..taxon..']][[Week::'..week..']][[Generation::'..gen..']][[Status::'..exstatus..']]'..whateverProperty..exgen,"?"..leaderType,limit=tostring(smwlimit),searchlabel="",offset=tostring(currentOffset),format="plainlist",headers="hide",mainlabel="-"})
		if smwResult == "" then break end
		PropList = PropList..", "..smwResult
		currentOffset = currentOffset + 500
		--debugtext = debugtext.."\n\n"..tostring(currentOffset)
		if currentOffset + 500 > count and endNextLoop == false then
			smwlimit = count - currentOffset
			debugtext = count..", "..currentOffset + smwlimit
			--endNextLoop = true
		end
	end
	
	--local PropArray = string.gmatch(PropList, '([^,]+)')
	local PropTable = {}
	
	for prop in string.gmatch(PropList, '([^,]+)') do
		prop = prop:match("^%s*(.-)%s*$")
		if not PropTable[prop] then
			PropTable[prop] = 0
		end
		PropTable[prop] = PropTable[prop] + 1
	end
	
	local proxyTable = {}
	for propval, count in pairs(PropTable) do
		if leaderType == "Creator" or leaderType == "Artist" then
			table.insert(proxyTable,{property='[[User:'..propval..'|'..propval..']]',total=count})
		elseif leaderType == "Domain" or leaderType == "Kingdom" or leaderType == "Phylum" or leaderType == "Class" or leaderType == "Order" or leaderType == "Family" then
			table.insert(proxyTable,{property="{{#queryformlink:form=ViewTaxon|query string=ViewTaxon[taxon]="..propval.."&_run|link text="..propval.."}}",total=count})
			
		elseif leaderType == "Ancestor" then
			table.insert(proxyTable,{property='[['..propval..']]',total=count})
		else
			table.insert(proxyTable,{property=propval,total=count})
		end
	end
	
	table.sort(proxyTable, function(a,b)
		return a.total > b.total
	end)
	
	--generate leaderboard table
	local leaderboardTable = '{| class="wikitable" style="width: 250px;"\n!colspan="3"|'..label..'!!n/entries\n|-'
	--local currentPlace = 0
	--local lastValue = 0
	
	for i, item in pairs(proxyTable) do
		leaderboardTable = leaderboardTable..'\n|\'\'\''..tostring(i)..'\'\'\'\n|colspan="2"|'..item.property.."\n|"..item.total..'\n|-'
		
		if i + 1 == limit + 1 then
			leaderboardTable = leaderboardTable..'\n|}'
			break
		end
	end
	
	return frame:preprocess(leaderboardTable)--.."\n"..debugtext--..PropList
end




return p