Module:Sandbox/AB-me/Racing table: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 11:
local participantsArg = mw.text.split(args['participants'], ',')
local pointPositionsArg = mw.text.split(args['points'], ',') or {}
local specialArgnotesArg = mw.text.split(args['specialnotes'], ',') or {}
local events = {} -- contains event information (code, name)
mw.logObject(points)
local participants = {} -- contains participant information (code, name, results, resultNotes, points, pointsTotal)
local pointPositions = {} -- contains the distribution of points based on position
local events = {}
local notes = {} -- contains information about distribution of points not based on position (code, adj, num)
local participants = {}
local pointPositions = {}
local specialstack = {}
 
local results = {}
for i,v in ipairs(eventsArg) do events[i] = {code = v, name = args['event_' .. v]} end
local resultsSpecials = {}
for i,v in ipairs(participantsArg) do participants[i] = {code = v, name = args['participant_' .. v], results = {}, resultNotes = {}, points = {}, pointsTotal = nil} end
local points = {}
for i,v in ipairs(eventsArg) do events[i] = {short = v, name = args['event_' .. v]} end
for i,v in ipairs(participantsArg) do participants[i] = {short = v, name = args['participant_' .. v]} end
for i,v in ipairs(pointPositionsArg) do pointPositions[i] = tonumber(v) or 0 end
for i,v in ipairs(specialArgnotesArg) do
local adj = true
local num = 0
local arg = args['specialPoints_notesPoints_' .. v]
if (arg ~= null) then
Line 40 ⟶ 37:
end
special notes[i] = {shortcode = v, adj = adj, num = tonumber(args['specialPoints_notesPoints_' .. v] or 0)}
end
-- Point handling and calculations
for iEvents,vEvents in ipairs(events) do
if (args['result_' .. vEvents['shortcode']] ~= nil) then
local eventResultresultSplit = mw.text.split(args['result_' .. vEvents['shortcode']], ',') or nil
results[iEvents]local res = {}
for i,v in ipairs(resultSplit) do res[v] = i end
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
for iParticipants,vParticipants in ipairs(participants) do
vParticipants['results'][iEvents] = res[vParticipants['code']]
if (vParticipants['results'][iEvents] ~= nil) then
vParticipants['points'][iEvents] = pointPositions[res[vParticipants['code']]] or 0
else
vParticipants['points'][iEvents] = nil
end
end
end
local spec = {}
for iNotes,vNotes in ipairs(notes) do
if (args['notes_' .. vEvents['code'] .. '_' .. vNotes['code']]) then
local notesSplit = mw.text.split(args['notes_' .. vEvents['code'] .. '_' .. vNotes['code']], ',')
for i,v in ipairs(notesSplit) do
if (spec[v] == nil) then spec[v] = {} end
table.insert(spec[v], vNotes)
end
end
end
 
for iParticipants,vParticipants in ipairs(participants) do
vParticipants['resultNotes'][iEvents] = spec[vParticipants['code']]
end
 
end
--Summation of points
local stack = {}
for iParticipants,vParticipants in ipairs(participants) do
local tot = nil
for i,v in pairs(vParticipants['points']) do
if (v ~= nil) then
tot = (tot or 0) + v
end
end
vParticipants['pointsTotal'] = tot
end
--Writing table
--local stack = {}
table.insert(stack, '{| class="wikitable" style="font-size: 85%; vertical-align:top; text-align:center""\n')
Line 91 ⟶ 99:
for i,v in ipairs(events) do
table.insert(stack, '!' .. (v['name'] or v['shortcode'] or i) .. '\n')
end
Line 97 ⟶ 105:
for i,v in ipairs(participants) do
table.insert(stack, '|-\n')
table.insert(stack, '|' .. i .. '\n')
table.insert(stack, '!')
table.insert(stack, '|style="text-align:left;"|' .. (v['name'] or v['short']) .. '\n')
if (v['pointsTotal'] ~= nil) then
table.insert(stack, i)
else
table.insert(stack, '&ndash;')
end
table.insert(stack, '\n')
 
table.insert(stack, '|style="text-align:left;"|' .. (v['name'] or v['code']) .. '\n')
for j,w in ipairs(events) do
table.insert(stack, '|')
table.insert(stack, v['results'][j])
if (results[j] ~= nil and results[j][v['short']] ~= nil) then
 
table.insert(stack, results[j][v['short']])
if (v['resultNotes'] ~= nil and v['resultNotes'][j] ~= nil) then
end
local firstNote = true
for k,x in ipairs(v['resultNotes'][j]) do
if (firstNote and v['results'][j] == nil) then
table.insert(stack, x['code'])
else
table.insert(stack, '<span style="margin:0 0.1em 0 0.1em;"><sup>' .. x['code'] .. '</sup></span>')
end
firstNote = false
end
end
 
table.insert(stack, '\n')
end
table.insert(stack, '|!' .. (points[v['shortpointsTotal']] or '&ndash;') .. '\n')
end