local dates = require "activity.dates" local activity = {} function activity.generate_table (year) year = year or dates.this_year() local function spot () return [[]] end local function day (level) return ([[]]):format(level) end local function cell (exists) if not exists then return spot end return day end local function row (weekday, 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)) end row = row .. last(math.random(0, 4)) .. "\n" return row end local rows = "" local weekdays = {"", "Mon", "", "Wed", "", "Fri", ""} 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) end return [[]] .. "\n" .. rows .. "
" end return activity