The VNDev Wiki underwent maintenance on March 14th, 2025, which is now complete. Semantic MediaWiki and associated extensions have been updated, and Scribunto and Semantic Scribunto have been installed. If you encounter any bugs or unexpected behavior, especially with VN jam statistics pages, please let the wiki admins know via the DevTalk Discord server.
Module:Jam series detailed stats: Difference between revisions
From VNDev Wiki
m oops |
m oh god dang it |
||
(11 intermediate revisions by the same user not shown) | |||
Line 43: | Line 43: | ||
for i,arg in pairs( frame.args ) do | for i,arg in pairs( frame.args ) do | ||
if | if arg ~= statType then | ||
toRet = toRet .. arg .. '\n' | --toRet = toRet .. arg .. '\n' | ||
table.insert(groups, mw.text.split(arg, '-', true ) ) | |||
end | end | ||
end | end | ||
--return toRet | |||
local zeroSubQ = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::0]]' } | |||
zeroSubQ.format = 'count' | |||
local zeroCount = mw.smw.ask( zeroSubQ ) | |||
local zeroCol = { 'Has sort order=0', 'Has label=None', 'Has count=' .. mw.smw.ask( zeroSubQ ) } | |||
local resultZero = mw.smw.subobject( zeroCol ) | |||
local resultFinal = false | |||
if resultZero == true then resultFinal = true end | |||
for i=1,#groups do | |||
if groups[i] ~= nil then | |||
local subQ = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::>' .. groups[i][1] .. ']]', '[[Has ' .. statType .. '::<' .. groups[i][2] ..']]' } | |||
subQ.format = 'count' | |||
local resultI = mw.smw.subobject ( { 'Has sort order=' .. groups[i][1], 'Has label=' .. groups[i][1] .. '-' .. groups[i][2], 'Has count=' .. mw.smw.ask( subQ ) } ) | |||
if resultI ~= true then resultFinal = false end | |||
end | |||
end | |||
return resultFinal | |||
end | |||
function p.statDesc( frame ) | |||
local statType = 'entries' | |||
if frame.args['statType'] ~= nil then statType = frame.args['statType'] end | |||
local seriesName = 'Spooktober Visual Novel Jam' | |||
if frame.args['seriesName'] ~= nil then seriesName = frame.args['seriesName'] end | |||
local occurQuery = { '[[Jam occurrence:+]]', '[[Is occurrence of::' .. seriesName .. ']]', '[[Has end date::<' .. mw.getContentLanguage():formatDate('M j Y') .. ']]', '[[Has ' .. statType .. '::+]]', '?Has short name=shortName', '?Has ' .. statType .. '#-=count', '?Has end date#-F[U]=endDate' } | |||
local occur = mw.smw.ask(occurQuery) | |||
if type( occur ) ~= "table" then return 'ERROR' end | |||
local numOccur = 0 | |||
local sumCount = 0 | |||
local largestCount = 0 | |||
local largestName = 'ERROR' | |||
local newestCount = 0 | |||
local newestDate = 0 | |||
local newestName = 'ERROR' | |||
for i=1, #occur do | |||
if occur[i] ~= nil then | |||
numOccur = numOccur + 1 | |||
sumCount = sumCount + occur[i].count | |||
if occur[i].count > largestCount then | |||
largestCount = occur[i].count | |||
largestName = occur[i].shortName | |||
end | |||
if tonumber(occur[i].endDate) > newestDate then | |||
newestCount = occur[i].count | |||
newestDate = tonumber(occur[i].endDate) | |||
newestName = occur[i].shortName | |||
end | |||
end | |||
end | |||
local avgCount = p.round(sumCount / numOccur, 2) | |||
local toRet = '' | |||
toRet = toRet .. seriesName .. ' has had ' .. avgCount .. ' ' .. statType .. ' on average, across ' .. numOccur .. ' occurrences. This is ' | |||
toRet = toRet .. p.prText( avgCount, statType ) .. ' of jam occurrences. \n\n' | |||
toRet = toRet .. 'The largest occurrence by ' .. statType .. ', which was ' .. largestName .. ', had ' .. largestCount .. ' ' .. statType .. '. This is ' | |||
toRet = toRet .. p.prText( largestCount, statType ) .. ' of jam occurrences. \n\n' | |||
toRet = toRet .. 'The most recent occurrence, which was ' .. newestName .. ', had ' .. newestCount .. ' ' .. statType .. '. This is ' | |||
toRet = toRet .. p.prText( newestCount, statType ) .. ' of jam occurrences.' | |||
return toRet | |||
end | |||
function p.percentileRank( count, statType ) | |||
local cfQuery = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::<' .. count .. ']]' } | |||
cfQuery.format = 'count' | |||
local fQuery = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::' .. count .. ']]' } | |||
fQuery.format = 'count' | |||
local nQuery = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::+]]' } | |||
nQuery.format = 'count' | |||
local cf = mw.smw.ask(cfQuery) | |||
local f = mw.smw.ask(fQuery) | |||
local n = mw.smw.ask(nQuery) | |||
local pr = 0.5 * f | |||
pr = cf - pr | |||
pr = pr / n | |||
pr = pr * 100 | |||
return p.round(pr, 0) | |||
end | |||
function p.prText( count, statType ) | |||
local text = 'higher' | |||
local prNum = p.percentileRank( count, statType ) | |||
if prNum <= 50 then | |||
text = 'lower' | |||
prNum = 100 - prNum | |||
end | |||
return text .. ' than ' .. prNum .. '%' | |||
end | |||
function p.round(num, numDecimalPlaces) | |||
local mult = 10^(numDecimalPlaces or 0) | |||
return math.floor(num * mult + 0.5) / mult | |||
end | |||
function p.shouldShowDetailsButton( frame ) | |||
local seriesName = 'Spooktober Visual Novel Jam' | |||
if frame.args['seriesName'] ~= nil then seriesName = frame.args['seriesName'] end | |||
local toRet = '' | |||
if p.shouldShowStat('entries', seriesName) == 'yes' or p.shouldShowStat('participants', seriesName) == 'yes' then toRet = 'yes' end | |||
return toRet | return toRet | ||
end | |||
function p.shouldShowDetailsCat( frame ) | |||
return p.shouldShowStat(frame.args['statType'], frame.args['seriesName']) | |||
end | |||
function p.shouldShowStat(statType, seriesName) | |||
local occurQuery = { '[[Jam occurrence:+]]', '[[Is occurrence of::' .. seriesName .. ']]', '[[Has end date::<' .. mw.getContentLanguage():formatDate('M j Y') .. ']]', '[[Has ' .. statType .. '::+]]', '?Has short name=shortName', '?Has ' .. statType .. '#-=count', '?Has end date#-F[U]=endDate' } | |||
local occur = mw.smw.ask(occurQuery) | |||
if type( occur ) ~= "table" then return '' end | |||
if #occur == nil or #occur == 0 then return '' end | |||
local sumCount = 0 | |||
for i=1, #occur do | |||
if occur[i] ~= nil then | |||
if occur[i].count ~= nil then sumCount = sumCount + occur[i].count end | |||
end | |||
end | |||
if sumCount == 0 then return '' end | |||
return 'yes' | |||
end | end | ||
return p | return p |
Latest revision as of 14:48, 17 March 2025
Documentation for this module may be created at Module:Jam series detailed stats/doc
local p = {}
function p.prepHistData( frame )
local statType = frame.args['statType']
local width = frame.args['width']
local q = { '[[Jam occurrence:+]]', '?Has ' .. statType .. '=count' }
q.sort = 'Has ' .. statType
q.order = 'descending'
q.limit = 1
q.mainheader = '-'
local maxCount = mw.smw.ask( q )
local numIntervals = math.ceil( maxCount[1].count / width )
local zeroSubQ = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::0]]' }
zeroSubQ.format = 'count'
local zeroCount = mw.smw.ask( zeroSubQ )
local zeroCol = { 'Has sort order=0', 'Has label=None', 'Has count=' .. mw.smw.ask( zeroSubQ ) }
local resultZero = mw.smw.subobject( zeroCol )
local resultFinal = false
if resultZero == true then resultFinal = true end
for i=1,numIntervals do
local subQ = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::>' .. (width * (i-1)) + 1 .. ']]', '[[Has ' .. statType .. '::<' .. width * i ..']]' }
subQ.format = 'count'
local resultI = mw.smw.subobject ( { 'Has sort order=' .. i, 'Has label=' .. (width * (i-1)) + 1 .. '-' .. width * i, 'Has count=' .. mw.smw.ask( subQ ) } )
if resultI ~= true then resultFinal = false end
end
return resultFinal
end
function p.prepHistDataCustom( frame )
local statType = frame.args['statType']
local groups = {}
local toRet = ''
for i,arg in pairs( frame.args ) do
if arg ~= statType then
--toRet = toRet .. arg .. '\n'
table.insert(groups, mw.text.split(arg, '-', true ) )
end
end
--return toRet
local zeroSubQ = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::0]]' }
zeroSubQ.format = 'count'
local zeroCount = mw.smw.ask( zeroSubQ )
local zeroCol = { 'Has sort order=0', 'Has label=None', 'Has count=' .. mw.smw.ask( zeroSubQ ) }
local resultZero = mw.smw.subobject( zeroCol )
local resultFinal = false
if resultZero == true then resultFinal = true end
for i=1,#groups do
if groups[i] ~= nil then
local subQ = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::>' .. groups[i][1] .. ']]', '[[Has ' .. statType .. '::<' .. groups[i][2] ..']]' }
subQ.format = 'count'
local resultI = mw.smw.subobject ( { 'Has sort order=' .. groups[i][1], 'Has label=' .. groups[i][1] .. '-' .. groups[i][2], 'Has count=' .. mw.smw.ask( subQ ) } )
if resultI ~= true then resultFinal = false end
end
end
return resultFinal
end
function p.statDesc( frame )
local statType = 'entries'
if frame.args['statType'] ~= nil then statType = frame.args['statType'] end
local seriesName = 'Spooktober Visual Novel Jam'
if frame.args['seriesName'] ~= nil then seriesName = frame.args['seriesName'] end
local occurQuery = { '[[Jam occurrence:+]]', '[[Is occurrence of::' .. seriesName .. ']]', '[[Has end date::<' .. mw.getContentLanguage():formatDate('M j Y') .. ']]', '[[Has ' .. statType .. '::+]]', '?Has short name=shortName', '?Has ' .. statType .. '#-=count', '?Has end date#-F[U]=endDate' }
local occur = mw.smw.ask(occurQuery)
if type( occur ) ~= "table" then return 'ERROR' end
local numOccur = 0
local sumCount = 0
local largestCount = 0
local largestName = 'ERROR'
local newestCount = 0
local newestDate = 0
local newestName = 'ERROR'
for i=1, #occur do
if occur[i] ~= nil then
numOccur = numOccur + 1
sumCount = sumCount + occur[i].count
if occur[i].count > largestCount then
largestCount = occur[i].count
largestName = occur[i].shortName
end
if tonumber(occur[i].endDate) > newestDate then
newestCount = occur[i].count
newestDate = tonumber(occur[i].endDate)
newestName = occur[i].shortName
end
end
end
local avgCount = p.round(sumCount / numOccur, 2)
local toRet = ''
toRet = toRet .. seriesName .. ' has had ' .. avgCount .. ' ' .. statType .. ' on average, across ' .. numOccur .. ' occurrences. This is '
toRet = toRet .. p.prText( avgCount, statType ) .. ' of jam occurrences. \n\n'
toRet = toRet .. 'The largest occurrence by ' .. statType .. ', which was ' .. largestName .. ', had ' .. largestCount .. ' ' .. statType .. '. This is '
toRet = toRet .. p.prText( largestCount, statType ) .. ' of jam occurrences. \n\n'
toRet = toRet .. 'The most recent occurrence, which was ' .. newestName .. ', had ' .. newestCount .. ' ' .. statType .. '. This is '
toRet = toRet .. p.prText( newestCount, statType ) .. ' of jam occurrences.'
return toRet
end
function p.percentileRank( count, statType )
local cfQuery = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::<' .. count .. ']]' }
cfQuery.format = 'count'
local fQuery = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::' .. count .. ']]' }
fQuery.format = 'count'
local nQuery = { '[[Jam occurrence:+]]', '[[Has ' .. statType .. '::+]]' }
nQuery.format = 'count'
local cf = mw.smw.ask(cfQuery)
local f = mw.smw.ask(fQuery)
local n = mw.smw.ask(nQuery)
local pr = 0.5 * f
pr = cf - pr
pr = pr / n
pr = pr * 100
return p.round(pr, 0)
end
function p.prText( count, statType )
local text = 'higher'
local prNum = p.percentileRank( count, statType )
if prNum <= 50 then
text = 'lower'
prNum = 100 - prNum
end
return text .. ' than ' .. prNum .. '%'
end
function p.round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function p.shouldShowDetailsButton( frame )
local seriesName = 'Spooktober Visual Novel Jam'
if frame.args['seriesName'] ~= nil then seriesName = frame.args['seriesName'] end
local toRet = ''
if p.shouldShowStat('entries', seriesName) == 'yes' or p.shouldShowStat('participants', seriesName) == 'yes' then toRet = 'yes' end
return toRet
end
function p.shouldShowDetailsCat( frame )
return p.shouldShowStat(frame.args['statType'], frame.args['seriesName'])
end
function p.shouldShowStat(statType, seriesName)
local occurQuery = { '[[Jam occurrence:+]]', '[[Is occurrence of::' .. seriesName .. ']]', '[[Has end date::<' .. mw.getContentLanguage():formatDate('M j Y') .. ']]', '[[Has ' .. statType .. '::+]]', '?Has short name=shortName', '?Has ' .. statType .. '#-=count', '?Has end date#-F[U]=endDate' }
local occur = mw.smw.ask(occurQuery)
if type( occur ) ~= "table" then return '' end
if #occur == nil or #occur == 0 then return '' end
local sumCount = 0
for i=1, #occur do
if occur[i] ~= nil then
if occur[i].count ~= nil then sumCount = sumCount + occur[i].count end
end
end
if sumCount == 0 then return '' end
return 'yes'
end
return p