Difference between revisions of "Module:Events"
From Blaseball Wiki
Line 4: | Line 4: | ||
local seasons = 17 | local seasons = 17 | ||
− | function | + | local function do_query(tables, fields, join, headers) |
− | + | output = {} | |
− | + | fields = 'Day=_sort,' .. fields | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
for i = 1, seasons do | for i = 1, seasons do | ||
table.insert(output, '===Season ' .. i .. '===') | table.insert(output, '===Season ' .. i .. '===') | ||
local args = { | local args = { | ||
where = 'Season = ' .. i, | where = 'Season = ' .. i, | ||
− | join = | + | join = join, |
− | orderBy = ' | + | orderBy = '_sort', |
} | } | ||
local results = cargo.query( tables, fields, args ) | local results = cargo.query( tables, fields, args ) | ||
− | + | if #results > 0 then | |
− | + | table.insert(output, '{| class="wikitable"\n!' .. table.concat(headers, '!!')) | |
− | + | for r = 1, #results do | |
− | + | result = results[r] | |
− | + | local row = {} | |
− | table.insert | + | for i, f in ipairs(headers) do |
+ | table.insert(row, result[f]) | ||
end | end | ||
− | table.insert(output, '|}') | + | table.insert(output, '|-\n|' .. table.concat(row, '||')) |
+ | end | ||
+ | table.insert(output, '|}') | ||
else | else | ||
table.insert(output, 'None') | table.insert(output, 'None') | ||
Line 40: | Line 32: | ||
return table.concat(output, '\n') | return table.concat(output, '\n') | ||
+ | end | ||
+ | |||
+ | function p.incinerations(frame) | ||
+ | local tables = 'IncinerationEvents,Players=Players1,Players=Players2,Teams' | ||
+ | local fields = [=[ | ||
+ | IF(game IS NOT NULL, | ||
+ | CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'), | ||
+ | IF(Day IS NULL, 'EL', Day) | ||
+ | )=Day, | ||
+ | CONCAT('[[', Players1.Name, ']]')=Player, | ||
+ | CONCAT('[[', Players2.Name, ']]')=Replaced by, | ||
+ | CONCAT('[[', Teams.Name, ']]')=Team | ||
+ | ]=] | ||
+ | local join = [[ | ||
+ | IncinerationEvents.OutPlayer=Players1.UUID, | ||
+ | IncinerationEvents.InPlayer=Players2.UUID, | ||
+ | IncinerationEvents.Team=Teams.UUID | ||
+ | ]] | ||
+ | |||
+ | return do_query(tables, fields, join, { 'Day', 'Player', 'Replaced by', 'Team' }) | ||
+ | end | ||
+ | |||
+ | function p.feedback(frame) | ||
+ | local tables = 'FeedbackEvents,Players=Players1,Players=Players2,Teams=Teams1,Teams=Teams2' | ||
+ | local fields = [=[ | ||
+ | IF(Game IS NOT NULL, | ||
+ | CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'), | ||
+ | IF(Day IS NULL, 'EL', Day) | ||
+ | )=Day, | ||
+ | CONCAT('[[', Players1.Name, ']]')=Player A, | ||
+ | CONCAT('[[', Teams1.Name, ']]')=Team A, | ||
+ | CONCAT('[[', Players2.Name, ']]')=Player B, | ||
+ | CONCAT('[[', Teams2.Name, ']]')=Team B | ||
+ | ]=] | ||
+ | local join = [[ | ||
+ | FeedbackEvents.PlayerA=Players1.UUID, | ||
+ | FeedbackEvents.PlayerB=Players2.UUID, | ||
+ | FeedbackEvents.TeamA=Teams1.UUID, | ||
+ | FeedbackEvents.TeamB=Teams2.UUID | ||
+ | ]] | ||
+ | return do_query(tables, fields, join, { 'Day', 'Player A', 'Team A', 'Player B', 'Team B' }) | ||
+ | end | ||
+ | |||
+ | function p.reverb(frame) | ||
+ | local tables = 'ShuffleEvents,Teams' | ||
+ | local fields = [=[ | ||
+ | IF(Game IS NOT NULL, | ||
+ | CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'), | ||
+ | IF(Day IS NULL, 'EL', Day) | ||
+ | )=Day, | ||
+ | CONCAT('[[', Teams.Name, ']]')=Team, | ||
+ | ShuffleEvents.Type=Type | ||
+ | ]=] | ||
+ | local join = 'ShuffleEvents.Team=Teams.UUID' | ||
+ | return do_query(tables, fields, join, { 'Day', 'Team', 'Type' }) | ||
end | end | ||
return p | return p |
Revision as of 19:18, 4 May 2021
This module generates tables of game events per season.
{{#invoke:Events|<type>}}
- Output tables for all seasons with an <h3>
header for each
{{#invoke:Events|<type>|<season>}}
- Output table for a single season with no header, or output nothing if there are no events for the given season
<type>
can be incinerations
, feedback
, or shuffle
.
local p = {}
local cargo = mw.ext.cargo
local seasons = 17
local function do_query(tables, fields, join, headers)
output = {}
fields = 'Day=_sort,' .. fields
for i = 1, seasons do
table.insert(output, '===Season ' .. i .. '===')
local args = {
where = 'Season = ' .. i,
join = join,
orderBy = '_sort',
}
local results = cargo.query( tables, fields, args )
if #results > 0 then
table.insert(output, '{| class="wikitable"\n!' .. table.concat(headers, '!!'))
for r = 1, #results do
result = results[r]
local row = {}
for i, f in ipairs(headers) do
table.insert(row, result[f])
end
table.insert(output, '|-\n|' .. table.concat(row, '||'))
end
table.insert(output, '|}')
else
table.insert(output, 'None')
end
end
return table.concat(output, '\n')
end
function p.incinerations(frame)
local tables = 'IncinerationEvents,Players=Players1,Players=Players2,Teams'
local fields = [=[
IF(game IS NOT NULL,
CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'),
IF(Day IS NULL, 'EL', Day)
)=Day,
CONCAT('[[', Players1.Name, ']]')=Player,
CONCAT('[[', Players2.Name, ']]')=Replaced by,
CONCAT('[[', Teams.Name, ']]')=Team
]=]
local join = [[
IncinerationEvents.OutPlayer=Players1.UUID,
IncinerationEvents.InPlayer=Players2.UUID,
IncinerationEvents.Team=Teams.UUID
]]
return do_query(tables, fields, join, { 'Day', 'Player', 'Replaced by', 'Team' })
end
function p.feedback(frame)
local tables = 'FeedbackEvents,Players=Players1,Players=Players2,Teams=Teams1,Teams=Teams2'
local fields = [=[
IF(Game IS NOT NULL,
CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'),
IF(Day IS NULL, 'EL', Day)
)=Day,
CONCAT('[[', Players1.Name, ']]')=Player A,
CONCAT('[[', Teams1.Name, ']]')=Team A,
CONCAT('[[', Players2.Name, ']]')=Player B,
CONCAT('[[', Teams2.Name, ']]')=Team B
]=]
local join = [[
FeedbackEvents.PlayerA=Players1.UUID,
FeedbackEvents.PlayerB=Players2.UUID,
FeedbackEvents.TeamA=Teams1.UUID,
FeedbackEvents.TeamB=Teams2.UUID
]]
return do_query(tables, fields, join, { 'Day', 'Player A', 'Team A', 'Player B', 'Team B' })
end
function p.reverb(frame)
local tables = 'ShuffleEvents,Teams'
local fields = [=[
IF(Game IS NOT NULL,
CONCAT('[https://reblase.sibr.dev/game/', Game, ' ', Day, ']'),
IF(Day IS NULL, 'EL', Day)
)=Day,
CONCAT('[[', Teams.Name, ']]')=Team,
ShuffleEvents.Type=Type
]=]
local join = 'ShuffleEvents.Team=Teams.UUID'
return do_query(tables, fields, join, { 'Day', 'Team', 'Type' })
end
return p