پودمان:ماتریس آرای هیئت نظارت/آزمایشی
ظاهر
![]() | اینجا صفحهٔ آزمایشها برای پودمان پودمان:ماتریس آرای هیئت نظارت است. نتایج آزمایشها. |
function uniquecandidates(frame)
local output = {}
for candidate in mw.text.gsplit(frame.args[2], ':') do
table.insert(output, candidate)
end
return output
end
function uniquevoters(frame)
local output = {}
local hash = {}
local res = {}
local voting = frame.args[1]
for candidate in mw.text.gsplit(frame.args[2], ':') do
local text = mw.title.new("انتخابات هیئت نظارت/دور " .. voting .. "/" .. candidate, "ویکیپدیا"):getContent()
local iter = mw.ustring.gmatch(text, "{{رای هیئت نظارت ".. voting .."|رای=[موافق مخالف]+[^\n]+c=[pپ]")
while true do
local m = iter()
if m == nil then break end
m = mw.ustring.gsub(m, "1=", "")
table.insert(output, m)
end
end
for _,v in ipairs(output) do
if (not hash[v]) then
res[#res+1] = v
hash[v] = true
end
end
return res
end
return {
main = function (frame)
local output = ""
local voting = frame.args[1]
candidates = uniquecandidates(frame)
voters = uniquevoters(frame)
local pos_mat = {}
local neg_mat = {}
for i=1,table.getn(voters) do
pos_mat[i] = {}
neg_mat[i] = {}
for j=1,table.getn(candidates) do
pos_mat[i][j] = 0
neg_mat[i][j] = 0
end
end
for candidate in mw.text.gsplit(frame.args[2], ':') do
local text = mw.title.new("انتخابات هیئت نظارت/دور " .. voting .. "/" .. candidate, "ویکیپدیا"):getContent()
local vid = 0
local cid = 0
for i, c in ipairs(candidates) do
if c == candidate then cid = i end
end
output = {}
local iter = mw.ustring.gmatch(text, "{{رای هیئت نظارت " .. voting .. "|رای=موافق[^\n]+c=[pپ]")
while true do
local m = iter()
if m == nil then break end
local voter = mw.ustring.gsub(m, "1=", "")
for i, v in ipairs(voters) do
if v == voter then vid = i end
end
pos_mat[cid][vid] = 1
end
local iter = mw.ustring.gmatch(text, "{{رای هیئت نظارت " .. voting .. "|رای=مخالف[^\n]+c=[pپ]")
while true do
local m = iter()
if m == nil then break end
local voter = mw.ustring.gsub(m, "1=", "")
for i, v in ipairs(voters) do
if v == voter then vid = i end
end
neg_mat[cid][vid] = 1
end
end
output = "{| class='wikitable sortble'\n!\n"
for i=1,table.getn(candidates) do
output = output .. "!" .. candidates[i] .. "\n"
end
for j=1,table.getn(voters) do
output = output .. "|-\n|" .. voters[j] .. "\n"
for i=1,table.getn(candidates) do
output = output .. "|"
if pos_mat[i][j] == 1 then
output = output .. "{{بله}}"
else
if neg_mat[i][j] == 1 then
output = output .. "{{خیر}}"
end
end
output = output .. "\n"
end
end
return output
end
}