Saltar para o conteúdo

Módulo:Filtros

Origem: Wikipédia, a enciclopédia livre.
Documentação do módulo[ver] [editar] [histórico] [purgar]

m = {}

function m.getNumberOfFalsePositives( frame )
    text = mw.title.new( 'Wikipédia:Filtro de edições/Análise/Filtro ' .. frame.args[1] ):getContent()
    -- title does not exist; content is nil; must exit now, or will fail when passing nil to string.gmatch below
	if text == nil then
		return 0
	end
    local gen, fp = string.gmatch(text, '{{Ação|%d+|?(%a*)'), 0
    for x in gen do
        if x == 'erro' then fp = fp + 1 end
    end
    return fp
end

function m.tabelafp(frame)
    local tabela = {}
    for i, f in ipairs(frame.args) do
        local num, desc = string.match(f, "(%d%d?%d?):([^\n]*)")
        text = mw.title.new('Wikipédia:Filtro de edições/Análise/Filtro ' .. num):getContent()
        local gen, count, fp = string.gmatch(text, '{{Ação|%d+|?(%a*)'), 0, 0
        for x in gen do
            count = count + 1
            if x == 'erro' then fp = fp + 1 end
        end
        table.insert(tabela,{num, desc, count, fp, string.gsub(math.floor(fp / count * 1000) / 10 .. ' %', '%.', ',')})
    end
    wikitext = [=[<table class="wikitable sortable" style="text-align: center">
  <tr>
    <th>Filtro</th>
    <th>Descrição</th>
    <th>Ações<br/>avaliadas</th>
    <th>Falsos<br/>positivos</th>
    <th>Porcentagem</th>
  </th>]=]
    for i, f in ipairs(tabela) do
        wikitext = wikitext .. string.format([=[
  <tr>
    <td>'''[[Especial:Filtro de abusos/%s|%s]]'''</td>
    <td>%s ([[Wikipédia:Filtro de edições/%s|discussão]])</td>
    <td>[[/Filtro %s|%d]]</td>
    <td>%d</td>
    <td>%s</td>
  </tr>]=], f[1], f[1], f[2], f[1], f[1], f[3], f[4], f[5])
    end
    wikitext = wikitext .. '\n</table>'
    return wikitext
end
 
return m