Content deleted Content added
No edit summary |
No edit summary |
||
Line 8:
function p._main(args)
local eventsArg = mw.text.split(args['events'],
local participantsArg = mw.text.split(args['participants'],
local pointPositionsArg = mw.text.split(args['points'],
local
mw.logObject(points)
local events = {}
local participants = {}
local pointPositions = {}
local
local resultsSpecials = {}
local points = {}
for i,v in ipairs(eventsArg) do events[
for i,v in ipairs(participantsArg) do participants[
for i,v in ipairs(pointPositionsArg) do pointPositions[i] = tonumber(v) or 0 end
for i,v in ipairs(
local adj = true
local num = 0
local arg = args['specialPoints_' .. v]
if (arg ~= null) then
local startsWith = mw.ustring.sub(arg, 1, 1)
if (startsWith ~= '+' and startsWith ~= '-') then
adj = false
end
num = tonumber(arg)
end
special[i] = {short = v, adj = adj, num = tonumber(args['specialPoints_' .. v] or 0)}
end
-- Point handling and calculations
▲ local t = {}
if (args['result_' .. vEvents['short']] ~= nil) then
local eventResult = mw.text.split(args['result_' .. vEvents['short']], ',') or nil
results[iEvents] = {}
for iEventResult,vEventResult in ipairs(eventResult) do
--The position is put as the value, so that we can retrieve it from the participant in the table
results[iEvents][vEventResult] = iEventResult
--Add to points total
points[vEventResult] = (points[vEventResult] or 0) + (pointPositions[iEventResult] or 0)
end
mw.logObject(points)
-- Handling of special results
for iSpecial,vSpecial in ipairs(special) do
if (args['special_' .. vEvents['short'] .. '_' .. vSpecial['short']] ~= nil) then
local eventSpecial = mw.text.split(args['special_' .. vEvents['short'] .. '_' .. vSpecial['short']], ',')
for iEventSpecial,vEventSpecial in ipairs(eventSpecial) do
if (results[iEvents][vEventSpecial] == nil) then
results[iEvents][vEventSpecial] = vSpecial['short']
else
results[iEvents][vEventSpecial] = results[iEvents][vEventSpecial] .. '<span style="margin:0 0.1em 0 0.1em;font-size:110%;font-weight:bold;"><sup>' .. vSpecial['short'] .. '</sup></span>'
end
--if (vSpecial ~= nil and vSpecial['adj'] ~= nil and vSpecial['adj'] == true and vSpecial['num'] ~= nil) then
--points[vEventResult] = 999
--points[vEventResult] = (points[vEventResult] or 0) + (vSpecial['num'] or 0)
--end
end
end
end
end
end
local stack = {}
table.insert(t, '{| class="wikitable" style="font-size: 85%; vertical-align:top; text-align:center""\n')▼
table.insert(t, '!style="vertical-align:middle;"|<abbr title="Position">Pos</abbr>\n')▼
table.insert(t, '!style="vertical-align:middle;"|Participant\n')▼
▲ table.insert(
▲ for k,v in pairs(events) do
table.insert(t, '!' .. v)▼
▲ table.insert(
for i,v in ipairs(events) do
table.insert(stack, '!' .. (v['name'] or v['short'] or i) .. '\n')
end
table.insert(
for i,v in ipairs(participants) do
table.insert(stack, '|-\n')
table.insert(stack, '|' .. i .. '\n')
table.insert(stack, '|style="text-align:left;"|' .. (v['name'] or v['short']) .. '\n')
for j,w in ipairs(events) do
if (results[j] ~= nil and results[j][v['short']] ~= nil) then
table.insert(stack, results[j][v['short']])
end
table.insert(stack, '\n')
end
table.insert(stack, '|' .. (points[v['short']] or '–') .. '\n')
end
table.insert(
return table.concat(
end
|