From 86e7fa2004c12db0bda8e8fd7697fd8d64b2e4b6 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 1 Sep 2023 00:11:05 +0200 Subject: Generated activity chart now actually contains some activity --- activity.lua | 33 ++++++++++++++++++++++++++------- generate.lua | 5 +++-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/activity.lua b/activity.lua index cece167..5aefbdc 100644 --- a/activity.lua +++ b/activity.lua @@ -1,9 +1,28 @@ local dates = require "activity.dates" +local git = require "activity.git" local activity = {} -function activity.generate_table (year) +function activity.generate_table (year, repositories) 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? + return 1 + end + if 2 < count and count <= 4 then + return 2 + end + if 4 < count and count <= 6 then + return 3 + end + if 6 < count then + return 4 + end + return 0 + end local function spot () return [[]] @@ -20,15 +39,15 @@ function activity.generate_table (year) return day end - local function row (weekday, first, last) + local function row (weekday, index, offset, first, last) first = cell(first) last = cell(last) local row = ([[%s]]):format(weekday) - row = row .. first(math.random(0, 4)) - for _=1,51 do - row = row .. day(math.random(0, 4)) + row = row .. first(count(index, offset, 0)) + for week=2,52 do + row = row .. day(count(index, offset, week)) end - row = row .. last(math.random(0, 4)) .. "\n" + row = row .. last(count(index, offset, 53)) .. "\n" return row end @@ -37,7 +56,7 @@ function activity.generate_table (year) 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 >= start_from, index <= end_at) + rows = rows .. row(weekday, index, 8 - start_from, index >= start_from, index <= end_at) end return [[]] .. "\n" .. rows .. "
" end diff --git a/generate.lua b/generate.lua index 2c78d61..0486f7e 100644 --- a/generate.lua +++ b/generate.lua @@ -1,8 +1,9 @@ local activity = require "activity" -local year = ... +local args = {...} +local year = tonumber(table.remove(args, 1)) print([[]]) print([[]]) print([[]]) print([[]]) print([[Activity]]) -print(activity.generate_table(year)) +print(activity.generate_table(year, args)) -- cgit v1.1