Uwaga |
---|
Moduł:statystyka
Przejdź do nawigacji
Przejdź do wyszukiwania
Moduł obsługujący główną tabelkę danych statystycznych na stronie Wikisłownik:Statystyka oraz szablony liczników. Zobacz też: /dane.
local langs = require 'Module:statystyka/dane'
local bdate = langs.date or 'bd.'
local LIMIT = 495 -- było: 500
local p = {}
local pagesInCategory = mw.site.stats.pagesInCategory
-- http://lua-users.org/wiki/FormattingNumbers
local function formatNum( num )
while true do
num, k = string.gsub( num, "^(-?%d+)(%d%d%d)", '%1 %2' )
if k == 0 then break end
end
return num
end
local function traverseIndexes( prop, op, callback )
local count = 0
local maxterms = 0
for position, langdata in ipairs( langs ) do
local langname = langdata[ 1 ]
local options = langdata[ 2 ] or {}
local propcount = 0
if position > LIMIT then
break
end
if prop == 'terms' then
propcount = pagesInCategory( langname .. ' (' .. op .. ')', 'pages' )
if not options.x then
count = count + propcount
end
elseif prop == 'meanings' then
if not op or op == langname then
local pagecount = pagesInCategory( langname .. ' (indeks)', 'pages' )
propcount = math.floor( ( options.z or 0 ) * pagecount )
if not op then
count = count + propcount
else
return propcount
end
else
count = 0
end
end
if callback then
local terms = callback{ position, langname, options, propcount }
if terms > maxterms then
maxterms = terms
end
end
end
return count, maxterms
end
p.WS_STAT = function( frame )
local tcounter = 0
local mcounter = 0
local maxtcount = 0
local langobject = mw.language.new( 'pl' )
local references = {
[ 'licznikZnaczeń' ] = 'W jednym haśle może być więcej niż jedno znaczenie, są one oznaczane kolejnymi numerami, np. (1.1), (1.2), itd. Statystyki znaczeń są oszacowane na podstawie zrzutu bazy danych z dnia ' .. bdate .. ' (średnia liczba znaczeń na hasło z tego dnia pomnożona jest przez aktualną liczbę haseł). Pozostałe dane w tej tabeli są aktualizowane na bieżąco.',
[ 'polski język migowy' ] = 'Wyjątkowo liczone są tu tłumaczenia na PJM – znaki migowe nie mają własnych sekcji.',
[ 'użycie międzynarodowe' ] = 'Znaki i symbole stosowane niezależnie od języka.',
[ 'znak chiński' ] = 'Wykorzystywane w kilku językach.'
}
local function makeRow( pos, lang, conf, pagecount )
local columns = {
key = -pagecount,
key2 = lang,
lang = mw.html.create( 'td' ),
['%'] = mw.html.create( 'td' ),
hbar = mw.html.create( 'td' ),
pcount = mw.html.create( 'td' ),
mcount = mw.html.create( 'td' ),
pagecount = pagecount
}
local langCSS = {
[ 'background-color' ] = ( pagecount > ( conf.a or 500 ) )
and 'yellow'
or conf.n
and 'silver'
or nil,
[ 'white-space' ] = 'nowrap'
}
local reference = ( conf.r or conf.r2 )
and mw.html.create( 'small' )
:wikitext( frame:extensionTag(
'ref',
references[ conf.r or conf.r2 ],
{ name = conf.r or conf.r2 }
) )
or ''
columns.lang: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 .. ']]' )
:node( conf.r and reference or '' )
:wikitext(
' ([[:Kategoria:' .. ( conf.w and langobject:ucfirst( lang ) or 'Język ' .. lang ) .. '|⌘]])' ..
( conf.p
and ' ([[:Portal:' .. langobject:ucfirst( lang ) .. '|P]])'
or ''
)
)
columns['%']:attr( 'align', 'right' ):css( 'width', '30px' )
:tag( 'span' ):attr( 'id', 'sort count' ):css( 'display', 'none' )
:wikitext( pagecount )
columns.pcount:attr( 'align', 'right' ):css( 'width', '200px' )
:wikitext( pagecount > 999
and formatNum( pagecount )
or pagecount
)
:node( conf.r2 and reference or '' )
local mcount = ( conf.z or 0 ) * pagecount
mcount = math.floor( mcount )
mcounter = mcounter + mcount
columns.mcount:attr( 'align', 'right' )
:wikitext( mcount > 999
and formatNum( mcount )
or mcount
)
return columns, pagecount
end
local header = mw.html.create( 'tr' )
header:tag( 'th' ):css{
[ 'text-align' ] = 'center',
[ 'width' ] = '10%'
}:wikitext( 'język' )
header:tag( 'th' ):css( 'border-right-style', 'hidden' )
header:tag( 'th' ):addClass( 'unsortable' ):css( 'width', '66%' )
:wikitext( 'licznik haseł' )
header:tag( 'th' ):css{
[ 'width' ] = '10%',
[ 'white-space' ] = 'nowrap',
[ 'border-left-style' ] = 'hidden'
}
header:tag( 'th' ):css{
[ 'white-space' ] = 'nowrap',
[ 'width' ] = '10%'
}:wikitext( 'licznik znaczeń' )
:tag( 'small' ):wikitext(
frame:extensionTag( 'ref', references[ 'licznikZnaczeń' ], { name = 'licznikZnaczeń' } )
)
local contents = mw.html.create( '' )
local rows = {}
tcounter, maxtcount = traverseIndexes( 'terms', 'indeks', function( args )
local columns, terms = makeRow( unpack( args ) )
table.insert( rows, columns )
return terms
end )
table.sort( rows, function( a, b )
if a.key == b.key then
return a.key2 < b.key2
else
return a.key < b.key
end
end )
for k, row in ipairs( rows ) do
contents:tag( 'tr' )
:node( row.lang )
:node( row['%']:tag( 'small' ):wikitext( string.format(
'%.3f',
( row.pagecount / tcounter ) * 100 ) .. '%'
):done() )
:node( row.hbar:tag( 'div' ):css{
[ 'width' ] = ( 100 * row.pagecount / maxtcount ) .. '%',
[ 'background-color' ] = '#36c'
}
:wikitext( ' ' )
:done() )
:node( row.pcount )
:node( row.mcount )
end
local footer = mw.html.create( 'tr' ):addClass( 'sortbottom' )
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( formatNum( tcounter ) )
footer:tag( 'td' ):attr( 'align', 'right' )
:tag( 'b' ):wikitext( formatNum( mcounter ) )
return mw.html.create( 'table' )
:addClass( 'wikitable sortable autonumber' )
:css{
[ 'margin' ] = '0',
[ 'text-align' ] = 'left',
[ 'width' ] = '100%'
}
:node( header )
:node( contents )
:node( footer )
end
p.licznik_hasel = function( frame )
local lang = frame:getParent().args[ 1 ]
local name = 'indeks'
if lang then
return pagesInCategory( lang .. ' (' .. name .. ')', 'pages' )
else
return ( traverseIndexes( 'terms', name ) )
end
end
p.licznik_form_fleksyjnych = function( frame )
local lang = frame:getParent().args[ 1 ]
local name = 'formy fleksyjne'
if lang then
return pagesInCategory( lang .. ' (' .. name .. ')', 'pages' )
else
return ( traverseIndexes( 'terms', name ) )
end
end
p.licznik_znaczen = function( frame )
local lang = frame:getParent().args[ 1 ]
return ( traverseIndexes( 'meanings', lang ) )
end
return p