From f63c181dd3a80aba322b84a081c138957b598771 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 25 Apr 2024 16:52:10 -0700 Subject: [PATCH] add a column for count of games played --- 0003-draw_data | 15 +++++++++++---- 0007-column_xs | 1 + 0020-load_results | 10 +++++++++- 0030-count_games | 9 +++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 0030-count_games diff --git a/0003-draw_data b/0003-draw_data index f9a3de9..9e5236d 100644 --- a/0003-draw_data +++ b/0003-draw_data @@ -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 \ No newline at end of file diff --git a/0007-column_xs b/0007-column_xs index c8b2980..6f6466d 100644 --- a/0007-column_xs +++ b/0007-column_xs @@ -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 \ No newline at end of file diff --git a/0020-load_results b/0020-load_results index 6e5ffe8..b61dd52 100644 --- a/0020-load_results +++ b/0020-load_results @@ -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 \ No newline at end of file diff --git a/0030-count_games b/0030-count_games new file mode 100644 index 0000000..78e8463 --- /dev/null +++ b/0030-count_games @@ -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 \ No newline at end of file