add a column for count of games played

This commit is contained in:
Kartik K. Agaram 2024-04-25 16:52:10 -07:00
parent 9c102c6f74
commit f63c181dd3
4 changed files with 30 additions and 5 deletions

View File

@ -6,7 +6,7 @@ draw_data = function()
local rside = max_row_width(Data) + namepx*2 -- width of name column
local nt = table.size(Data)
local hrow = total_row_width(Data) + namepx*2*nt
local width = rside + hrow + App.width('Total') + namepx*2
local width = rside + hrow + App.width('Games') + App.width('Total') + namepx*4
local height = (nt+1)*c
local top, left = 30,30
local cx = column_xs(Rows, left+rside, namepx) -- right margin of each column
@ -39,6 +39,9 @@ draw_data = function()
love.graphics.print(Rows[i], l+px, top+py)
l = r
end
-- 'Games' counts number of games played
love.graphics.print('Games', l+namepx, top+py)
l = l+App.width('Games')+namepx*2
-- 'Total' doubles as a button that sorts the rows by teams' total score
button(Global_state, 'total', {
x=l, y=top,
@ -54,7 +57,7 @@ draw_data = function()
Rows = ordered_keys(Data)
end
})
love.graphics.print('Total', l+namepx, top+py)
love.graphics.print('Total', l+namepx, top+py)
-- print out cells
for y,t1 in ipairs(Rows) do
l = left+rside
@ -101,9 +104,13 @@ draw_data = function()
end
l = cx[x]
end
App.color{r=0, g=0, b=0}
local count = count_games(Data, t1)
local px = (App.width('Games') - App.width(count)) / 2
love.graphics.print(count, l+px, top+y*c+py)
l = l + App.width('Games') + namepx*2
local total = score(Data, t1)
local px = (App.width('Total') - App.width(total)) / 2
App.color{r=0, g=0, b=0}
love.graphics.print(score(Data, t1), l+px, top+y*c+py)
love.graphics.print(total, l+px, top+y*c+py)
end
end

View File

@ -6,5 +6,6 @@ column_xs = function(rows, init, px)
x = x + App.width(name) + px*2
table.insert(result, x)
end
table.insert(result, x + App.width('Games') + px*2)
return result
end

View File

@ -11,14 +11,22 @@ load_results = function(filename)
results[subject] = {}
end
results[subject][object] = 2
if results[subject].count == nil then
results[subject].count = 0
end
results[subject].count = results[subject].count+1
if results[object] == nil then
results[object] = {}
end
results[object][subject] = 0
if results[object].count == nil then
results[object].count = 0
end
results[object].count = results[object].count+1
end)
or
error('incorrect format: '..line)
end
f:close()
return results
end
end

9
0030-count_games Normal file
View File

@ -0,0 +1,9 @@
count_games = function(t, team)
local result = 0
for opp, score in pairs(t[team]) do
if type(score) == 'number' then
result = result + 1
end
end
return result
end