diff options
author | Aki <please@ignore.pl> | 2024-02-08 01:48:43 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-02-08 01:48:43 +0100 |
commit | 89b7fc43530535ea0fb2114e5fa0cf5660ca37a0 (patch) | |
tree | 547bfb206159eea7b380e8fdc1db357c94b1bf57 /activity.lua | |
parent | 85f53fed3026366c3970e26e2843be3d8e702c20 (diff) | |
download | activity-89b7fc43530535ea0fb2114e5fa0cf5660ca37a0.zip activity-89b7fc43530535ea0fb2114e5fa0cf5660ca37a0.tar.gz activity-89b7fc43530535ea0fb2114e5fa0cf5660ca37a0.tar.bz2 |
Fixed last two weeks of each year not showing up
Diffstat (limited to 'activity.lua')
-rw-r--r-- | activity.lua | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/activity.lua b/activity.lua index 8bec2a0..9a602b5 100644 --- a/activity.lua +++ b/activity.lua @@ -3,13 +3,15 @@ local git = require "activity.git" local activity = {} -function activity.generate_table (year, repositories, format) +function activity.generate_table (year, lookup, format) year = year or dates.this_year() - local lookup = git.lookup(repositories) - local function count (weekday, offset, week) -- TODO: filtering - local count = (lookup[year] or {})[weekday + offset + week * 7] or 0 - if 0 < count and count <= 2 then -- TODO: maybe relative to maximum? + local function day_of_year (first_weekday, week, weekday) + return week * 7 + weekday - first_weekday + 1 + end + + local function level (count) + if 0 < count and count <= 2 then return 1 end if 2 < count and count <= 4 then @@ -24,6 +26,10 @@ function activity.generate_table (year, repositories, format) return 0 end + local function day_level (first_weekday, week, weekday) + return level(lookup(year, day_of_year(first_weekday, week, weekday))) + end + local function cell (exists) if not exists then return format.spot @@ -31,15 +37,15 @@ function activity.generate_table (year, repositories, format) return format.cell end - local function row (weekday, index, offset, first, last) + local function row (weekday, index, start_from, first, last) first = cell(first) last = cell(last) local row = format.start_row() .. format.label(weekday) - row = row .. first(count(index, offset, 0)) - for week=2,52 do - row = row .. format.cell(count(index, offset, week)) + row = row .. first(day_level(start_from, 0, index)) + for week=1,51 do + row = row .. format.cell(day_level(start_from, week, index)) end - row = row .. last(count(index, offset, 53)) .. format.end_row() + row = row .. last(day_level(start_from, 52, index)) .. format.end_row() return row end @@ -48,7 +54,7 @@ function activity.generate_table (year, repositories, format) local start_from = dates.first_week_day(year) local end_at = (start_from + dates.days_in(year) - 1) % 7 for index, weekday in pairs(weekdays) do - rows = rows .. row(weekday, index, 8 - start_from, index >= start_from, index <= end_at) + rows = rows .. row(weekday, index, start_from, index >= start_from, index <= end_at) end return format.start_document"Activity" .. format.start_table() .. rows .. format.end_table() .. format.end_document() |