Module:Peter Bowman/statystyka

From Wikipedia

Documentation for this module may be created at Module:Peter Bowman/statystyka/doc

local p = {}

local langs = { asturyjski = { a = 5000 } }

local pagesInCategory = mw.site.stats.pagesInCategory
local langobject      = mw.language.new( 'pl' )

local tcounter, mcounter

local function makeRow( html, lang, conf, stat )
	local pagecount = pagesInCategory( 'Citation templates'--[[lang .. ' (indeks)']], 'pages' )
	local langCSS   = {
		[ 'background-color' ] = ( pagecount > ( conf.a or 500 ) )
			and 'yellow'
			or  conf.n
				and 'silver'
				or  nil,
		[ 'white-space' ] = 'nowrap'
	}
	
	html:tag( 'td' ):attr( 'align', 'center' ):css( langCSS )
		:tag( 'span' ):attr( 'id', 'sort name' ):css( 'display', 'none' )
			:wikitext( ( conf.s or '' ) .. lang ):done()
		:wikitext(
			'[[:Kategoria:' .. lang .. ' (indeks)|' .. lang .. ']]' ..
			( conf.r or '' ) ..
			' ([[:Kategoria:' .. ( conf.w and langobject:ucfirst( lang ) or 'Język ' .. lang ) .. '|⌘]])' ..
			( conf.p and ' ([[:Portal:' .. langobject:ucfirst( lang ) .. '|P]])' or '' )
		)
		
	html:tag( 'td' ):attr( 'align', 'right' ):css( 'width', '30px' )
		:tag( 'span' ):attr( 'id', 'sort count' ):css( 'display', 'none' ):wikitext( pagecount ):done()
		:tag( 'small' ):wikitext( string.format( '%.3f', ( pagecount / tcounter ) * 100 ) .. '%' )
	
	html:tag( 'td' ):tag( 'div' ):css{
			[ 'width' ]            = ( pagecount / 150 ) .. 'px',
			[ 'background-color' ] = 'maroon'
		}
		:wikitext( ' ' )

	html:tag( 'td' ):attr( 'align', 'right' ):css( 'width', '200px' )
		:wikitext( pagecount .. ( conf.r2 or '' ) )
	
	html:tag( 'td' ):attr( 'align', 'right' ):wikitext( stat )
end

p.main = function( frame )
	--local stats = mw.title.new( 'User:AlkamidBot/statystyka/znaczenia średnia/template' ):getContent()
	
	tcounter = 481000--frame:expandTemplate{ title = 'licznik' }
	mcounter = 585964--frame:expandTemplate{ title = 'licznikZnaczeń' }
	
	local data  = { asturyjski = 1.04 }
	
	--[[for lang, stat in string.gfind( stats, '\n|(.-)=(.-)\n' ) do
		data[ lang ] = tonumber( stat )
	end]]
	
	local header = mw.html.create( 'tr' )
	
	header:tag( 'th' ):addClass( 'unsortable ordinal' ):wikitext( 'lp.' )
	header:tag( 'th' ):css( 'text-align', 'center' ):wikitext( 'język' )
	header:tag( 'th' ):css( 'border-right-style', 'hidden' )
	header:tag( 'th' ):addClass( 'unsortable' ):wikitext( 'licznik haseł' )
	header:tag( 'th' ):css{
			[ 'width' ]             = '100px',
			[ 'white-space' ]       = 'nowrap',
			[ 'border-left-style' ] = 'hidden'
		}
	header:tag( 'th' ):css( 'white-space', 'nowrap' )
			:tag( 'small' )
			:tag( 'ref', { selfClosing = true } ):attr( 'name', 'licznikZnaczeń' )
	
	local contents = mw.html.create( '' )
	local position = 0
	
	for lang, conf in pairs( langs ) do
		position = position + 1

		makeRow(
			contents:tag( 'tr' )
				:tag( 'td' ):wikitext( position ):done(),
			lang,
			conf,
			data[ lang ]
				and string.format( "%.0f", data[ lang ] * 2176--[[frame:expandTemplate{
						title = 'licznik',
						args  = { lang }
					}]] )
				or  '0'
		)
	end
	
	local footer = mw.html.create( 'tr' ):addClass( 'sortbottom' )
	
	footer:tag( 'td' )
	footer:tag( 'td' ):attr( 'align', 'right' )
			:tag( 'b' ):wikitext( 'Razem:' )
	footer:tag( 'td' ):attr( 'align', 'right' )
			:tag( 'small' ):wikitext( '100%' )
	footer:tag( 'td' )
	footer:tag( 'td' ):attr( 'align', 'right' )
			:tag( 'b' ):wikitext( tcounter )
	footer:tag( 'td' ):attr( 'align', 'right' )
			:tag( 'b' ):wikitext( tcounter )
	
	return mw.html.create( 'table' )
		:addClass( 'wikitable sortable' )
		:css{
			[ 'margin' ]     = '0',
			[ 'text-align' ] = 'left'
		}
		:node( header )
		:node( contents )
		:node( footer )
end

return p